14

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.

5 Answers 5

12

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
1
  • In my case, I also had to set the same MAC address on the connection; the 802-3-ethernet.mac-address (when running nmcli c show my-bridge) had to be equal to GENERAL.HWADDR (when running nmcli d show ens7)
    – Omid N
    Commented Jul 2 at 8:16
3

The easiest would be

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

Check this bash script for a solution with the password as variable.

This script offer you the choice of selection and hidden password.

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

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
ifconfig

# 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
ifconfig

# PROFIT!
0

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).

0

Make sure you don't have your interfaces listed in /etc/NetworkManager/conf.d/99-unmanaged-devices.conf. If they are there, nothing you do anywhere else will matter.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .