最好的办法就是使用两块网卡,NAT(虚拟机访问互联网,使用10.0.2.X段)和host-only(虚拟机和主机互相通信,使用192.168.56.X段).

注意:需要将虚拟机关闭后,才能添加虚拟机的网卡




eth0不需设置gateway,设置了会导致无法访问外网
# This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # The primary network interface auto eth0 iface eth0 inet static address 192.168.56.106 netmask 255.255.255.0 auto eth1 iface eth1 inet dhcp ~
注意不能设置GATEWAY,原因:Linux双网卡默认路由问题: 在安装第二块网卡后出现无法上网问题,使用route发现是默认路由出现问题
本文详细介绍了如何通过配置两块网卡实现虚拟机内外网同时访问的方法。具体步骤包括为虚拟机分配NAT和host-only两种网络模式,并针对不同网卡设置静态IP地址和DHCP获取方式。此外还特别强调了避免设置默认网关以防止网络连接问题。
904

被折叠的 条评论
为什么被折叠?



