I have a WireGuard server as the edge router. Forwarding all http traffic to my web server. Everything works fine but there is a problem. The web server cannot access itself through the WireGuard public IP address. On the web server computer, I cannot use the web browser to access my website.
I found that daddr based nat can resolve this issue but I would like to know if there any better method because IP address may vary but iif is fixed. My Netgear WiFi router can port forwarding without this kind of problem. But I cannot check its internal rule, also I don't think it uses daddr based nat.
Here are the config of the WireGuard server.
wg0
interface: wg0 Address = 10.0.0.1/24 public key: (hidden) private key: (hidden) listening port: 51820 peer: (hidden) endpoint: (hidden):51820 allowed ips: 10.0.0.2/32 latest handshake: 56 seconds ago transfer: 20.69 MiB received, 115.85 MiB sent nftables
table ip firewall { chain input { type filter hook input priority filter; policy drop; ct state established,related accept udp dport {51820} accept tcp dport {22} accept ip saddr 10.0.0.0/24 accept } chain prerouting { type nat hook prerouting priority dstnat; iif eth0 tcp dport {80,443} dnat to 10.0.0.2 } chain postrouting { type nat hook postrouting priority srcnat; ip saddr 10.0.0.0/24 masquerade } chain forward { type filter hook forward priority filter; policy drop; ct state established,related accept ct status dnat accept ip saddr 10.0.0.0/24 accept } } Here are the config of the Web server.
wg0
interface: wg0 Address = 10.0.0.2/24 public key: (hidden) private key: (hidden) listening port: 51820 fwmark: 0xca6c peer: (hidden) endpoint: (hidden):51820 allowed ips: 0.0.0.0/0 latest handshake: 25 seconds ago transfer: 114.69 MiB received, 3.56 MiB sent persistent keepalive: every 25 seconds