容易忘记的命令之route

route命令
route - show /
manipulate the IP routing table 显示或修改路由表


显示路由表
route -n
这样的话命令执行的快一点,因为加上-n选项后,直接使用ip或者端口号,而不使用协议或主机名,少了一个解析的过程

liuliancao@liuliancao-K45VD:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags
Metric Ref    Use Iface
0.0.0.0         10.10.49.254    0.0.0.0         UG   
0      0        0 wlan0
10.10.49.0      0.0.0.0         255.255.255.0   U    
9      0        0 wlan0
liuliancao@liuliancao-K45VD:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags
Metric Ref    Use Iface
default         10.10.49.254    0.0.0.0         UG   
0      0        0 wlan0
10.10.49.0      *               255.255.255.0   U    
9      0        0 wlan0
liuliancao@liuliancao-K45VD:~$
注意上面的内容,由于我的是ubuntu,可能略有不同哈

第一列是目的地destination,和genmask就是目标网络,路由表一般按一定顺序排列,default表示默认路由。
第二列是网关,gateway,表示网络出口,网上经常说的看门的人,0.0.0.0表示本机
第四列flags,标志,U
up,G
use gateway ,D dynamic route
网络接口iface 通过哪个网卡实现向外传递数据包


路由表的增删

增加 
记住几个关键词 -net 完整网络 dev
route add -net  网络
( eg 192.168.1.0 netmask 255.255.255.0 )
 设备(eg dev eth0)


liuliancao@liuliancao-K45VD:~$ sudo route add -net
192.168.1.0  netmask 255.255.255.0 dev eth0
[sudo] password for liuliancao:
liuliancao@liuliancao-K45VD:~$ route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags
Metric Ref    Use Iface
0.0.0.0         10.10.49.254    0.0.0.0         UG   
0      0        0 wlan0
10.10.49.0      0.0.0.0         255.255.255.0   U    
9      0        0 wlan0
192.168.1.0     0.0.0.0         255.255.255.0   U    
0      0        0 eth0

删除同理
这里不再演示