插入一条到13.1.1.0/24这个网段的路由从eth0出去
[[email protected] ~]# route add -net 13.1.1.0 netmask 255.255.255.0 dev eth0
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
12.1.1.0 * 255.255.255.0 U 0 0 0 eth0
13.1.1.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
default 12.1.1.2 0.0.0.0 UG 0 0 0 eth0
删除一条到13.1.1.0/24这个网段的路由从eth0出去的路由
[[email protected] ~]# route del -net 13.1.1.0 netmask 255.255.255.0 dev eth0
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
12.1.1.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
default 12.1.1.2 0.0.0.0 UG 0 0 0 eth0
[[email protected] ~]# route add -net 13.1.1.0 netmask 255.255.255.0 dev eth0
SIOCADDRT: No route to host,因为设置的网关地址不可达所以报错
[[email protected] ~]# route add default gw 12.1.1.13 #设置一个默认网关
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
12.1.1.0 * 255.255.255.0 U 0 0 0 eth0
13.1.1.0 - 255.255.255.0 ! 0 - 0 -
link-local * 255.255.0.0 U 1002 0 0 eth0
default 12.1.1.13 0.0.0.0 UG 0 0 0 eth0
default 12.1.1.2 0.0.0.0 UG 0 0 0 eth0
[[email protected] ~]# route add -net 0.0.0.0 netmask 0.0.0.0 gw 12.1.1.10 设置一个默认网关(删除的时候必须把add换成del删除)
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
12.1.1.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
default 12.1.1.10 0.0.0.0 UG 0 0 0 eth0
default 12.1.1.2 0.0.0.0 UG 0 0 0 eth0
[[email protected] ~]# route del default gw 12.1.1.13 #删除一个默认网关
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
12.1.1.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
default 12.1.1.2 0.0.0.0 UG 0 0 0 eth0
#添加一条屏蔽的路由
[[email protected] ~]# route add -net 13.1.1.0 netmask 255.255.255.0 dev eth0 reject
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
12.1.1.0 * 255.255.255.0 U 0 0 0 eth0
13.1.1.0 - 255.255.255.0 ! 0 - 0 -
link-local * 255.255.0.0 U 1002 0 0 eth0
default 12.1.1.2 0.0.0.0 UG 0 0 0 eth0
#删除一条屏蔽的路由
[[email protected] ~]# route del -net 13.1.1.0 netmask 255.255.255.0 dev eth0 reject
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
12.1.1.0 * 255.255.255.0 U 0 0 0 eth0
link-local * 255.255.0.0 U 1002 0 0 eth0
default 12.1.1.2 0.0.0.0 UG 0 0 0 eth0