首先要在/etc/iproute2/rt_tables添加一个自定义的路由表名字,不然重启就会丢失,其中的30 vpn就是我定义的路由表。
root@OpenWrt:/etc/iproute2# cat rt_tables # # reserved values # 128 prelocal 255 local 254 main 253 default 0 unspec # # local # #1 inr.ruhep 30 vpn
然后在路由规则里面添加自己需要的自定义路由
这里的意思是从lan口过来的192.168.8.0/24的流量使用vpn路由表,然后vpn路由表默认都是走vpn网关10.99.99.1
这样子192.168.8.0/24的子网就可以默认全部走VPN通道了。
需要更高级功能的可以使用官方PBR策略路由插件,因我的是单臂路由openwrt只有一个lan口无法使用,也懒得研究了,传统的lan、wan结构的可以使用看看。
参考资料链接:
https://www.reddit.com/r/openwrt/comments/w0wf47/help_with_routing_tables/
https://openwrt.org/docs/guide-user/network/routing/pbr_app
https://docs.openwrt.melmac.net/pbr/
https://blog.fernvenue.com/zh/archives/using-pbr-to-route-traffic-on-openwrt/