OpenWRT 之数据包原路发回(多出口策略路由)

PS:请自行安装软件包 ip-full

eth0: 内网接口0
eth1: 外网线路1
eth2: 外网线路2

# 创建路由表
echo "51 way1" >> /etc/iproute2/rt_tables
echo "52 way2" >> /etc/iproute2/rt_tables
# 设置线路二
ip route flush table way1
ip route add 172.16.1.0/24 dev eth0 scope link table way1
ip route add 11.11.11.0/24 dev eth1 scope link table way1
ip route add 22.22.22.0/24 dev eth2 scope link table way1
ip route add default via 11.11.11.1 dev eth1 table way1
ip rule add from 11.11.11.11 pref 101 table way1
# 设置线路一
ip route flush table way2
ip route add 172.16.1.0/24 dev eth0 scope link table way2
ip route add 11.11.11.0/24 dev eth1 scope link table way2
ip route add 22.22.22.0/24 dev eth2 scope link table way2
ip route add default via 22.22.22.1 dev eth2 table way2
ip rule add from 22.22.22.22 pref 102 table way2
# 刷新路由缓存
ip route flush cache

至此无论是way1还是way2,访问2个ip的任意一个地址都能够连通了。
即便是服务器上本身的默认路由都没有设置,也能够让外面的用户正常访问。

以下为相关参考指令:

# 指定IP出口
ip rule add from 172.16.1.5 pref 201 table way1
ip rule add from 172.16.1.6 pref 202 table way2
# 删除IP规则
ip rule del table pref 201 way1
ip rule del table pref 202 way2
文章作者: 若海; 原文链接: https://www.rehiy.com/post/111/; 转载需声明来自技术写真 - 若海

添加新评论