A-A+

linux下ip与网关不在同一段配置的方法

2016年01月02日 站长资讯 暂无评论

当想要设置的网关与主机ip地址不同时,用route add default gw xx.xxx.xx.xx是不成功的,比如我主机ip地址为:192.168.1.3,想要设置的网关为192.168.2.1。

  1. root@ubuntu:/etc/network# route add default gw 192.168.2.1  
  2. SIOCADDRT: No such process  
  3. root@ubuntu:/etc/network#   

解决办法:

  1. root@ubuntu:/etc/network# route add -host  192.168.2.1 dev eth0  
  2. root@ubuntu:/etc/network# route add default gw  192.168.2.1 dev eth0  
  3. root@ubuntu:/etc/network# route  
  4. Kernel IP routing table  
  5. Destination     Gateway         Genmask         Flags Metric Ref    Use Iface  
  6. 192.168.2.1     *               255.255.255.255 UH    0      0        0 eth0  
  7. 192.168.1.0     *               255.255.255.0   U     1      0        0 eth0  
  8. link-local      *               255.255.0.0     U     1000   0        0 eth0  
  9. default         192.168.2.1     0.0.0.0         UG    0      0        0 eth0  
  10. default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0  
  11. root@ubuntu:/etc/network#   

设置成功。

标签:

给我留言