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
ens7    ethernet  disconnected  --         
eth0    ethernet  disconnected  --         
lo      loopback  unmanaged     --         
[root@localhost ~]# ping
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
# nmcli connection modify my-bridge ipv4.method manual ipv4.addresses

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.

4 Answers 4


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

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, 2017 at 16:56
  • Not sure nmcli offer solution for that, but I will have a look ...
    – aurelien
    Aug 5, 2017 at 17:51
  • Maybe an environmental variable.
    – CodeMed
    Aug 5, 2017 at 20:28
  • @CodeMed I add a script with password environnemental variable.
    – aurelien
    Aug 6, 2017 at 6:24
  • And for information it works like a charm in Emacs shell :-)
    – aurelien
    Aug 6, 2017 at 6:47

If you have a device with two wifi adapters, and you want to use the second one, then you should do the following commands. I used this with my AWS DeepLens, since the internal WiFi antenna is quite basic, but my USB WiFi adapter is very very good:

# Find the device name (such as wlan0) of your good adapter
ip a

# Ensure that NetworkManager sees the device
nmcli d

# Ensure that the device is detected as a Wifi adapter:
# NOTE: Replace "wlan0" with the name of your device
nmcli d show wlan0

# Ensure that the device can look around and do a scan of nearby networks:
nmcli d wifi list ifname wlan0

# Connect to the Wifi with the given password
# NOTE: Replace "MyHomeNetwork" with your Wifi network SSID
#       and replace "Sup3r-secret-password" with your password,
#       If your password contains any special characters, such as the $ below
#         I highly recommend surrounding it in single quotes, this is a shell thing,
#         not a nmcli thing.
nmcli d wifi connect MyHomeNetwork password 'Sup3r-$ecret-password' ifname wlan0

# Make sure it worked!
nmcli d
ip a


Also, for completion, if you want to attach a network connection profile to a specific device temporarily (for example, you'd want to use a wireless connection with a USB WiFi adapter), you can use nmcli to start an existing network connection with a non-default interface like this:

nmcli con up MyNetwork ifname other-device

(this will likely not work out of the box for connection configured through some Network Manager front-ends as they might have set "restrict connection to this MAC address", but it is easy to fix).

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.