Configuring DNS Localhost in NetworkManager Using dnsmasq Plugin
NetworkManager is a powerful tool that allows users to manage their network connections with ease. One of the features of NetworkManager is its ability to use the dnsmasq plugin for DNS resolution. However, sometimes NetworkManager can bind dnsmasq to the wrong interface, which can cause issues with DNS resolution on the localhost.
Understanding the Problem
By default, NetworkManager will bind dnsmasq to the first available network interface. In some cases, this can cause issues if you have multiple network interfaces and want to use dnsmasq for localhost DNS resolution. Specifically, if NetworkManager binds dnsmasq to the wrong interface, you may experience issues with DNS resolution on the localhost.
For example, if NetworkManager is configured to bind dnsmasq to the enp6s0 interface instead of the lo interface, you may see DNS resolution issues on the localhost. In this case, the DNS server address may be set to 127.0.2.1@enp6s0 instead of 127.0.2.1@lo.
Checking the Current Configuration
To check the current configuration of NetworkManager and dnsmasq, you can use the following command:
sudo cat /etc/NetworkManager/NetworkManager.conf
This will show you the current configuration for NetworkManager, including any plugins that are enabled. If the dnsmasq plugin is enabled, you should see a line like this:
dns=dnsmasq
To check which interface dnsmasq is currently bound to, you can use the following command:
sudo cat /run/NetworkManager/dnsmasq-conf.dhcp
This will show you the current configuration for dnsmasq, including the interface it is bound to. If dnsmasq is bound to the wrong interface, you can update the configuration to bind it to the correct interface.
Updating the Configuration
To update the configuration of NetworkManager and dnsmasq to bind dnsmasq to the lo interface, you can follow these steps:
- Open the NetworkManager configuration file:
- Add the following line to the file:
- Save and close the file.
- Create a new file for the dnsmasq configuration:
- Add the following lines to the file:
- Save and close the file.
- Restart NetworkManager to apply the changes:
sudo nano /etc/NetworkManager/NetworkManager.conf
[main]
dns=dnsmasq
sudo nano /etc/NetworkManager/dnsmasq.d/localhost.conf
interface=lo
server=127.0.0.1
sudo systemctl restart NetworkManager
After following these steps, dnsmasq should be bound to the lo interface, and you should be able to use localhost DNS resolution without issues.
- NetworkManager can use the dnsmasq plugin for DNS resolution.
- By default, NetworkManager binds dnsmasq to the first available network interface.
- If NetworkManager binds dnsmasq to the wrong interface, you may experience issues with DNS resolution on the localhost.
- To update the configuration of NetworkManager and dnsmasq to bind dnsmasq to the
lointerface, you can follow the steps outlined in this article.