Native Environment: Centos
Their virtual machines have recently been unable to network, the status quo is as follows:
[[email protected] ~]# Ping baidu.com
Ping:unknown Host Baidu.com
View the network card configuration for the next computer:
[Email protected] ~]# 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
The newly installed virtual machines are DHCP-acquired IPs by default. In order to ensure the IP fixed, self-updated network card information, using the static mode. The yellow background part is the information obtained by using the Ifconfig command when following the DHCP mode.
To view DNS information:
[Email protected] ~]# 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
The above results indicate that DNS is not configured.
The right way to solve the problem:
[Email protected] ~]# cd/etc/sysconfig/network-scripts/
[email protected] network-scripts]# CP Ifcfg-eth0 Ifcfg-eth0.bak
[Email protected] 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"
[Email protected] desktop]# service network restart
[email protected] 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)
[email protected] ~]# 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
[Email protected] desktop]# more/etc/resolv.conf
# Generated by NetworkManager
Domain Localdomain
Search Localdomain
NameServer 192.168.196.2
Reconfigure the Ifcfg-eth0 file based on the information above
[Email protected] ~]# 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
[Email protected] ~]# cd/etc/sysconfig/network-scripts/
[Email protected] network-scripts]# service network restart
[email protected] network-scripts]# vi/etc/resolv.conf
# Generated by NetworkManager
Domain Localdomain
Search Localdomain
NameServer 192.168.196.2
[[email protected] ~]# Ping www.baidu.com
PING www.a.shifen.com (115.239.210.27) bytes of data.
Bytes from 115.239.210.27:icmp_seq=1 ttl=128 time=6.46 ms
Bytes from 115.239.210.27:icmp_seq=2 ttl=128 time=7.00 ms
OK, problem solved. Analysis down, it appears that the previous access to the history NIC information has changed, resulting in the inability to ping the outside network. It should be related to the previous restart of the host in another network environment. When solving the problem, it is found that the /etc/resolv.conf is reset as soon as the network card is restarted. This is because
[Email protected] ~]# 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
[[Email protected] ~]# service NetworkManager stop
The NetworkManager process modifies the information in the /etc/resolv.conf in real time
Ping:unknown Host Baidu.com