route命令参数详细说明及常用命令
原文地址 docs.lvrui.io
> route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default localhost 0.0.0.0 UG 100 0 0 eno16780032
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
192.168.10.0 0.0.0.0 255.255.255.0 U 100 0 0 eno16780032
macOS 中使用 netstat -nr
命令来查看当前路由表
route add –host 192.168.59.2 dev eth1
route add –host 192.168.59.2 gw 192.168.10.85
route add -net 192.168.248.0/24 gw 192.168.10.85
route add –net 192.168.248.0 netmask 255.255.255.0 gw 192.168.10.85
route add –net 192.168.248.0 netmask 255.255.255.0 dev eth1
route add default gw 192.168.10.85
route add -net 0.0.0.0 gw 192.168.10.85
使用 route 命令添加的路由,机器重启或者网卡重启后路由就失效了
route del –host 192.168.10.85 dev eth1
怎么 add 的就怎么 del 掉. 但是 del 的时候可以不写网关
在/etc/rc.local
里添加路由信息
route add -net 192.168.247.0/24 dev eth1
route add -net 192.168.110.0/24 gw 192.168.10.85
在/etc/sysconfig/network
里添加到末尾GATEWAY=gw-ip 或者 GATEWAY=gw-dev
在/etc/sysconfig/static-router
添加any net x.x.x.x/24 gw y.y.y.y
CentOS7 下推荐使用上面第三种方法添加永久静态路由
[root@centos7 ~]
10.15.150.0/24 via 192.168.150.253 dev enp0s3
10.25.250.0/24 via 192.168.150.253 dev enp0s3
将永久静态路由需要写到 /etc/sysconfig/network-scripts/route-interface 文件中
注意:
ifcfg-enp0s3 文件改名为 ifcfg-eth0 后,route-enp0s3 文件也要改名为 route-eth0
参考文档:
如果这篇文章对你有所帮助,可以通过下边的“打赏”功能进行小额的打赏。
本网站部分内容来源于互联网,如有侵犯版权请来信告知,我们将立即处理。