How to change DNS ip address in RHEL

I am a new RHEL 5.x/6.x/7.x sysadmin. How do I change DNS IP address in RHEL using the CLI? What is the procedure to change the DNS IP from to in Red Hat Enterprise Linux desktop or server?

Introduction – DNS is an acronym for Domain Name Server. It is possible that you set up wrong DNS ip address in RHEL. This page shows how to change your RHEL server’s DNS IP address settings from the CLI.

Procedure to change DNS ip address in RHEL

  1. Edit the /etc/resolv.conf file with an editor, such as nano or vim in RHEL: sudo vim /etc/resolv.conf
  2. Set the name servers (DNS IP) that you want to use on RHEL : nameserver
  3. Save and close the file in RHEL
  4. Test new settings

How to see the current DNS settings in RHEL

Type the following cat command:
cat /etc/resolv.conf

RHEL change DNS ip address

Type the following vim command:
$ sudo vim /etc/resolv.conf
# vim /etc/resolv.conf
Edit/update nameserver entry as follows (you can set maximum 3 nameserver IP address):

## Change DNS settings on RHEL (Red Hat Enterprise Linux) ##

Test it using the ping command or host command/dig command:
ping -c 4

Changed DNS settings on RHEL? Test new DNS settings with ping, host and dig commands

How to change DNS settings on RHEL using Network Manager

Simply run the following nmcli command to connection names:
$ sudo nmcli connection
To set up DNS IP address to and, run:
sudo nmcli con mod {connectionNameHere} ipv4.dns ""
In this example just set up DNS IP to from the CLI on RHEL:
sudo nmcli con mod eth0 ipv4.dns ""
Reload new DNS settings by running any one of the following command:
sudo systemctl restart NetworkManager.service
sudo nmcli connection reload
Verify it by using the grep command and cat command and host command:
cat /etc/resolv.conf
grep DNS /etc/sysconfig/network-scripts/ifcfg-Ethernet_connection_1


This page described how to change your RHEL server’s DNS IP settings using the CLI.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.