设置linux路由

我试图build立的系统有一个IP地址172.31.2.1 。 它的默认网关是172.31.254.1 。 这工作正常,我可以达到任何网关允许我去( 172.31.0.0/16 + 149.244.178.0/24 )。

还有另外一个网关149.244.178.1 ,它可以让我达到149.244.0.0中的任何东西,我试图把它添加到表中,所以我可以访问149.244.64.250

这是我的路由表目前看起来像:

Kernel IP Routing table Destination Gateway Genmask Flags Metric Ref Use Iface 172.31.0.0 * 255.255.0.0 U 0 0 0 eth0 169.254.0.0 * 255.255.0.0 U 0 0 0 eth0 default 172.31.254.1 0.0.0.0 UG 0 0 0 eth0 

路由添加149.244.0.0/16 gw 1​​49.244.178.1给出的错误:

 route: netmask 0000ffff doesn't make sense with host route. 

route add -net 149.244.0.0/16 dev eth0将路由表更改为:

 Kernel IP Routing table Destination Gateway Genmask Flags Metric Ref Use Iface 172.31.0.0 * 255.255.0.0 U 0 0 0 eth0 169.254.0.0 * 255.255.0.0 U 0 0 0 eth0 149.244.0.0 * 255.255.0.0 U 0 0 0 eth0 default 172.31.254.1 0.0.0.0 UG 0 0 0 eth0 

但是,试图添加网关仍然给我同样的错误。 对不起,如果听起来令人费解,任何帮助表示赞赏!

149.xxx主机不会在您的本地子网上,所以您的电脑将无法联系它。 您的子网和该子网之间的路由器应具有149.x和172.x地址(希望在两个不同的NIC上),它将在两个子网之间路由。