Search My Techie Guy

Monday, September 4, 2017

How to quickly add DNS settings in Linux (CentOS)?

Summary: 

This note will show you how to quickly fix DNS settings on linux. Am using centOS

[root@localhost ~]# cat /etc/*release*
CentOS release 6.3 (Final)
CentOS release 6.3 (Final)
CentOS release 6.3 (Final)
cpe:/o:centos:linux:6:GA

Problem or Goal:

Pinging a domain name like "yahoo.com" returns error
[root@localhost ~]# ping yahoo.com
ping: unknown host yahoo.com
[root@localhost ~]# 

Cause:

Checking the ifcfg files, there is no DNS settings defined!!
[root@localhost ~]# cd /etc/sysconfig/network-scripts/

[root@localhost network-scripts]# more ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
BROADCAST="172.17.6.255"
GATEWAY="172.17.6.3"
HWADDR="14:FE:B5:DF:B9:A9"
IPADDR="172.17.6.44"
NETMASK="255.255.255.0"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"


Solution:

Check and make sure you have proper internet connection, i tested by pinging a public DNS 8.8.8.8

[root@localhost network-scripts]# ping 172.29.1.111
PING 172.29.1.111 (172.29.1.111) 56(84) bytes of data.
64 bytes from 172.29.1.111: icmp_seq=1 ttl=125 time=0.943 ms
64 bytes from 172.29.1.111: icmp_seq=2 ttl=125 time=0.675 ms
^C
--- 172.29.1.111 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1712ms
rtt min/avg/max/mdev = 0.675/0.809/0.943/0.134 ms
[root@localhost network-scripts]# 

Now add the DNS settings in the ifcfg-eth0 file, make sure you know your network DNS IPs to use, or you can use the public DNS, 8.8.8.8 if it's allowed on your network.

[root@localhost network-scripts]# vi ifcfg-eth0

DEVICE="eth0"
BOOTPROTO="static"
BROADCAST="172.17.6.255"
GATEWAY="172.17.6.3"
HWADDR="14:FE:B5:DF:B9:A9"
IPADDR="172.17.6.44"
NETMASK="255.255.255.0"
DNS1="172.29.1.111"
DNS2="8.8.8.8"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"

Restart the network services

[root@localhost etc]# /etc/init.d/network restart
Shutting down interface eth0:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
[root@localhost etc]# 


Problem Solved?

Test by ping a domain name, for example "yahoo.com"

[root@localhost ~]# ping www.yahoo.com
PING atsv2-fp.wg1.b.yahoo.com (46.228.47.115) 56(84) bytes of data.
64 bytes from ir1.fp.vip.ir2.yahoo.com (46.228.47.115): icmp_seq=1 ttl=53 time=202 ms
64 bytes from ir1.fp.vip.ir2.yahoo.com (46.228.47.115): icmp_seq=2 ttl=53 time=202 ms
64 bytes from ir1.fp.vip.ir2.yahoo.com (46.228.47.115): icmp_seq=3 ttl=53 time=202 ms
64 bytes from ir1.fp.vip.ir2.yahoo.com (46.228.47.115): icmp_seq=4 ttl=53 time=202 ms
64 bytes from ir1.fp.vip.ir2.yahoo.com (46.228.47.115): icmp_seq=5 ttl=53 time=203 ms
^C
--- atsv2-fp.wg1.b.yahoo.com ping statistics ---
6 packets transmitted, 5 received, 16% packet loss, time 5035ms
rtt min/avg/max/mdev = 202.167/202.646/203.652/0.772 ms
[root@localhost ~]# 

No comments: