
How to prevent NetworkManager from managing a specific interface? (SOLVED)
February 19, 2021
NetworkManager is a Linux service that manages various network interfaces, including physical, such as Ethernet and wireless, and virtual, such as VPN and other tunnels. Network Manager can be configured to manage some or all of the system interfaces.
NetworkManager has a graphical interface - this is the applet that opens when you click on the network icon located next to the clock, as well as the network and network settings windows, which you can access from the applet. NetworkManager comes preinstalled on many Linux distributions by default.
While NetworkManager is an excellent service for managing the day-to-day needs of a user's computer, its effects are usually not optimal for a testing environment. NetworkManager can independently, without a user request, change the MAC addresses of network interfaces, as well as change their state - for example, when a USB Wi-Fi adapter is connected, it is NetworkManager that sets it in the up state, it can bring the wireless interface out of monitor mode and switch it to its normal state.
If you want to avoid this for certain network interfaces, then besides the obvious solution to stop the NetworkManager service or remove NetworkManager altogether, there are other options. By the way, if you are just not satisfied with the fact that the MAC addresses are changed to arbitrary, then this can be configured or disabled in the NetworkManager itself.
What is an unmanaged interface in NetworkManager
The unmanaged state in NetworkManager for a network interface means that NetworkManager does not interact with this network interface in any way: it does not enable it, does not change its operating mode, does not change the MAC address, does not use it to scan networks, and does not even show it in the list of network interfaces - that is, NetworkManager pretends that this interface simply does not exist in the system.
How to determine if NetworkManager is managing a specific network interface
The unmanaged state only has an effect on the NetworkManager itself. You, as usual, you can see all network interfaces with the command
ip a
or only wireless interfaces by command:
iw dev
At the same time, it is not indicated in any way whether this interface is controlled by NetworkManager.
As already mentioned, if your device is not in the list of network interfaces shown by NetworkManager, then it may be in an unmanaged state.
But to be sure of this, you can use the nmcli command, which is a command line tool for managing NetworkManager. To display a list of network interfaces and their status, run the command:
nmcli dev status
For unmanaged devices, it will show “unmanaged”.
Suppose I want NetworkManager not to change in any way the settings of the wireless network interface named wlp0s20f0u1.
How to temporarily move a network interface to unmanaged in NetworkManager
The network interface can be disconnected from NetworkManager management temporarily or permanently (so that this status remains after reboot). In fact, you can change the status at any time.
To temporarily make the interface unmanaged, run a command like:
nmcli dev set INTERFACE managed no
For instance:
nmcli dev set wlp0s20f0u1 managed no
We check:
nmcli dev status
Pay attention to the line:
wlp0s20f0u1 wifi unmanaged --
This setting is reset not only after restarting the computer, but also after disconnecting and connecting the network interface (plug and unplug).
How to put network interface to unmanaged in NetworkManager so that this persists after reboot
To prevent NetworkManager from touching the network interface immediately after starting the service and to keep this setting after a reboot, you need to use the keyfile method.
To do this, open the file /etc/NetworkManager/NetworkManager.conf:
sudo gedit /etc/NetworkManager/NetworkManager.conf
And add lines like this there:
[keyfile] unmanaged-devices=mac:00:11:22:33:44:55;mac:66:77:88:99:00:aa
You can list any number of MAC addresses.
You can view the MAC addresses of network interfaces with the command
ip a
But remember that NetworkManager could already assign an arbitrary MAC address, to see the real one, run a command like this:
nmcli dev set INTERFACE managed no
List the MAC address of each interface that Network Manager should ignore, separated by semicolons. Make sure the MAC addresses listed here are written in lowercase.
Newer versions of NetworkManager may also use the more general alternative KEYFILE method, which does not include the actual MAC addresses and instead uses the interface names. This syntax replaces the above [keyfile] section with the following:
[keyfile] unmanaged-devices=interface-name:eth*,except:interface-name:eth0;interface-name:wlan*
For example, I want NetworkManager not to manage the wlp0s20f0u1, wlp0s20f0u2 and wlp0s20f0u3 network interfaces, then my lines are as follows:
[keyfile] unmanaged-devices=interface-name:wlp0s20f0u1;interface-name:wlp0s20f0u2;interface-name:wlp0s20f0u3
Save your changes and restart the service:
sudo systemctl restart NetworkManager
Let's check:
nmcli dev status
How to return a network interface under NetworkManager control
Now the listed network interfaces will always be “unmanaged”. But they can be set back under the control of NetworkManager. To do this, simply roll back the changes made in the NetworkManager.conf file and restart the service.
If you took the interface out of the NetworkManager control with the nmcli command, then you can return it to its previous state with the command:
nmcli dev set INTERFACE managed yes
How to turn off NetworkManager
If you want to completely stop NetworkManager so that it stops managing all network interfaces at once, then run the command:
sudo systemctl stop NetworkManager
If you want to remove NetworkManager from startup, then run:
sudo systemctl disable NetworkManager
To start NetworkManager again and add it to startup run:
sudo systemctl start NetworkManager sudo systemctl enable NetworkManager
Related articles:
- Why does VirtualBox lose connection when changing MAC address (SOLVED) (76.8%)
- Where NetworkManager stores settings (SOLVED) (74.6%)
- How to prevent NetworkManager and other programs from modifying the /etc/resolv.conf file (57.8%)
- How to remove Mobile broadband and Bluetooth connection in NetworkManager (57.8%)
- Why are channels between 64 and 100 unavailable on 5 GHz Wi-Fi? (SOLVED) (52.2%)
- Updating packages: whether to update the config file (RANDOM - 50%)