一、问题描述
切换到桥接模式,获取ip并固定后,只能在局域网内通信,ping不通公网(百度,114.114,114.114等)
[root@localhost ~]# ping 10.36.192.66 #局域网内可以ping通
PING 10.36.192.66 (10.36.192.66) 56(84) bytes of data.
64 bytes from 10.36.192.66: icmp_seq=1 ttl=64 time=0.336 ms
64 bytes from 10.36.192.66: icmp_seq=3 ttl=64 time=0.598 ms
^C
--- 10.36.192.66 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.336/0.491/0.598/0.115 ms
[root@localhost ~]# ping baidu.com #不能ping通公网
ping: baidu.com: 未知的名称或服务
[root@localhost ~]# ping 114.114.114.114
PING 114.114.114.114 (114.114.114.114) 56(84) bytes of data.
^C
--- 114.114.114.114 ping statistics ---
33 packets transmitted, 0 received, 100% packet loss, time 32019ms
二、解决方法:
1.查看本机(不是虚拟机)的网关
win+r cmd
C:\Users\zhangxiao>ipconfig
以太网适配器 以太网:
连接特定的 DNS 后缀 . . . . . . . :
本地链接 IPv6 地址. . . . . . . . : fe80::686c:8776:d99d:34df%3
IPv4 地址 . . . . . . . . . . . . : 10.36.192.69
子网掩码 . . . . . . . . . . . . : 255.255.255.0
默认网关. . . . . . . . . . . . . : 10.36.192.1
2.若网关最后一位为1,修改网卡文件
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
IPADDR="10.36.192.66"
NETMASK="255.255.255.0"
GATEWAY="10.36.192.1" 将2修改为1
DNS1="114.114.114.114"
DNS2="8.8.8.8"
3.重启网卡
[root@localhost ~]# systemctl restart network
4.ping公网
[root@localhost ~]# ping baidu.com
PING baidu.com (39.156.66.10) 56(84) bytes of data.
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=1 ttl=49 time=41.3 ms
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=2 ttl=49 time=78.7 ms
64 bytes from 39.156.66.10 (39.156.66.10): icmp_seq=3 ttl=49 t