To change the Nameserver in CentOS 8, follow these steps:
1. Check the current nameserver status
The DNS configuration file is located at the following path:
cat /etc/resolv.conf
The result of this command displays a list of current DNS servers. For example:
nameserver 8.8.8.8
nameserver 8.8.4.4
2. Edit the resolv.conf file (temporary method)
To temporarily change the nameservers:
Buy a cloud server (hourly and monthly) with instant delivery and incredible speed from Radib, Click
sudo nano /etc/resolv.conf
Add or replace new nameservers:
nameserver 8.8.8.8
nameserver 8.8.4.4
Note:
- This Changes will be lost after a server restart.
- To make the change permanent, continue with the steps.
3. Permanently change the nameserver
a) Using NetworkManager
- Edit the network connection configuration file:
sudo nmcli con show
-
Find the network connection ID (e.g. "eth0").
-
Change the DNS settings:
sudo nmcli con mod eth0 ipv4.dns "8.8.8.8 8.8.4.4"
sudo nmcli con mod eth0 ipv4.ignore-auto-dns yes
- Apply changes:
sudo nmcli con up eth0
B) Edit Network Scripts Files
- Edit the file related to the network interface:
Buy a server without abuses at the best price from Radib, Click
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
- Add (or edit) these lines:
DNS1=8.8.8.8
DNS2=8.8.4.4
- Restart the network service:
sudo systemctl restart NetworkManager
4. Check the changes
To make sure the changes have been applied, check the resolv.conf file again:
cat /etc/resolv.conf
5. Flush DNS Cache (Optional)
If the server uses a DNS cache, flush it:
sudo systemctl restart named
sudo systemctl restart nscd
Important Note:
If your server uses CloudLinux or cPanel/WHM, DNS settings may be managed through these tools and may require manual changes in the control panel environment.
Conclusion:
With these steps, you can temporarily or permanently change the nameserver of your CentOS 8 server. If you need fast and stable Linux servers, Radib Group offers a variety of hosting options.