三种路由类型:
1.主机路由(H):路由选择表中指向单个Ip地址或者主机名的路由记录,Flags字段为H
2.网络路由(N):主机可以到达的网络,Flags字段为N
3.默认路由(G):当主机不能在路由表中查找到目标Ip地址或者网络路由时,数据包将发送到默认路由上,Flags字段为G
Flags为路由标志,编辑当前网络节点的状态
·U up代表路由当前为启动状态 ·H host表示此网关为一个主机 ·G gateway此网关为一个路由器 ·R reinstate route使用动态路由重新初始化的路由 ·D dynamically,此路由是动态写入的 ·M modified是有路由守护程序或导向器修改 ·! 此路由当前为关闭状态
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.0.7.253 0.0.0.0 UG 0 0 0 eth0
default 10.0.6.253 0.0.0.0 UG 1001 0 0 eth1
10.0.6.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
10.0.7.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.7.253 0.0.0.0 UG 0 0 0 eth0
0.0.0.0 10.0.6.253 0.0.0.0 UG 1001 0 0 eth1
10.0.6.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
10.0.7.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
route add default gw 10.0.7.253 dev eth0
route add default gw 10.0.6.253 dev eth1
route add -net 10.0.6.0 netmask 255.255.255.0 dev eth1
route add -net 10.0.7.0 netmask 255.255.255.0 dev eth0
添加
添加路由
route -v add
route add -net 192.168.56.0/24 dev eth0
route add -net 192.168.56.0/24 gw 192.168.56.1
route add -net 192.168.56.0 netmask 255.255.255.0 gw 192.168.56.1
route add -net 192.168.56.0 netmask 255.255.255.0 gw 192.168.56.1 dev eth0 metric 1
添加默认路由
route add default gw 192.168.56.1 dev eth0
route add -net 0.0.0.0 gw 192.168.56.1 netmask 0.0.0.0 dev eth0
删除
清空路由表
# ip route | awk '{print $1}' | while read line; do ip route del $line; done
删除路由
route -v del
route del -net 192.168.56.0 netmask 255.255.255.0
route del -net 192.168.56.0 netmask 255.255.255.0 dev eth0
route del -net 192.168.56.0 dev eth0
删除默认路由
route del default
route del default dev enp0s8
route del default dev enp0s9