19
2023
04
15:28:54

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



推荐点击下面图片,通过本站淘宝优惠价购买:

image.png

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
Bash

至此无论是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.hqyman.cn/post/3934.html 非本站原创文章欢迎转载,原创文章需保留本站地址!

分享到:





休息一下,本站随机推荐观看栏目:


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

您的IP地址是: