virtualbox虚拟机NAT模式下不能连接外网

在他人博客的帮助下。
目前情况为:
在这里插入图片描述我不知道哪个是默认路由。应该是Destination为0.0.0.0的为默认路由吧

虚拟机:virtualbox
系统:centos 6.5
问题:虚拟机有2块网卡,NAT+ host-only, 可以ping通 192.168.56.1网关,ping不通宿主机,宿主机可以ping通虚拟机
原因:在路由表中,默认网关被设置成了192.168.56.1(而非10.0.2.2)
解决:删除网卡配置文件中的“GATEWAY=x.x.x.x”即可
具体:1. 确认问题,输入命令 route,结果中 Destination 为 default 项的 Gateway的值为"10.0.2.2"以外的值,且Flags为“UG”2. 删除2块网卡配置文件/etc/sysconfig/network-scripts/ifcfg-ethX 中的“GATEWAY=x.x.x.x”3. 在/etc/sysconfig/network文件中加入“GATEWAY=10.0.2.2”(可省略,如果第二步的配置文件中不存GATEWAY=x.x.x.x)

如果在第二步中不存在GATEWAY=x.x.x.x,也可以做第三步
重启虚拟机
可以ping通外网。

以上,解决方法也有可能是只是重启虚拟机就可以了,不需要多余操作

经过实验,好像确实只重启虚拟机就可以了。

知识补充:
连接外网

如何获取这个外网网卡的网关地址呢?virtualbox如下规定:

In NAT mode, the guest network interface is assigned to the IPv4 range 10.0.x.0/24 by default where x corresponds to the instance of the NAT interface +2. So x is 2 when there is only one NAT instance active. In that case the guest is assigned to the address 10.0.2.15, the gateway is set to 10.0.2.2 and the name server can be found at 10.0.2.3.

(https://www.virtualbox.org/manual/ch09.html#changenat)

使用nat网卡ping外网,hostonly网卡ping物理机

虚拟机ping自己要ping hostonly网卡的ip
要ping通的话要注意虚拟机以及物理机设置的映射。(hosts)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值