需要添加固定的路由。防止重启,断网无法上网。
ubuntu 下
vi /etc/rc.local
添加如下一行。
route add default gw 10.0.2.1(默认网关)
静态ip配置
sudo vi /etc/network/interfaces
auto lo
iface lo inet loopback
auto enp0s3
iface enp0s3 inet static
address 10.0.2.6
auto enp0s8
iface enp0s8 inet static
address 192.168.56.12
netmast 255.255.255.0
gateway 192.168.56.2
dns-nameservers 10.0.2.1 192.168.56.2 8.8.8.8
centos下。
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
BOOTPROTO=yes
DEFROUTE=yes
NAME=enp0s3
DEVICE=enp0s3
ONBOOT=yes
IPADDR=10.0.2.5
GATEWAY=10.0.2.2
DNS1=10.0.2.2
NETMASK=255.255.255.0