本文為joshua317原創文章,轉載請注明:轉載自joshua317博客 https://www.joshua317.com/article/236
一、路由查看
# 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
三、知識擴展
在線搜索:ip地址在線計算器
3.1 子網掩碼轉換器
3.2 掩碼轉換到網絡可用地址的數量
本文為joshua317原創文章,轉載請注明:轉載自joshua317博客 https://www.joshua317.com/article/236