Route Wireguard traffic to specific WAN based on port number

Hey Friends,

I have a setup like,

As per my setup,
I have an OpenWRT Physical router with two WAN connections (WAN1:eth1, WAN2:eth2) establishing a Wireguard tunnel with a Virtual OpenWrt device in AWS.
My requirement is that I need to send wg1 traffic via WAN1 and wg2 traffic via WAN2.
Could anyone help me out with the any iptables routing rules to route traffic with port numbers to specific WAN's?

Thanks in Advance.

iptables -t mangle -I OUTPUT -m udp -p udp --dport 51821 -j MARK --set-mark 1
ip rule add fwmark 0x1 table 100 prio 1
ip route add default via $YOUR_WAN1_GW_IP_Addr table 100

iptables -t mangle -I OUTPUT -m udp -p udp --dport 51822 -j MARK --set-mark 2
ip rule add fwmark 0x2 table 200 prio 2
ip route add default via $YOUR_WAN2_GW_IP_Addr table 200

The ip rules / routes could be created in /etc/config/network.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.