Redirect wireguard client through wwan0 to get eth1 public IP address

Hello,

I have been using chatgpt to sort out my problem, but i am not getting anywhere after few days.

What is my aim?

I want all of my Wireguard clients - once connected to the server, get the WAN public IP address.

Problem Statement:

I have successfully set up a WireGuard server on an XE300 router using a SIM card with a static IP (interface: wwan0). Clients can connect and function as expected. However, when I plug in a WAN connection (to eth1), the WireGuard client can not connect.

My Goals:

  1. Keep WireGuard running on wwan0 even when eth1 is connected.
  2. Split the WAN (eth1) and Cellular (wwan0) traffic so that WireGuard only listens on wwan0.
  3. Route client traffic through eth1 once connected to WireGuard.

Questions:

1)How do I prevent eth1 from interfering with WireGuard's connection on wwan0?
2)How can I configure WireGuard to only accept incoming connections on wwan0?
3)How do I route WireGuard clients' traffic through eth1 (WAN) ?

Since the public IP is on the WWAN (cellular) interface and the traffic coming in and out of the VPN server must be the same interface, then the traffic in and out of the VPN server only be by the WWAN. The wwan (cellular) interface needs to be placed first priority and will not be interfered by WAN (On the GL GUI > Network > Multi-WAN).

WAN is meaningless in this and impossible to route WireGuard traffic.

Just FYI, I finally managed to do this

ip rule add from lookup 100
ip route add default via dev wwan0 table 100
ip rule add from 10.0.0.0/24 lookup 200
ip route add default via dev eth1 table 200
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
iptables -A FORWARD -i wgserver -o eth1 -j ACCEPT
iptables -A FORWARD -i eth1 -o wgserver -j ACCEPT
ping <external IP address of wwan0)

some other tweaks as well.