Here’s how I solved it:
1. Setup VPN Interface with Policy-Based Routing:
• First, I set up WireGuard as the VPN client on my Unifi gateway. Many VPN providers allow you to download a WireGuard config that can be uploaded into Unifi.
• Once the VPN is configured, you can create a Policy-Based Route to specify which devices or networks should use the VPN for outbound traffic. This step ensures your internal devices route traffic through the VPN tunnel.
2. Solution: Custom Firewall and NAT Rules:
To make port forwarding work, I had to set up both a custom firewall rule and a Destination NAT rule.
Step-by-Step Setup:
• Firewall Rule:
1. Go to Firewall & Security → Create a new rule under “Internet In”.
2. Action: Set to “Accept”.
3. Protocol: Select TCP/UDP (or any specific protocol you need).
4. Source: Set to Any. Since the traffic is coming from the internet via your VPN, it’s important to allow any source.
5. Destination: This should be the internal IP of the device you want to forward traffic to (e.g., 192.168.1.xxx).
6. Destination Port: Set the specific port you’re forwarding.
7. Save the rule.
• NAT Rule (Destination NAT):
1. Go to Network Settings and create a Destination NAT rule.
2. Set the Interface to your WireGuard VPN interface.
3. Destination Address: Set this to the internal IP address from the VPN tunnel (the IP assigned to you by your VPN provider within the VPN network, e.g., 10.x.x.x).
4. Translated IP Address: Set this to the local IP of the device in your network (e.g., 192.168.1.xxx).
5. Ports: Match the Destination Port to the port you are forwarding.