Linux 查看 添加 修改路由


最近搭建vpn, 使用 ssh 隧道一直在涉及路由相關問題,今天簡單整理一下,方便下次使用:

查看路由:

[jsi@localhost Desktop]$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.134.150.0    *               255.255.254.0   U     1      0        0 eth2
default         10.134.150.1    0.0.0.0         UG    0      0        0 eth2
注: 哪條在前面, 哪條就有優先, 前面都沒有, 就用最后一條default
[jsi@localhost Desktop]$ netstat -nr
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.134.150.0    0.0.0.0         255.255.254.0   U         0 0          0 eth2
0.0.0.0         10.134.150.1    0.0.0.0         UG        0 0          0 eth2
[jsi@localhost Desktop]$ ip route show
10.134.150.0/23 dev eth2  proto kernel  scope link  src 10.134.151.44  metric 1 
default via 10.134.150.1 dev eth2  proto static 

添加路由(臨時):(永久添加可以配置初始化腳本添加)

使用route 命令添加的路由,機器重啟或者網卡重啟后路由就失效了,方法:
//添加到主機的路由
# route add –host 192.168.168.110 dev eth0
# route add –host 192.168.168.119 gw 192.168.168.1
//添加到網絡的路由
# route add –net IP netmask MASK eth0
# route add –net IP netmask MASK gw IP
# route add –net IP/24 eth1
//添加默認網關
# route add default gw IP
//刪除路由
# route del –host 192.168.168.110 dev eth0
ip ro add 192.56.76.0/24 dev 192.168.0.1#添加一條靜態路由
ip ro add default via 192.168.0.1 dev eth0#添加默認路由
ip ro del 192.168.1.0/24#刪除一條路由
ip route show#查看路由表
# 命令添加路由只是臨時起作用,重啟失效;

永久添加路由,我沒用到,就不在這里寫了。

常用路由命令備份:

route add -host 202.112.137.223 dev enp4s0 (2019年6月8日19:12:11)

route add -host 202.112.137.223 dev tun0 (2019年6月9日17:32:27)


免責聲明!

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



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