Easy Steps To Disable systemd-resolved on Centos 7
In this guide, you will learn to Disable systemd-resolved on Centos 7. In the Linux operation system, the systemd-resolved service brings a DNS resolver facility. If you are using your own DNS server, so you need to disable your systemd-resolved service which is listening on port 53. If you don’t disable this service, you aren’t able to use your DNS server.
To disable your systemd-resolved service on Centos, you can follow the steps below on the Orcacore website.
To disable this service on your server, you can download the disable-systemd-resolved.sh package by using the following wget command:
wget https://raw.githubusercontent.com/serverok/server-setup/master/tools/disable-systemd-resolved.sh
Then, run the script to disable your systemd-resolved service:
bash disable-systemd-resolved.sh
Or, you can use the following commands instead:
# systemctl disable systemd-resolved.service
# systemctl stop systemd-resolved
Create a /etc/resolv.conf file on Centos 7
At this point, you need to remove the default /etc/resolv.conf file with the following command:
rm -f /etc/resolv.conf
Then, create a new file on your server. For example:
tee /etc/resolv.conf << END
nameserver 8.8.8.8
nameserver 1.1.1.1
END
That’s it, you are done.
Conclusion
At this point, you have learned to Disable systemd-resolved on Centos 7 which is listening on port 53 and create your own DNS server on Centos 7. With this option, you can use your DNS server.
Hope you enjoy it. You may be interested in these articles:
How To Clear Yum Cache on Centos 7
How To Enable IP Forwarding in Linux
Upgrade Linux Kernel on Centos 7
Alternative Solutions to Disabling systemd-resolved on Centos 7
While the provided script and commands effectively disable systemd-resolved
, they represent a fairly blunt approach. It completely shuts down the service. Sometimes, a more nuanced approach is preferable, allowing you to retain some of the benefits of systemd-resolved
while still using your preferred DNS servers. Here are two alternative solutions:
1. Configuring systemd-resolved to Use Specific DNS Servers (While Keeping it Running)
Instead of disabling systemd-resolved
entirely, you can configure it to forward DNS queries to your chosen DNS servers. This method allows you to benefit from systemd-resolved
‘s caching and DNSSEC validation features, while still utilizing your preferred DNS infrastructure. This is especially useful if you want to keep the benefits of systemd-resolved
such as its local caching of DNS responses, which can speed up DNS lookups. This approach is a more graceful solution than completely disabling the service.
Steps:
-
Edit the
resolved.conf
file: The primary configuration file forsystemd-resolved
is located at/etc/systemd/resolved.conf
. Open this file with your favorite text editor (e.g.,vi
,nano
).vi /etc/systemd/resolved.conf
-
Uncomment and modify the
DNS=
andFallbackDNS=
lines: Find the lines that start withDNS=
andFallbackDNS=
. Uncomment them (remove the#
at the beginning of the line) and specify your desired DNS servers, separated by spaces.[Resolve] DNS=8.8.8.8 8.8.4.4 FallbackDNS=1.1.1.1 1.0.0.1
DNS=
specifies the DNS servers thatsystemd-resolved
will use for resolving domain names. In this example, we’re using Google’s Public DNS servers (8.8.8.8 and 8.8.4.4).FallbackDNS=
specifies DNS servers thatsystemd-resolved
will use as a fallback if the servers specified inDNS=
are unreachable. Here, we’re using Cloudflare’s DNS servers (1.1.1.1 and 1.0.0.1).
-
Restart the
systemd-resolved
service: After modifying the configuration file, you need to restart the service for the changes to take effect.systemctl restart systemd-resolved
-
Verify the configuration: You can verify that
systemd-resolved
is using the specified DNS servers by querying its status.systemd-resolve --status
Look for the "DNS Servers" section in the output. It should list the DNS servers you configured in
/etc/systemd/resolved.conf
. -
Link /etc/resolv.conf to systemd-resolved: If it is not already, ensure that
/etc/resolv.conf
is a symbolic link to/run/systemd/resolve/stub-resolv.conf
. This file is dynamically generated bysystemd-resolved
and reflects the configured DNS servers. If it’s not a symlink, create one.rm -f /etc/resolv.conf ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
This approach maintains the functionality of systemd-resolved
while directing it to use your preferred DNS servers.
2. Masking systemd-resolved and Using NetworkManager
Another approach, especially relevant in desktop environments, is to mask the systemd-resolved
service and allow NetworkManager to handle DNS resolution. Masking prevents the service from starting, providing a more thorough disabling than simply stopping it. NetworkManager often provides a more convenient and user-friendly way to configure DNS settings, particularly for systems that frequently switch networks (e.g., laptops). This approach works best if you are using NetworkManager to manage your network connections.
Steps:
-
Mask the
systemd-resolved
service: This prevents the service from starting automatically.systemctl mask systemd-resolved.service
-
Stop the
systemd-resolved
service (if it’s running):systemctl stop systemd-resolved.service
-
Configure DNS settings in NetworkManager: Use the NetworkManager GUI (if available) or the command-line tool
nmcli
to configure your desired DNS servers.-
Using
nmcli
(command-line): First, identify your network connection’s name:nmcli connection show
Then, modify the connection to use your desired DNS servers:
nmcli connection modify "Your Connection Name" ipv4.dns "8.8.8.8,8.8.4.4" nmcli connection modify "Your Connection Name" ipv4.dns-search "" #Optional: clear DNS search domains nmcli connection up "Your Connection Name"
Replace
"Your Connection Name"
with the actual name of your network connection.Explanation:
nmcli connection modify
: This command is used to modify an existing network connection."Your Connection Name"
: This is the name of the network connection you want to modify. You can find the name by runningnmcli connection show
.ipv4.dns "8.8.8.8,8.8.4.4"
: This sets the DNS servers for IPv4 to Google’s Public DNS servers (8.8.8.8 and 8.8.4.4). You can specify multiple DNS servers separated by commas.ipv4.dns-search ""
: Clears the DNS search domains, which is optional.nmcli connection up "Your Connection Name"
: This command reactivates the connection, applying the changes you made.
-
-
Link /etc/resolv.conf to NetworkManager: NetworkManager manages the
/etc/resolv.conf
file, so make sure it is linked to the correct location. Usually, it will be linked to/run/NetworkManager/resolv.conf
.rm -f /etc/resolv.conf ln -s /run/NetworkManager/resolv.conf /etc/resolv.conf
This method effectively delegates DNS resolution to NetworkManager, providing a more integrated approach for systems that rely on it. It provides a more reliable and integrated solution for managing DNS settings within a desktop environment managed by NetworkManager. This can be a more convenient option, especially if you are frequently changing networks.
These alternative solutions provide more flexible ways to manage DNS resolution on Centos 7, allowing you to choose the approach that best suits your specific needs and environment. The original guide offers a straightforward method to Disable systemd-resolved on Centos 7, but these alternatives offer a more nuanced and sometimes more appropriate solution. Remember to test your DNS configuration after making any changes to ensure that your system can resolve domain names correctly.