4

An installation of CentOS 7 has two connections and three devices. How can I attach the device ens7 to the connection my-bridge? And how can I attach the device eth0 to the connection my-eth1?

Here is the relevant data from the terminal:

[root@localhost ~]# nmcli con show
NAME       UUID          TYPE            DEVICE 
my-bridge  some.uuid     802-3-ethernet  --     
my-eth1    another.uuid  802-3-ethernet  --     

[root@localhost ~]# nmcli device status
DEVICE  TYPE      STATE         CONNECTION 
ens7    ethernet  disconnected  --         
eth0    ethernet  disconnected  --         
lo      loopback  unmanaged     --         
[root@localhost ~]# ping 8.8.8.8
connect: Network is unreachable

I think it is something like nmcli connection modify id my-bridge ens7 but I am not sure of the exact syntax.

Also, the problem may have to do with the fact that the my-bridge connection (for example) was created in this way:

# nmcli con add con-name my-bridge ifname eth1 type ethernet ip4 10.1.1.2/24
# nmcli connection modify my-bridge ipv4.method manual ipv4.addresses 10.1.1.1/24

An answer would either show the exact syntax to type in the terminal for attaching the devices to the connections, or alternatively, the syntax for creating new connections that are automatically attached to devices from the start.

1

The easiest would be

nmcli device wifi connect <name ssid> password <the password>

For a solution with the password as variable: https://github.com/aurelien-git/bash/blob/master/wifi.sh

This script offer you the choice of selection and hidden passord

  • Thank you and +1 for documenting another approach. But leaving passwords exposed is a security risk. How would you secure the password? – CodeMed Aug 5 '17 at 16:56
  • Not sure nmcli offer solution for that, but I will have a look ... – aurelien Aug 5 '17 at 17:51
  • Maybe an environmental variable. – CodeMed Aug 5 '17 at 20:28
  • @CodeMed I add a script with password environnemental variable. – aurelien Aug 6 '17 at 6:24
  • And for information it works like a charm in Emacs shell :-) – aurelien Aug 6 '17 at 6:47
6

The short answer is:

# nmcli con modify my-bridge connection.interface-name ens7
# nmcli con up my-bridge

However, it's never that simple - read on...

Three things are needed for the connection to be attached to the device:

  1. A valid network device
  2. The connection.autoconnect property to be set to yes
  3. The connection.interface-name property is set to the name of the interface

Make sure that you have a working NIC (virtual in a VM). This is outside the scope of this answer as there are so many options.

Check the state of the connection.autoconnect property with:

# nmcli con show my-bridge | grep connection.autoconnect:
connection.autoconnect:                  no

and if need be, change it with:

# nmcli con modify my-bridge connection.autoconnect yes

Check the state of the connection.interface-name with:

# nmcli con show my-bridge | grep connection.interface-name
connection.interface-name           --

and if need be, set it with:

# nmcli con modify my-bridge connection.interface-name ens7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.