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)

猜你喜欢

转载自www.cnblogs.com/xuyaowen/p/linux-route.html