Linux;route
在Linux中,有时候需要手动添加路由。
在过去的日志里,介绍了这方面的需求在MS Windows中的实现:http://d-prototype.com/archives/704。
在Linux中,通过命令“route”完成。
具体如下:
1 2 3 4 5 6 7 8 9 10 |
[root@adamhuanlinux ~]# route add -net 1**.0.1.0 netmask 255.255.255.0 gw 1**.0.1.* [root@adamhuanlinux ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 1**.0.1.** 0.0.0.0 UG 100 0 0 enp2s0 1**.0.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enp2s0 1**.16.1.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet1 1**.16.10.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet8 1**.0.1.0 1**.0.1.* 255.255.255.0 UG 0 0 0 enp2s0 [root@adamhuanlinux ~]# |
————————————————————
Done。
要显示当前系统中的路由信息,还可以用以下的方式实现:
[root@adamhuan-linux ~]# route -v
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 168.0.1.37 0.0.0.0 UG 100 0 0 enp2s0
166.100.0.0 168.0.1.2 255.255.255.0 UG 0 0 0 enp2s0
168.0.1.0 0.0.0.0 255.255.255.0 U 100 0 0 enp2s0
[root@adamhuan-linux ~]#
route add -net 192.168.2.0 netmask 255.255.255.0 gw dev eth0 netstat -rnroute del default dev eth0route add default gw 192.168.1.1ip route showsudo ip route add default via $GATEWAYroute add default gw {IP-ADDRESS} {INTERFACE-NAME}参考文档:http://www.cnblogs.com/snake-hand/p/3143041.html