注
:
场景说明
操作如下
# 指定 172.0.0.0/8 网段流量通过网卡em1的网关进行处理,此方式重启网络后配置会重置
route add -net 172.0.0.0/8 gw 172.16.138.1 dev em1 metric 100
# 删除路由 route del -net 172.0.0.0/8 gw 172.16.138.1 dev em1
# 网卡配置文件添加静态路由配置
$ vim /etc/sysconfig/network-scripts/ifcfg-em1
POSTROUTING_SCRIPT=/etc/sysconfig/network-scripts/route-em1
# 路由文件增加内容
$ vim /etc/sysconfig/network-scripts/route-em1
172.0.0.0/8 via 172.16.138.1 dev em1 metric 100
# 重启
systemctl restart network
# 查看路由,这里的 192.168.1.1 是另外一块网卡的网关地址
[root@hukanfa ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 101 0 0 em2
172.0.0.0 172.16.138.1 255.0.0.0 UG 100 0 0 em1