I have a hairpin NAT loopback to be able to access my self-hosted server domain (resolving to my WAN IP) from within my home network.
It is implemented in custom firewall rules:
iptables -t nat -A prerouting_rule -d {{public_WAN_ip}} -p tcp --dport 443 -j DNAT --to {{local_ip:port to handle the request}}
iptables -A forwarding_rule -p tcp --dport {{local port}} -d {{local ip}} -j ACCEPT
iptables -t nat -A postrouting_rule -s {{local network}} -p tcp --dport {{local port}} -d {{local ip}} -j MASQUERADE
It works when I restart my firewall but then when I enable vpn policy routing it stops working.
Looking for help on debugging.
relevant parts
/etc/config/vpn-policy-routing
server is configured to go through wan
config vpn-policy-routing 'config'
list supported_interface ''
option boot_timeout '30'
option webui_enable_column '0'
option webui_protocol_column '0'
list webui_supported_protocol 'tcp'
list webui_supported_protocol 'udp'
list webui_supported_protocol 'tcp udp'
list webui_supported_protocol 'icmp'
list webui_supported_protocol 'all'
option enabled '1'
option ipv6_enabled '1'
option src_ipset '1'
option webui_sorting '0'
option iptables_rule_option 'append'
option iprule_enabled '0'
option webui_chain_column '0'
option strict_enforcement '1'
option dest_ipset 'dnsmasq.ipset'
option verbosity '0'
config policy
option interface 'wan'
option name 'server'
option src_addr '{{local ip}}'
# This doesn't do anything to fix the problem but I thought I'd try this.
config policy
option interface 'wan'
option name 'loopback'
option dest_addr '{{external domain that resolves to wan IP}}'
/etc/init.d/vpn-policy-routing support
vpn-policy-routing 0.2.1-8 running on OpenWrt 18.06.5. WAN (IPv4): wan/dev/{{WAN))
============================================================
Dnsmasq version 2.80 Copyright (c) 2000-2018 Simon Kelley
Compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC no-ID loop-detect inotify dumpfile
============================================================
Routes/IP Rules
default * 0.0.0.0 U 0 0 0 wgclient
IPv4 Table 201: default via {{WAN}} dev eth0.0
IPv4 Table 201 Rules:
32705: from all fwmark 0x10000/0xff0000 lookup 201
IPv4 Table 202: default via {{VPN}} dev wgclient
IPv4 Table 202 Rules:
32704: from all fwmark 0x20000/0xff0000 lookup 202
IPv6 Table 201: fe80::/64 dev eth0.0 proto kernel metric 256 pref medium
IPv6 Table 202: {{VPN}} dev wgclient proto kernel metric 256 pref medium
IPv6 Table 202: default dev wgclient proto static metric 1024 pref medium
============================================================
IP Tables PREROUTING
-N VPR_PREROUTING
-A VPR_PREROUTING -p udp -m multiport --dports 5060 -m comment --comment SIP_Ports -c 0 0 -j MARK --set-xmark 0x10000/0xff0000
-A VPR_PREROUTING -p tcp -m multiport --dports 5060 -m comment --comment SIP_Ports -c 1 52 -j MARK --set-xmark 0x10000/0xff0000
-A VPR_PREROUTING -m set --match-set wgclient_mac src -c 5727 419512 -j MARK --set-xmark 0x20000/0xff0000
-A VPR_PREROUTING -m set --match-set wgclient_ip src -c 0 0 -j MARK --set-xmark 0x20000/0xff0000
-A VPR_PREROUTING -m set --match-set wgclient dst -c 23 3076 -j MARK --set-xmark 0x20000/0xff0000
-A VPR_PREROUTING -m set --match-set wan_mac src -c 90433 32787727 -j MARK --set-xmark 0x10000/0xff0000
-A VPR_PREROUTING -m set --match-set wan_ip src -c 24569 21052089 -j MARK --set-xmark 0x10000/0xff0000
-A VPR_PREROUTING -m set --match-set wan dst -c 0 0 -j MARK --set-xmark 0x10000/0xff0000
============================================================
IP6 Tables PREROUTING
-N VPR_PREROUTING
-A VPR_PREROUTING -p udp -m multiport --dports 5060 -m comment --comment SIP_Ports -c 0 0 -j MARK --set-xmark 0x10000/0xff0000
-A VPR_PREROUTING -p tcp -m multiport --dports 5060 -m comment --comment SIP_Ports -c 0 0 -j MARK --set-xmark 0x10000/0xff0000
-A VPR_PREROUTING -m set --match-set wgclient_mac src -c 9 696 -j MARK --set-xmark 0x20000/0xff0000
-A VPR_PREROUTING -m set --match-set wan_mac src -c 451 102090 -j MARK --set-xmark 0x10000/0xff0000
============================================================
IP Tables FORWARD
-N VPR_FORWARD
-A VPR_FORWARD -m set --match-set wgclient dst -c 0 0 -j MARK --set-xmark 0x20000/0xff0000
-A VPR_FORWARD -m set --match-set wan dst -c 0 0 -j MARK --set-xmark 0x10000/0xff0000
============================================================
IPv6 Tables FORWARD
-N VPR_FORWARD
============================================================
IP Tables INPUT
-N VPR_INPUT
-A VPR_INPUT -m set --match-set wgclient dst -c 0 0 -j MARK --set-xmark 0x20000/0xff0000
-A VPR_INPUT -m set --match-set wan dst -c 0 0 -j MARK --set-xmark 0x10000/0xff0000
============================================================
IPv6 Tables INPUT
-N VPR_INPUT
============================================================
IP Tables OUTPUT
-N VPR_OUTPUT
-A VPR_OUTPUT -m set --match-set wgclient dst -c 0 0 -j MARK --set-xmark 0x20000/0xff0000
-A VPR_OUTPUT -m set --match-set wan dst -c 0 0 -j MARK --set-xmark 0x10000/0xff0000
============================================================
IPv6 Tables OUTPUT
-N VPR_OUTPUT
============================================================
Current ipsets
create wan hash:net family inet hashsize 1024 maxelem 65536 comment
create wan_ip hash:net family inet hashsize 1024 maxelem 65536 comment
add wan_ip {{local server IP}} comment "server: {{local server IP}}"
create wgclient hash:net family inet hashsize 1024 maxelem 65536 comment
add wgclient .............. {redacted}
add wgclient .............. {redacted}
add wgclient .............. {redacted}
add wgclient .............. {redacted}
create wgclient_ip hash:net family inet hashsize 1024 maxelem 65536 comment
create wan_mac hash:mac hashsize 1024 maxelem 65536 comment
.............. {redacted}
============================================================
DNSMASQ ipsets
ipset=/{{hostname that resolves to my external IP}}/wan # loopback
============================================================
/etc/init.d/vpn-policy-routing reload
Creating table 'wan/eth0.0/{{redacted network}}' [✓]
Creating table 'wgclient/{{redacted network}}' [✓]
Routing .....redacted...
Routing 'server' via wan [✓]
Routing 'loopback' via wan [✓]
vpn-policy-routing 0.2.1-8 started with gateways:
wan/eth0.0/{{redacted network}}
wgclient/{{redacted network}} [✓]