0、解决虚拟机连接不上外网,不能互相ping通
直接在linux系统下,编辑修改如下文件:
//编辑文件/etc/sysconfig/network-scripts/ifcfg-eth0 [[email protected] install]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 //查看文件/etc/sysconfig/network-scripts/ifcfg-eth0 [[email protected] 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 //重启网卡 [[email protected] install]# service network restart 正在关闭接口 eth0: [确定] 关闭环回接口: [确定] 弹出环回接口: [确定] 弹出界面 eth0: [确定] //尝试ping主机 [[email protected] 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外网百度 [[email protected] 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 [[email protected] install]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 //查看文件/etc/sysconfig/network-scripts/ifcfg-eth0 [[email protected] install]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 [[email protected] 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的获取:
[[email protected] install]# uuidgen eth0 17c77773-bc60-40d0-b4e3-e9f22ca1841b
HWADDR的获取:
这下就能虚拟机完美上网了:
原文地址:https://www.cnblogs.com/mmzs/p/9488213.html
时间: 2024-10-10 15:28:13