Linux 路由的添加刪除-ip route


一、路由查看

# 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 掩碼轉換到網絡可用地址的數量

 

 

 

 

 

 

 

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM