dynamic“路由添加”命令不起作用,但静态正在工作

我有一个情况在哪里

route add 

是不工作,但如果我添加,作为在sysconfig / network-scripts / route-eth0中的静态条目

它的工作

networking细节:

 IPADDR=198.xx1 NETMASK=255.255.255.255 BROADCAST=198.xx1 

如果我添加一个静态路由使用

 route add default gw 192.xx254 

它返回SIOCADDRT:没有这样的过程

simillary

 ping 192.xx254 

连接:networking无法访问

奇怪的是,如果我把它添加为route-eth0中的静态条目

 route add 192.xx254 dev eth0 route add default gw 192.xx254 

一切正常,我可以看到路由中的默认gw -n和ping也在工作

那么,这里有什么不同呢?

您不能添加该路由,因为该默认网关位于不同的子网中,因此无法访问。

从人路线:

  gw GW route packets via a gateway. NOTE: The specified gateway must be reachable first. This usually means that you have to set up a static route to the gateway beforehand. If you specify the address of one of your local interfaces, it will be used to decide about the interface to which the packets should be routed to. This is a BSDism compatibility hack. 

IPADDR = 198.xx1

NETMASK = 255.255.255.255

BROADCAST = 198.xx1

我假设你的ip是192.xx1(但是解释也对198.xx1有效),所以你创build一个扩展为0的子网(192.xx1 / 32),这意味着它限制了视图本身

如果我添加一个静态路由使用

路由添加默认gw 192.xx254

在这里你在你的子网的扩展之外添加一个网关,所以你会得到你的错误:

它返回SIOCADDRT:没有这样的过程

对于相同的共振,你不能ping任何IP除了你(192.xx1)

路由添加192.xx254 dev eth0

路由添加默认gw 192.xx254

在这里你添加到你的接口eth0一个路由到主机192.xx254,所以你的子网(单一的IP 192.xx1)知道在哪里find192.xx254,因此,当你添加它作为网关一切正常。 通过以前的configuration,您无法知道192.xx254在哪里。