在Rocky Linux中配置策略路由实现多网关分流
-
添加自定义路由表
echo '100 table1' >> /etc/iproute2/rt_tables echo '200 table2' >> /etc/iproute2/rt_tables
-
为每个接口配置默认网关
- 编辑接口配置文件(如
/etc/sysconfig/network-scripts/route-eth0
):default via 192.168.1.1 dev eth0 table table1
- 同理在
route-eth1
中为第二个接口设置网关:default via 10.0.0.1 dev eth1 table table2
- 编辑接口配置文件(如
-
定义策略路由规则
- 在
/etc/sysconfig/network-scripts/rule-eth0
添加:from 192.168.1.0/24 lookup table1
- 在
rule-eth1
中设置:from 10.0.0.0/24 lookup table2
- 在
-
应用配置
systemctl restart network
验证:
ip route show table table1
检查分流路由ip rule list
确认策略规则生效