主机访问服务器上虚拟机ttl超时,手动配置网关,解决VMWare虚拟机内可以访问主机但无法访问互联网的问题...

常常都被虚拟机的网络折腾得颠三倒四,做点笔记吧。

问题:选择NAT后并配置好IP和NetMask之后,可以ping通主机,但连不通Internet。

解决:手动配置默认网关。

步骤:

在虚拟网络编辑器里,找到网关配置,这里是192.168.171.2 。

在虚拟机设置里,确认选择NAT。

IP和NetMask已经配置:

[root@localhost ~]# ifconfig ens33

ens33: flags=4163 mtu 1500

inet 192.168.171.128 netmask 255.255.255.0 broadcast 192.168.171.255

inet6 fe80::20c:29ff:feba:ba7c prefixlen 64 scopeid 0x20

ether 00:0c:29:ba:ba:7c txqueuelen 1000 (Ethernet)

RX packets 281023 bytes 361357640 (344.6 MiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 68897 bytes 14016800 (13.3 MiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

可以Ping通主机,但无法连接Internet:

[root@localhost ~]# ping 192.168.171.1

PING 192.168.171.1 (192.168.171.1) 56(84) bytes of data.

64 bytes from 192.168.171.1: icmp_seq=1 ttl=128 time=0.416 ms

64 bytes from 192.168.171.1: icmp_seq=2 ttl=128 time=0.318 ms

64 bytes from 192.168.171.1: icmp_seq=3 ttl=128 time=0.348 ms

64 bytes from 192.168.171.1: icmp_seq=4 ttl=128 time=0.262 ms

^C

— 192.168.171.1 ping statistics —

4 packets transmitted, 4 received, 0% packet loss, time 3001ms

rtt min/avg/max/mdev = 0.262/0.336/0.416/0.055 ms

[root@localhost ~]# ping 8.8.8.8

connect: Network is unreachable

检查路由表:

[root@localhost ~]# netstat -nr

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

192.168.171.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33

手动添加网关:

[root@localhost ~]# route add default gw 192.168.171.2

[root@localhost ~]# netstat -nr

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

0.0.0.0 192.168.171.2 0.0.0.0 UG 0 0 0 ens33

192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

192.168.171.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33

再次尝试:

[root@localhost ~]# ping 8.8.8.8

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.

64 bytes from 8.8.8.8: icmp_seq=1 ttl=128 time=23.4 ms

64 bytes from 8.8.8.8: icmp_seq=2 ttl=128 time=26.5 ms

64 bytes from 8.8.8.8: icmp_seq=3 ttl=128 time=22.5 ms

64 bytes from 8.8.8.8: icmp_seq=4 ttl=128 time=29.2 ms

^C

— 8.8.8.8 ping statistics —

4 packets transmitted, 4 received, 0% packet loss, time 3007ms

rtt min/avg/max/mdev = 22.524/25.448/29.255/2.666 ms

删除刚刚添加的网关,重现之前的错误:

[root@localhost ~]# route del default gw 192.168.171.2

[root@localhost ~]# netstat -nr

Kernel IP routing table

Destination Gateway Genmask Flags MSS Window irtt Iface

192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0

192.168.171.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33

[root@localhost ~]# ping 8.8.8.8

connect: Network is unreachable

参考链接:

https://www.freebsd.org/doc/h… https://unix.stackexchange.co…

本文由乐趣区整理发布,转载请注明出处,谢谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值