Configuring DNS on CentOS, AlmaLinux, and Rocky Linux
Step-by-step guide to changing DNS servers in CentOS, AlmaLinux, and Rocky Linux.
To change DNS servers in modern CentOS, AlmaLinux, and Rocky Linux distributions (version 8 and newer), NetworkManager is used. Directly editing the /etc/resolv.conf file is no longer recommended, as the system automatically overwrites it upon reboot or when network settings change.
Note
DNS server IP addresses vary depending on your server's location. You can find the current IP addresses in the control panel under the specific service card: open the IPv4 / IPv6 tab and copy the addresses from the DNS Servers section.
1. Identifying the Network Connection Name
Before configuring, find the name of your active network connection using the following command:
nmcli connection show
The connection name (for example, eth0, enp0s3, or System eth0) will be displayed in the NAME column.
2. Configuring DNS Servers via NetworkManager
Specify the required DNS servers for your connection. Replace eth0 with your connection name from the previous step, and replace the IP addresses with the current ones for your location from the control panel. The example below uses DNS servers for the Germany location:
nmcli connection modify eth0 ipv4.dns "1.1.1.1 8.8.8.8 9.9.9.9"
3. Applying the Settings
Restart the network connection for the new parameters to take effect:
nmcli connection up eth0
NetworkManager will automatically update the /etc/resolv.conf file. You can check its current contents using the command:
cat /etc/resolv.conf
4. Verifying DNS Functionality
Ensure that domain name resolution is working properly by running a test query using the nslookup (or dig) utility:
nslookup example.com
If configured correctly, the output will display the domain's IP address along with the address of one of your configured DNS servers.
These settings are automatically preserved after a system reboot and ensure stable domain name resolution on VPS and dedicated servers.
Our products and services
Help
If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!