Tag: NetworkManager

How to remove Mobile broadband and Bluetooth connection in NetworkManager

NetworkManager is a universal application for managing all kinds of network connections:

  • wired connections
  • wireless connections
  • USB modem
  • Bluetooth modem

Wired and wireless connections can be deleted in the Network Settings and Network Connections interfaces.

With Mobile broadband connections (using a mobile phone as a USB modem) and Bluetooth connections, the situation is somewhat different.

In Network Settings, when you select a Bluetooth connection, the button (minus sign, “-”) to delete this connection is inactive.

In Network Connections, it seems like you can delete Bluetooth connections – the delete button is active, but actually they are not deleted.

You can look for these connections in the /etc/NetworkManager/conf.d and /usr/lib/NetworkManager/conf.d direcotories – they are actually present in them, you can even delete the files of these connections. But this does not solve the problem – these files reappear.

See Also: Where NetworkManager stores settings

The crux of the problem is that Bluetooth connections are controlled by another service, and NetworkManager only receives information from it about available connections, so you need to delete Bluetooth connections using utilities responsible for Bluetooth.

In the command line, an unnecessary connection can be removed using the following algorithm.

1. The following command displays a list of available Bluetooth connections:

bluetoothctl devices

2. To remove an unnecessary connection, enter a command of the form:

bluetoothctl remove MAC_ADDRESS

For instance:

bluetoothctl remove C8:38:70:AD:BB:47

As you can see, the specified Bluetooth connection has disappeared from the list of network connections in NetworkManager.

You can also see the MAC_ADDRESS in Network Settings by going to the Bluetooth tab.

To copy the MAC_ADDRESS, click the gear icon.

The MAC_ADDRESS value can also be viewed in the Blueman applet.

Where NetworkManager stores settings (SOLVED)

NetworkManager Configuration Files

NetworkManager supports various plug-ins that can define new locations for storing configuration information.

The main configuration file for NetworkManager, which is usually changed, is /etc/NetworkManager/NetworkManager.conf. You can view its contents with the following command:

cat /etc/NetworkManager/NetworkManager.conf

In addition to this file, NetworkManager settings can be saved in the /etc/NetworkManager/conf.d and /usr/lib/NetworkManager/conf.d directories.

For a list of all NetworkManager settings, taking into account all configuration files, run the command:

NetworkManager --print-config

Where NetworkManager stores network connection settings

NetworkManager stores the settings for each connection in separate text files with the .nmconnection extension. A typical storage location for configuration files is /var/run/NetworkManager/system-connections. In addition to it, files with connections can be located in other places defined by NetworkManager plugins, for example, settings for network connections via Bluetooth can be stored in the /etc/NetworkManager/NetworkManager.conf folder. The NetworkManager configuration file is /etc/NetworkManager/NetworkManager.conf. Besides these main locations, there may be other paths that are specific to Linux distributions.

To list all network connections and the location of their configuration files, run the command:

nmcli -f NAME,DEVICE,FILENAME connection show

All NetworkManager configuration files

So, the configuration files for NetworkManager are as follows:

  • /etc/NetworkManager/NetworkManager.conf – main configuration file
  • /etc/NetworkManager/conf.d – directory with configuration files
  • /usr/lib/NetworkManager/conf.d – system directory with configuration files (for example, file /usr/lib/NetworkManager/conf.d/20-connectivity.conf)
  • /var/lib/NetworkManager/NetworkManager-intern.conf – internal configuration file. This file is written and read by NetworkManager, and its configuration values are merged with the configuration from NetworkManager.conf. Changes made to this file will be overwritten
  • /var/lib/NetworkManager/NetworkManager.state – file with a set of states
  • /etc/NetworkManager/system-connections/ – directory where wired and wireless connections are stored
  • /var/run/NetworkManager/system-connections/ – directory with some types of connections, for example, Internet via Bluetooth modem
  • /var/lib/NetworkManager/
  • /etc/NetworkManager/dispatcher.d/
  • /etc/NetworkManager/dnsmasq.d/
  • /etc/NetworkManager/dnsmasq-shared.d/

See also: How to remove Mobile broadband and Bluetooth connection in NetworkManager

How to prevent NetworkManager and other programs from modifying the /etc/resolv.conf file

The /etc/resolv.conf file contains a list of DNS servers that are used to resolve hostnames to IP addresses.

NetworkManager, which is responsible for making network connections, automatically changes the contents of this file. The replacement takes place without notifying the user and can lead to unpleasant consequences – for example, causing a DNS leak, which negatively affects anonymity. It can also disrupt your own caching DNS server.

In addition to the option not to use NetworkManager at all, you can specify in the settings of this program a prohibition on changing the /etc/resolv.conf file.

To do this, open the file /etc/NetworkManager/NetworkManager.conf:

sudo gedit /etc/NetworkManager/NetworkManager.conf

and add the dns=none line to the [main] group. If the [main] group is missing, then add the following lines:


Restart NetworkManager:

sudo systemctl restart NetworkManager

Make a backup copy of the /etc/resolv.conf file:

sudo cp /etc/resolv.conf /etc/resolv.conf.backup

And then remove /etc/resolv.conf (this is important because it might be a link to a file, not the actual file):

sudo rm -f /etc/resolv.conf

And create a file /etc/resolv.conf with the content you want.

Modifying the /etc/resolv.conf file is prohibited for NetworkManager, but the /etc/resolv.conf file is still overwritten

Unfortunately, besides NetworkManager, other programs can overwrite the /etc/resolv.conf file, and they do it silently, without displaying any warnings.

In my practice, this program turned out to be create_ap, launched without the --no-dns option. This program, or the dnsmasq it uses, overwrites the /etc/resolv.conf file without displaying any warnings or restoring it to its original state.

It is possible to make a complete ban on changing the /etc/resolv.conf file for all programs.

First, make sure it's a real file and not a symbolic link:

ls -l /etc/resolv.conf

If it's a symbolic link, remove it:

sudo rm /etc/resolv.conf

Then re-create the /etc/resolv.conf file with the values you want.

To completely disable editing the /etc/resolv.conf file (even with superuser rights), run the command:

sudo chattr +i /etc/resolv.conf

If you need to edit this file, run the command:

sudo chattr -i /etc/resolv.conf

How to find out which process is modifying the /etc/resolv.conf file

Install the auditd package, then run the commands:

sudo auditctl -w /etc/resolv.conf -p wa
sudo systemctl start auditd.service

To view the log entries, run the command:

sudo ausearch -f /etc/resolv.conf

For details, see the article “How to find out which process is modifying a file”.

How to prevent NetworkManager from managing a specific interface? (SOLVED)

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:


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:


For example, I want NetworkManager not to manage the wlp0s20f0u1, wlp0s20f0u2 and wlp0s20f0u3 network interfaces, then my lines are as follows:


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