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
See current DNS name server IP address on RHEL

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.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 2 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
2 comments… add one
  • Madhu May 3, 2016 @ 19:39

    To change DNS settings on Linux
    vi /etc/resolv.conf

    nameserver 2001:4860:4860::8888
  • Josh Q T Mar 13, 2018 @ 12:12

    How do I change the IP address, DNS IP and hostname on the command line without rebooting the RHEL 6.x web server? Please help!!!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum