CentOS7配置静态路由有多种方式:
1、临时配置方法:
#ip route add 192.168.100.0/24 via 172.16.16.254 dev eth0
此时,访问192.168.100.0/24网段,将通过eth0网卡转出,下一跳指向172.16.16.254、注意:临时添加路由的方法无需重启网卡,立即生效,但是如果对网卡进行了重启,临时路由会立即丢失,有可能造成断网。
2、永久生效方式:
在/etc/sysconfig/network-scripts/目录下创建route-eth*配置文件,其中eth*为对应的网卡编号,即静态路由的出口网卡,该配置文件中的路由出口信息,必须与此文件名编号一致,否者将造成网卡启动失败,导致断网。
#cat /etc/sysconfig/network-scripts/route-eth0 192.168.101.0/24 via 172.16.16.254 dev eth0 192.168.102.0/24 via 172.16.16.254 dev eth0 192.168.103.0/24 via 172.16.16.254 dev eth0
3、查看路由信息
[[email protected]]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.3.254 0.0.0.0 UG 100 0 0 eth1 172.16.0.0 0.0.0.0 255.255.0.0 U 100 0 0 eth0 192.168.3.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1 192.168.101.0 172.16.16.254 255.255.255.0 UG 100 0 0 eth0 192.168.102.0 172.16.16.254 255.255.255.0 UG 100 0 0 eth0 192.168.103.0 172.16.16.254 255.255.255.0 UG 100 0 0 eth0
原文地址:https://www.cnblogs.com/itbox/p/11569687.html
时间: 2025-01-02 18:29:05