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 CentOS, AlmaLinux, and Rocky Linux systems, the configuration file resolv.conf needs to be edited.

1. Edit the resolv.conf file

First, open the file using a text editor, such as Nano:

nano /etc/resolv.conf

options rotate
options timeout:2
options attempts:1

nameserver 91.228.153.88
nameserver 195.26.237.237
nameserver 31.172.68.71

This example uses the specified DNS servers to resolve domain names. The addresses can be replaced with others that are suitable for the desired configuration.

Guide on how to use the Nano editor is available on this page.

2. Save settings after reboot

To save the changes after the system reboots, the network interface configuration file needs to be edited.

Open the interface settings file with the following command:

nano /etc/sysconfig/network-scripts/ifcfg-eth0

Replace the DNS-related lines with the following:

DNS1=91.228.153.88
DNS2=195.26.237.237
DNS3=31.172.68.71

These changes will ensure that the specified DNS servers are used after every system restart.

3. Restart the network

After making the changes, restart the network services for the settings to take effect:

systemctl restart network

4. Check DNS functionality

To verify the correct operation of the configured DNS servers, you can use the nslookup command:

nslookup example.com

If the settings were configured correctly, the command will return the IP address for the specified domain.

Now, the system will use the specified DNS servers for domain name resolution. These settings are commonly applied on VPS and dedicated servers to improve network speed and stability.

Help

If you have any questions or need assistance, please contact us through the ticket system — we're always here to help!

Need help?Our engineers will help you free of charge with any question in minutesContact us