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
- Edit the /etc/resolv.conf file with an editor, such as nano or vim in RHEL: sudo vim /etc/resolv.conf
- Set the name servers (DNS IP) that you want to use on RHEL : nameserver 192.168.2.254
- Save and close the file in RHEL
- 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
OR
# 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) ## nameserver 192.168.2.254 nameserver 192.168.2.18
Test it using the ping command or host command/dig command:
ping -c 4 www.nixcraft.com
host www.nixcraft.com
dig www.cyberciti.biz
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 192.168.2.254 and 192.168.2.18, run:
sudo nmcli con mod {connectionNameHere} ipv4.dns "192.168.2.254 192.168.2.18"
In this example just set up DNS IP to 192.168.2.254 from the CLI on RHEL:
sudo nmcli con mod eth0 ipv4.dns "192.168.2.254"
Reload new DNS settings by running any one of the following command:
sudo systemctl restart NetworkManager.service
OR
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
host www.cyberciti.biz
Conclusion
This page described how to change your RHEL server’s DNS IP settings using the CLI.
🐧 2 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
To change DNS settings on Linux
vi /etc/resolv.conf
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!!!