如果某台Linux(CentOS)伺服器ping網域名稱, 如下提示:
# ping www.sina.com
ping: unknown host www.sina.com
確認網路沒問題的情況下, 可以通過如下步驟尋找解決辦法:
1) 確認設定了網域名稱伺服器
# cat /etc/resolv.conf
nameserver 8.8.8.8#(Google的公用DNS服務)
nameserver 8.8.4.4#(Google的公用DNS服務)
2) 確認網關已設定/確認路由表正常
# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 10.10.10.1 0.0.0.0 UG 0 0 0 eth0
如果未設定, 則通過如下方式增加網關:
# route add default gw 10.245.75.1
# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*
/etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=10.245.75.1
3) 確認可用dns解析
# grep hosts /etc/nsswitch.conf
hosts:files dns
以上的1) 2) 3) 點只是確認問題,個人喜歡手工編寫設定檔,一次解決問題。
配置/etc/sysconfig/network-scripts/ifcfg-eth0檔案後,重啟network服務:
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
IPADDR=10.245.75.240
#PREFIX=24
GATEWAY=10.245.75.1
DNS1=8.8.8.8
DNS2=8.8.4.4
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=yes
NAME="System eth0"
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # uuid
HWADDR=xx:xx:xx:xx:xx:xx# hwaddr
NETWORKING=yes
# service network restart