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

解决虚拟机连接不上外网,不能互相ping通

时间:2018-08-16 17:46:11      阅读:752      评论:0      收藏:0      [点我收藏+]

标签:pack   接口   --   host   1.5   service   static   重启   ipaddr   

0、解决虚拟机连接不上外网,不能互相ping通

直接在linux系统下,编辑修改如下文件:

//编辑文件/etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost install]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 
//查看文件/etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost install]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0 
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.20.129
NETMASK=255.255.255.0
GATEWAY=192.168.20.2    
DNS1=101.198.199.200
DNS2=114.114.114.114
//重启网卡
[root@localhost install]# service network restart
正在关闭接口 eth0:                                        [确定]
关闭环回接口:                                             [确定]
弹出环回接口:                                             [确定]
弹出界面 eth0:                                            [确定]
//尝试ping主机
[root@localhost install]# ping 192.168.1.125
PING 192.168.1.125 (192.168.1.125) 56(84) bytes of data.
64 bytes from 192.168.1.125: icmp_seq=1 ttl=128 time=0.893 ms
64 bytes from 192.168.1.125: icmp_seq=2 ttl=128 time=0.747 ms
64 bytes from 192.168.1.125: icmp_seq=3 ttl=128 time=0.583 ms
^C
--- 192.168.1.125 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2952ms
rtt min/avg/max/mdev = 0.583/0.741/0.893/0.126 ms
//尝试ping外网百度
[root@localhost install]# ping www.baidu.com
PING www.a.shifen.com (115.239.211.112) 56(84) bytes of data.
64 bytes from 115.239.211.112: icmp_seq=1 ttl=128 time=42.6 ms
64 bytes from 115.239.211.112: icmp_seq=2 ttl=128 time=39.1 ms
^C
--- www.a.shifen.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1653ms
rtt min/avg/max/mdev = 39.128/40.876/42.625/1.760 ms

注意:

DNS一定要和主机的一样,如下图:

技术分享图片

1、 如果还是不能解决,可以尝试将文件按照如下格式修改:

//编辑文件/etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost install]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 
//查看文件/etc/sysconfig/network-scripts/ifcfg-eth0
[root@localhost install]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
[root@localhost install]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
TYPE=Ethernet                    
BOOTPROTO=static                    
DEFROUTE=yes                    
IPV4_FAILURE_FATAL=no            
IPV6INIT=no
IPV6_AUTOCONF=no
IPV6_DEFROUTE=no
IPV6_PEERDNS=no
IPV6_PEERROUTES=no
IPV6_FAILURE_FATAL=no
NAME=eth0
UUID=17c77773-bc60-40d0-b4e3-e9f22ca1841b
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.20.129
PREFIX=24
GATEWAY=192.168.20.2    
DNS1=101.198.199.200
DNS2=114.114.114.114
HWADDR="00:0C:29:0B:91:B7"

 注意:

UUID的获取:

[root@localhost install]# uuidgen eth0
17c77773-bc60-40d0-b4e3-e9f22ca1841b

HWADDR的获取:

技术分享图片

这下就能虚拟机完美上网了:

技术分享图片

 

解决虚拟机连接不上外网,不能互相ping通

标签:pack   接口   --   host   1.5   service   static   重启   ipaddr   

原文地址:https://www.cnblogs.com/mmzs/p/9488213.html

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