【Ubuntu日常技巧】VirtualBox多网卡路由配置,保障虚拟机连接上外网

背景】: 配置Ubuntu 虚拟机双网卡,一个是Host-Only网络,一个是桥接网络。当在虚拟机中同时连接到两个网络后,虚拟机能够ping通内部网络,不能ping通外部网络,如www.baidu.com。

1. 虚拟机网卡配置

    

2. 虚拟机内部网络配置

HostOnly网络配置:                                   

桥接网络配置:

 

3.检查虚拟机网络

 ping不通外网,查看路由表。

 

失败原因: 发现default路由是HostOnly 的网络,网段是56段的,不能与外网相通;将default路由修改为1段(192.168.1.X)的。

4.修改default路由

dev@dev-VirtualBox:~$ sudo route add default gw 192.168.1.1
dev@dev-VirtualBox:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth1
default         192.168.56.1    0.0.0.0         UG    0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     1      0        0 eth1
192.168.56.0    *               255.255.255.0   U     1      0        0 eth0

 

 修改后发现有两个default路由,然后出现了Dns,无法进行域名解析。

 解决方案:

 删除56网段的default路由

dev@dev-VirtualBox:~$ sudo route del default gw 192.168.56.1
dev@dev-VirtualBox:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth1
192.168.1.0     *               255.255.255.0   U     1      0        0 eth1
192.168.56.0    *               255.255.255.0   U     1      0        0 eth0

 

 

 

还有一种比较简单的方案,在创建虚拟机网卡时,设置虚拟机网卡顺序为:网卡1 桥接网络; 网卡2HostOnly网络。

 

 

转载于:https://www.cnblogs.com/QuLory/p/4472135.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值