码迷,mamicode.com
首页 > 其他好文 > 详细

ping: unknown host baidu.com

时间:2016-06-17 19:35:34      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

本机环境:Centos

自己的虚拟机最近不能等外网了,现状如下:

[root@vhost03 ~]# ping baidu.com
ping: unknown host baidu.com

查看了下本机的网卡配置:

[root@vhost03 ~]# more /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:0C:29:D7:D2:49"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="f08dcf57-d670-46b3-8298-240cd0b76bc2"
IPADDR=192.168.196.129
BROADCAST=192.168.196.255
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

新装的虚拟机默认都是dhcp方式获取IP。为了保证IP固定,自己更新了网卡信息,使用了static模式。其中黄色底色部分都是按照dhcp模式时,使用ifconfig命令获取的信息。

查看DNS信息:

[root@vhost03 ~]# more /etc/resolv.conf
# Generated by NetworkManager


# No nameservers found; try putting DNS servers into your
# ifcfg files in /etc/sysconfig/network-scripts like so:
#
# DNS1=xxx.xxx.xxx.xxx
# DNS2=xxx.xxx.xxx.xxx
# DOMAIN=lab.foo.com bar.foo.com

上述结果表示并没有配置DNS。

正确的解决方式:

[root@vhost03 ~]# cd /etc/sysconfig/network-scripts/

[root@vhost03 network-scripts]# cp ifcfg-eth0 ifcfg-eth0.bak
[root@vhost03 network-scripts]# vi ifcfg-eth0

DEVICE="eth0"
BOOTPROTO="dhcp"
HWADDR="00:0C:29:D7:D2:49"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"

[root@vhost03 Desktop]# service network restart

[root@vhost03 Desktop]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0C:29:D7:D2:49 
          inet addr:192.168.196.135  Bcast:192.168.196.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fed7:d249/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:222887 errors:0 dropped:0 overruns:0 frame:0
          TX packets:29460 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:147116593 (140.3 MiB)  TX bytes:3667288 (3.4 MiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:18 errors:0 dropped:0 overruns:0 frame:0
          TX packets:18 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:1064 (1.0 KiB)  TX bytes:1064 (1.0 KiB)

[root@vhost02 ~]#  netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
192.168.196.0   0.0.0.0         255.255.255.0   U         0 0          0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
0.0.0.0         192.168.196.2   0.0.0.0         UG        0 0          0 eth0

[root@vhost03 Desktop]# more /etc/resolv.conf
# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.196.2

根据上面的信息重新配置ifcfg-eth0文件

[root@vhost03 ~]# cd /etc/sysconfig/network-scripts/

DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:0C:29:D7:D2:49"
IPV6INIT="yes"
NM_CONTROLLED="yes"

ONBOOT="yes"
TYPE="Ethernet"
UUID="f08dcf57-d670-46b3-8298-240cd0b76bc2"
IPADDR=192.168.196.129
BROADCAST=192.168.196.255
NETMASK=255.255.255.0
GATEWAY=192.168.196.2

[root@vhost03 ~]# cd /etc/sysconfig/network-scripts/

[root@vhost03 network-scripts]# service network restart

[root@vhost03 network-scripts]# vi /etc/resolv.conf

# Generated by NetworkManager
domain localdomain
search localdomain
nameserver 192.168.196.2

[root@vhost03 ~]# ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.
64 bytes from 115.239.210.27: icmp_seq=1 ttl=128 time=6.46 ms
64 bytes from 115.239.210.27: icmp_seq=2 ttl=128 time=7.00 ms

ok,问题解决。分析下来,看来是之前获取的历史网卡信息变了,导致不能ping外网。之前有在其它网络环境下重启过宿主机,应该和这个有关。解决问题的时候发现,只要重启网卡就会出现/etc/resolv.conf 被重置的现象。这是因为

[root@vhost02 ~]# chkconfig --list |grep -i network
NetworkManager  0:off   1:off   2:on    3:on    4:on    5:on    6:off
network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@vhost02 ~]# service NetworkManager stop

NetworkManager进程会实时修改/etc/resolv.conf 中的信息


 

ping: unknown host baidu.com

标签:

原文地址:http://www.cnblogs.com/janehoo/p/5594921.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!