网络配置 | 2011-06-26
Linux route命令备忘
本章要点
本章正文
查看本机路由表信息:route
[inbi@debian ~]#route kernel IP routing table
destination | Gateway | Genmask | Flags | Metric | Ref | Use | Iface |
192.168.1.228 | * | 255.255.255.255 | UH | 0 | 0 | 0 | eth1 |
10.0.2.0 | * | 255.255.255.0 | U | 0 | 0 | 0 | eth0 |
default | 10.0.2.2 | 0.0.0.0 | UG | 0 | 0 | 0 | eth0 |
添加路由表:route add
[inbi@debian ~]#route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.228 dev eth1 [inbi@debian ~]#route add -host 10.0.2.222 gw 10.0.2.2 dev eth0 [inbi@debian ~]#route add default gw 192.168.1.228 dev eth1 [inbi@debian ~]#route kernel IP routing table
destination | Gateway | Genmask | Flags | Metric | Ref | Use | Iface |
10.0.2.222 | 10.0.2.2 | 255.255.255.255 | UGH | 0 | 0 | 0 | eth0 |
192.168.2.0 | * | 255.255.255.0 | UG | 0 | 0 | 0 | eth1 |
192.168.1.228 | * | 255.255.255.255 | UH | 0 | 0 | 0 | eth1 |
10.0.2.0 | * | 255.255.255.0 | U | 0 | 0 | 0 | eth0 |
default | 192.168.1.228 | 0.0.0.0 | UG | 0 | 0 | 0 | eth1 |
default | 10.0.2.2 | 0.0.0.0 | UG | 0 | 0 | 0 | eth0 |
路由表是由上向下匹配的,如已匹配就不再匹配了。
删除路由表:route del
[inbi@debian ~]#route del -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.228 dev eth1 [inbi@debian ~]#route del -host 10.0.2.222 gw 10.0.2.2 dev eth0 [inbi@debian ~]#route del default gw 192.168.1.228 dev eth1 [inbi@debian ~]#route kernel IP routing table
destination | Gateway | Genmask | Flags | Metric | Ref | Use | Iface |
192.168.1.228 | * | 255.255.255.255 | UH | 0 | 0 | 0 | eth1 |
10.0.2.0 | * | 255.255.255.0 | U | 0 | 0 | 0 | eth0 |
default | 10.0.2.2 | 0.0.0.0 | UG | 0 | 0 | 0 | eth0 |
除非注明,文章均为原创,采用 CC BY-NC-SA 2.5 许可,转载和引用需保留署名,并以链接形式标明原文出处:
IT手记 | http://www.itwhy.org/2011/06-26/368.html