路由表和(iproute2 与 net-tools)

路由表和(iproute2 与 net-tools)

我有以下路由表:

# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.42.129  0.0.0.0         UG    0      0        0 enx6a58445c5d43
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 enx6a58445c5d43
192.168.42.0    0.0.0.0         255.255.255.0   U     0      0        0 enx6a58445c5d43
192.168.57.0    0.0.0.0         255.255.255.0   U     0      0        0 vboxnet1

当我使用以下命令时出现错误:

# ip route add 192.168.42.0/24 via  192.168.57.1 dev vboxnet1
RTNETLINK answers: File exists

但是当我从 net-tools 使用时,我没有收到任何错误:

# route add -net 192.168.42.0/24 gw   192.168.57.1 dev vboxnet1
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.42.129  0.0.0.0         UG    0      0        0 enx6a58445c5d43
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 enx6a58445c5d43
192.168.42.0    192.168.57.1    255.255.255.0   UG    0      0        0 vboxnet1 ####add here
192.168.42.0    0.0.0.0         255.255.255.0   U     0      0        0 enx6a58445c5d43
192.168.57.0    0.0.0.0         255.255.255.0   U     0      0        0 vboxnet1

问题是:如何通过iproute2添加?

答案1

您的路由表中有网络地址 192.168.42.0/24。所以你必须:

ip route replace 192.168.42.0/24 via 192.168.57.1 dev vboxnet1 

或者

ip route del 192.168.42.0/24 
ip route add 192.168.42.0/24 via 192.168.57.1 dev vboxnet1 

相关内容