一、路由查看
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway 0.0.0.0 UG 0 0 0 eth0
link-local 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
172.21.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 172.21.0.1 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
172.21.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
# ip route show
default via 172.21.0.1 dev eth0
169.254.0.0/16 dev eth0 scope link metric 1002
172.21.0.0/20 dev eth0 proto kernel scope link src 172.21.0.15
# ip route list
default via 172.21.0.1 dev eth0
169.254.0.0/16 dev eth0 scope link metric 1002
172.21.0.0/20 dev eth0 proto kernel scope link src 172.21.0.15
# netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 172.21.0.1 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
172.21.0.0 0.0.0.0 255.255.240.0 U 0 0 0 eth0
二、路由新增
# 1.添加默认路由信息,其中172.21.0.1是网关地址。
# ip route add default via 172.21.0.1 dev eth0
# 或者
# route add default gw 172.21.0.1
# 2.添加网络路由
# route add -net 172.21.0.0/24 netmask 255.255.255.0 dev eth0
#或者简写
# route add -net 172.21.0.0/24 dev eth0
#添加一条路由(发往172.21.0这个网段的全部要经过网关172.21.0.1)
route add -net 172.21.0.0/24 netmask 255.255.255.0 gw 172.21.0.1
# 3.添加主机的路由
# route add -host 172.21.0.64/32 dev eth0
# 或者具体地址
# route add -host 172.21.0.64 dev eth0
三、路由删除
# 1.删除默认路由信息
# ip route del default via 172.21.0.1 dev eth0
# 2.删除网络路由
# route del -net 172.2.1.0/24netmask 255.255.255.0 dev eth0
# 或者简写
# route add -net 172.2.1.0/24 dev eth0
# 3.删除主机的路由
# route del -host 172.2.0.64/32 dev eth0
# 或者
# route del -host 172.21.0.64 dev eth0
注意:路由规则变更后,需要重启
#删除完后,需要重启网络
# systemctl restart network
#查看路由信息
# route -n
网友评论