Published services → Hairpin NAT

“A client inside that opens a published service by its public address — the one DNS gives out — normally gets nothing: the publication answers on the wan…

“A client inside that opens a published service by its public address — the one DNS gives out — normally gets nothing: the publication answers on the wan only, and the server would reply to it directly. Hairpin NAT translates that traffic too and sends the reply back through the appliance.”

Example: the NAS 192.168.10.20 is published on the wan with nas.johnsmith.test → 203.0.113.10, port 5001. From home it works; from the office a PC opens https://nas.johnsmith.test:5001, arrives on the appliance’s LAN interface, and the publication, bound to the wan, does not translate it.

Local DNS or hairpin?

There are two solutions:

  • Local DNS (recommended): in DNS and DHCP → Local DNS add a record nas.johnsmith.test → 192.168.10.20. The internal clients that use the appliance as their DNS go straight to the NAS: no translation, no needless trip through the appliance, and the NAS sees the client’s real address. It works if the clients use the appliance’s resolver (the normal case with Argos’s DHCP, and always with forced DNS) and if the internal port is the same as the published one.
  • Hairpin NAT: needed when local DNS is not enough, for example when the clients use an external DNS you do not control, when an application has the public address written in its configuration, or when the external port differs from the internal one.

With hairpin, the server sees these connections arrive from the appliance’s address, not from the client’s: keep it in mind if the service filters or logs addresses.

The block

The block opens from Published services → Hairpin NAT. At the top, the “Effect of saving” panel reminds you that the changes take effect with “Apply”.

  • “Hairpin NAT” — the switch. “Off by default. Every zoned publication also answers the other internal zones on the addresses below; its allowed sources still apply.”
  • “Public addresses” — “The IPv4 addresses the publications are reached at from the internet: the WAN’s own, and the upstream router’s when the appliance sits behind one.” Type the address and add it with “Add address”; at most 16. If you have never saved the block, the list is prefilled with the addresses the appliance currently sees on the WAN side, also shown below the field: “Seen on the WAN side now: 203.0.113.10”. Check that they are the right ones: the public one often belongs to the provider’s router.
  • “Save” — writes the configuration and confirms with “Hairpin NAT saved”. “Takes effect on the next firewall apply. A publication on SSH’s port or on the console’s 8000 is never hairpinned; one on 443 or 80 is, like any other port (the console still answers on the appliance’s inside addresses).”

For John Smith Ltd: switch on “Hairpin NAT”, leave 203.0.113.10 in “Public addresses”, click “Save”, then “Apply” in the header and confirm within 60 seconds.

The Hairpin NAT blockThe Hairpin NAT block
The Hairpin NAT block

Possible errors below the field: “Add at least one public address” (switch on without addresses), “Only IPv4 addresses”, “At most 16 addresses”.

What it reflects and what it does not

  • Only the publications with an ingress zone. A publication with “Any zone” already answers on every interface and needs no hairpin.
  • The reflected traffic is the traffic arriving from the other internal zones: every zone except the publication’s own and the wan, leaving out the gateways’ interfaces. With the publication on the wan, then, lan, guests (the guests) and production (the production machines).
  • The publication’s “Allowed remote sources” apply to hairpin too: if you have limited the publication to a supplier’s addresses, the internal clients do not reach it. The “Source limit /min” and the “Allowed countries”, on the other hand, do not apply to hairpin: they protect the internet side.
  • Publications on SSH’s port and on 8000 are never reflected: from the inside, that port of the appliance is the safe way in.

For the technician With the switch off, or without valid addresses, the ip argos_nat table is identical to before the feature. On, for each publication with a zone the dstnat chain gets a line iifname { <inside interfaces> } ip daddr { <public addresses> } [ip saddr { <sources> }] <proto> dport { <ports> } counter ct mark set ct mark or 0x18000000 dnat to <host>[:<port>] (the publication’s bit plus the hairpin’s), and srcnat first does ct mark and 0x10000000 == 0x10000000 counter masquerade, so the server’s reply comes back to the appliance and is translated back.

LET’S TALK INFRASTRUCTURE

Control starts with a conversation.

Tell us about your infrastructure. Let’s start with what you actually need.

Talk to an engineer