Debian 9 在 virtualbox 上运行。我有 2 个适配器,一个 NAT,另一个仅主机。这是我的 /etc/network/interfaces 文件:
allow-hotplug enp0s3
auto enp0s3
iface enp0s3 inet dhcp
allow-hotplug enp0s8
auto enp0s8
iface enp0s8 inet static
address 192.168.56.3
netmask 255.255.255.0
gateway 192.168.56.1
当我启动时,我将第二个接口作为默认网关,但我需要第一个接口。
手动运行此命令可以解决该问题:
ip route change default via 10.0.2.3
假设(?)因为这个IP是DHCP生成的(由virtualbox),我如何将其设置为启动时的默认路由?
如果有帮助,这是ip route show
(在该命令之后)的输出
default via 10.0.2.3 dev enp0s3
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15
169.254.0.0/16 dev enp0s8 scope link metric 1000
192.168.56.0/24 dev enp0s8 proto kernel scope link src 192.168.56.3
这是输出ip addr show
:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:b8:c5:ff brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:feb8:c5ff/64 scope link
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:c8:d2:fb brd ff:ff:ff:ff:ff:ff
inet 192.168.56.3/24 brd 192.168.56.255 scope global enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fec8:d2fb/64 scope link
valid_lft forever preferred_lft forever
答案1
删除allow-hotplug
线(你已经有了auto
)和gateway
线(手动设置默认网关)。