I recently switched from OPNsense to OpenWRT, and I'm trying to configure the same functionality.
I'm trying to forward port 51820 to a Wireguard server on my LAN, so I can access my LAN when I'm not at home. This is a setup I've used for years. I can connect to the Wireguard server from my LAN.
Port forward settings:
Name: Wireguard
Restrict to address family: IPv4 only
Protocol: UDP
Source zone: WAN
External port: 51820
Destination zone: LAN
Internal IP address: 192.168.10.10 (I'm using 192.168.10.0/24 as my LAN subnet)
Internal port: 51820
I've set up dynamic DNS so that my domain is pointing to my WAN address, and this is working.
However, I can't ping the WAN address from my phone when it's connected to the cell network.
I should also mention that I have configured OpenWRT so that all internet traffic goes through Mullvad VPN. I've set up firewall zones so that if the Mullvad connection goes down, all internet traffic is blocked. I have a suspicion that this is the source of my problem, but I'm not sure.
That is port forward rule of DNAT type. Do not select destination zone filter as packets incoming are not destined to blindly forward to ip4 lan from your parameters, it follows (neighbour) route instead.
But if you have a default route out via the Mullvad VPN then you need to make sure that traffic which comes in via the WAN (e.g. your Wireguard server traffic) goes out via the WAN and not via the VPN.
You need Policy Based Routing for this
Either install the full PBR app which will do this automatically or do it manually
The way I had it set up on OPNsense, was that when I was connected to my Wireguard server, the traffic was still going out to the internet via Mullvad. I want the same functionality now.
The Wireguard firewall zone is for Mullvad, not my Wireguard server. I followed this guide to set it up.
For IPv6 it is a Traffic rule just opening the port, no dnat necessary as the server has a public IPv6 address note the negative netmask so that the prefix does not matter in case the prefix is dynamic
Then you also have to connect via the Mullvad external IP address, they used to allow port forwarding but I think they stopped supporting this so this no longer seems possible?
You cannot connect from the WAN and go out via the VPN, the firewall will not allow that.
That guide is OK, but does not cover IPv6 and Mullvad has excellent IPv6 support, my own guide is of course better WireGuard Client Setup Guide
I think that a decent firewall should not allow that but @brada is one of our firewall experts.
I never used OPNSense so I do not know what they do, I would be surprised if they allow traffic coming in from one interface go out via different interface but who knows :).
So the way to do it is to route traffic back via the incoming interface as outlined already