Linux解决ip ping不通百度的问题:
把 Linux 的网段设置为电脑的网段:
-
更改网络适配器选项中的VM8的IPV4的属性
VMware安装完成之后默认是会在Windows安装两块网卡的,一块是VMnet1另一块是VMnet8。
可以 win + r 输入 ncpa.cpl 命令查看。
1、在仅主机模式下:Window用VMnet1的网卡与虚拟机通信。
2、在NAT模式下:Window用VMnet8的网卡与虚拟机通信。win + r 输入 ncpa.cpl 命令查看VMware安装的两块网卡,一块是VMnet1另一块是VMnet8。
将 自动分配给Linux地址的方式改为 固定IP,原因:系统更新后网段重置会给分配个错误的地址
注意:VM8 的 IPV4 的 IP 网段 要与 电脑的网段 保持一致
此处 电脑网段为:192.168.150.43 , VM8 的 IP 为:192.168.150.55 。
ipconfig 查看 Windows 电脑 IP
- 虚拟机选择桥接模式
dhclient命令的作用是:使用动态主机配置协议动态的配置网络接口的网络参数,也支持BOOTP协议。语法格式:dhclient [参数] [网络接口]常用参数:-p指定dhcp客户端监听的端口号:默认
[redhat@localhost ~]$ su
Password:
[root@localhost redhat]# dhclient
[root@localhost redhat]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ll
total 4
-rwxrwxr-x. 1 root root 283 Apr 9 10:58 ifcfg-ens160
[root@localhost network-scripts]# cat ifcfg-ens160
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens160
UUID=6fbd8904-cb1d-4b64-932b-f96599b229e6
DEVICE=ens160
ONBOOT=yes
在 /etc/sysconfig/network-scripts/ifcfg-ens160 (确认ONBOOT=yes),其中 ens160 是设备名
ONBOOT是指明在系统启动时是否激活网卡,只有在激活状态的网卡才能去连接网络,进行网络通讯
修改参数 ONBOOT=yes
[root@localhost network-scripts]# vim ifcfg-ens160
[root@localhost network-scripts]#
也有一些教程增加配置了 IP 网关 等参数,但此处采用了 dhclient 命令 动态的配置网络接口的网络参数。不再额外配置。
dhclient命令的作用是:使用动态主机配置协议动态的配置网络接口的网络参数。
然后再将网卡重启
[root@localhost network-scripts]# service network restart
重启成功后尝试 ping
[root@localhost network-scripts]# ping www.baidu.com
PING www.wshifen.com (119.63.197.139) 56(84) bytes of data.
64 bytes from 119.63.197.139 (119.63.197.139): icmp_seq=1 ttl=54 time=4.70 ms
64 bytes from 119.63.197.139 (119.63.197.139): icmp_seq=2 ttl=54 time=5.51 ms
--- www.wshifen.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 10ms
rtt min/avg/max/mdev = 4.699/5.184/5.506/0.348 ms
如果没有成功,且采用动态配置的 IP:查看 动态配置的 IP 网段 是否与 电脑的网段 保持一致
或者如果自己配置了 IP 网关,则查看一下window本地的VM8的IP4的地址跟设置的匹配吗?
[root@localhost redhat]# ping www.baidu.com
PING www.wshifen.com (119.63.197.139) 56(84) bytes of data.
^C
--- www.wshifen.com ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 134ms
[root@localhost redhat]#
而此处碰到一个特别的问题,100% packet loss 丢包,调查发现是自己的 WIFI 链接需要验证的缘故。
通过 RHEL Linux 自带的 Firefox 浏览器 进行 WIFI 登录验证之后,该问题得到解决。如果没有 WIFI 链接验证 的情况请忽略。
采用 ifconfig -a 查看 动态配置的 IP,此处为:192.168.150.34
[root@localhost network-scripts]# ifconfig -a
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.150.34 netmask 255.255.255.0 broadcast 192.168.150.255
inet6 fe80::2276:1028:f2e5:f135 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:02:ef:75 txqueuelen 1000 (Ethernet)
RX packets 22426 bytes 10635866 (10.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10730 bytes 2627072 (2.5 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 60 bytes 7020 (6.8 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 60 bytes 7020 (6.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:2d:69:47 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0-nic: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:2d:69:47 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[root@localhost network-scripts]#
解决 Linux的网卡丢失问题
有时候使用ifconfig的时候发现网卡丢失了,就用以下步骤进行解决
- 定位位置
[root@localhost network-scripts]# cd /etc/sysconfig/network-scripts/
- 查看本文件
[root@localhost network-scripts]# ll
total 4
-rwxrwxr-x. 1 root root 283 Apr 9 10:58 ifcfg-ens160
[root@localhost network-scripts]# cat ifcfg-ens160
-
查看IP和网关是否对应
· 不正确就修改 -
修改无误之后运行以下命令
[root@localhost network-scripts]# service NetworkManager stop
- 再重启
[root@localhost network-scripts]# service network restart
自从电脑系统更新后第一次开虚拟机,结果遇到ping 不通www.baidu.com的问题,ping 8.8.8.8也是100%丢包。
结果发现系统更新后我的网段重置了。
把Linux的网段设置为电脑的网段就好了。