当想要设置的网关与主机ip地址不同时,用route add default gw xx.xxx.xx.xx是不成功的,比如我主机ip地址为:192.168.1.3,想要设置的网关为192.168.2.1。
root@ubuntu:/etc/network# route add default gw 192.168.2.1
SIOCADDRT: No such process
root@ubuntu:/etc/network#
解决办法:
root@ubuntu:/etc/network# route add -host 192.168.2.1 dev eth0
root@ubuntu:/etc/network# route add default gw 192.168.2.1 dev eth0
root@ubuntu:/etc/network# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.1 * 255.255.255.255 UH 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth0
default 192.168.2.1 0.0.0.0 UG 0 0 0 eth0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
root@ubuntu:/etc/network#
设置成功。
转载于:https://blog.51cto.com/liuxiangtaojob/1609784