Hi Everyone, hope you are dooing well and wish you a happy new year filled with health, joy and wealth ![]()
This is yet another post about Hairpin. i've been looking through the documentation and reading a lot of post forums about it (most of them dating 3 to 4 years now) and still havin some problems with Hairpin.
The problem :
I havei been hosting a lot of game servers for years now for me, my family and friends using Pterodactyl panel on my homelab (2 Node proxmox).
Everything works fine, dstnat is working perfectly and never had any problem.
I have been creating some new game servers these days that do not want to connect via the lan ip but needs the public IP which is for me and my family a typical Hairpin problem because packets get's out of the network to come back from outside it.
To simplify things here is a simple diagram of the network stack
[Internet] <---> [Public IP] ISP BOX [(DMZ) Interface : 192.168.1.254/24] <---> [192.168.1.9/24] CCR2004 [192.168.2.1/24] <---> Switches/devices
Bellow is my filter rules and the relevant firewall rules (removed those not connected to the problem)
As i said everything works fine, i can connect to the game servers either by their local address or the public address for those refusing to aknowledge the local one.
I wanted to create a hairpin to prevent the outside/inside so added the masquerades but :
- If i put Out-address as XXX (nat, bradge etc etc) as i've seen in a lot of examples nothing works. Only way to make it work is either as an IN interface or nothing
- When testing a tcp/udp scan with nmap with hairpin activate i can see the counter going up which is encouraging
- When i connect to the game server i seen the packet counter going up once and then ... nothing ... no traffic registered, no packets going up.
This is the part where i'm confused : i expected to see packets constantly incrementing with the communication between my pc and the game server but nothing. So does it work ? How can i know it ? In logs i get nothing apart from the initial connection.
--- Filter
/ip firewall filter
add action=accept chain=input comment="defconf: accept established,related,untracked" connection-state=established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment="defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add action=accept chain=input comment="Allowing wireguard port acces to te router" dst-port=13231 protocol=udp
add action=accept chain=input comment="[Wireguard] Protonvpn" dst-port=13232 protocol=udp
add action=accept chain=input comment="[Wireguard] Protonvpn" dst-port=13233 protocol=udp
add action=accept chain=input comment="Acceptation connexion vers routeur depuis la liners Family" src-address-list=liners_family
add action=drop chain=input comment="defconf: drop all not coming from LAN" in-interface-list=!LAN log=yes log-prefix="[DROP-NO-LAN]”
add action=accept chain=forward comment="defconf: accept in ipsec policy" ipsec-policy=in,ipsec
add action=accept chain=forward comment="defconf: accept out ipsec policy" ipsec-policy=out,ipsec
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" connection-state=established,related hw-offload=yes
add action=accept chain=forward comment="defconf: accept established,related, untracked" connection-state=established,related,untracked
add action=accept chain=forward comment="Acceptation trafic vers r\C3\A9seau local depuis wireguard" dst-address=192.168.2.0/24 in-interface=homeliners-wireguard-interface log=yes log-prefix="[input-liners_family]”
add action=drop chain=forward comment="defconf: drop invalid" connection-state=invalid
add action=drop chain=forward comment="defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat connection-state=new in-interface-list=WAN
--- Firewall
/ip firewall nat
add action=masquerade chain=srcnat comment="Hairpin for the game server" disabled=yes dst-address-list=free_ipv4_public dst-port=28000-28199 log=yes log-prefix="[FW][PTEROS-0-HAIRPIN-TCP]" protocol=tcp src-address-list=liners_family to-ports=28000-28199
add action=masquerade chain=srcnat comment="Hairpin for the game server" disabled=yes dst-address-list=free_ipv4_public dst-port=28200-28250 log=yes log-prefix="[FW][PTEROS-1-HAIRPIN-TCP]" protocol=tcp src-address-list=liners_family to-ports=28200-28250
add action=masquerade chain=srcnat comment="Hairpin for the game server" disabled=yes dst-address-list=free_ipv4_public dst-port=28000-28199 log=yes log-prefix="[FW][PTEROS-0-HAIRPIN-UDP]" protocol=udp src-address-list=liners_family to-ports=28000-28199
add action=masquerade chain=srcnat comment="Hairpin for the game server" disabled=yes dst-address-list=free_ipv4_public dst-port=28200-28250 log=yes log-prefix="[FW][PTEROS-1-HAIRPIN-UDP]" protocol=udp src-address-list=liners_family to-ports=28200-28250
add action=masquerade chain=srcnat comment="defconf: masquerade" ipsec-policy=out,none log=yes log-prefix="[DEFAULT-MASQUERADE]" out-interface-list=WAN
add action=dst-nat chain=dstnat comment="[tiguemmi][lxc] pteros-0" dst-port=28000-28199 in-interface-list=WAN log=yes log-prefix="[FW][PTEROS-0]" protocol=tcp to-addresses=192.168.2.250 to-ports=28000-28199
add action=dst-nat chain=dstnat comment="[tiguemmi][lxc] pteros-0" dst-port=28000-28199 in-interface-list=WAN log=yes log-prefix="[FW][PTEROS-0]" protocol=udp to-addresses=192.168.2.250 to-ports=28000-28199
add action=dst-nat chain=dstnat comment="[tiguemmi][lxc] pteros-1" dst-port=28200-28250 in-interface-list=WAN log=yes log-prefix="[FW][PTEROS-1]" protocol=tcp to-addresses=192.168.2.248 to-ports=28200-28250
add action=dst-nat chain=dstnat comment="[tiguemmi][lxc] pteros-1" dst-port=28200-28250 in-interface-list=WAN log=yes log-prefix="[FW][PTEROS-1]" protocol=udp to-addresses=192.168.2.248 to-ports=28200-28250

