My old DD-WRT router was dying, so I grabbed a UniFi EdgeRouter, which is, stylistically, much more like a "real router". I have various public IPs that I have 1-to-1 NAT setup for, i.e. the internal system has an IP of 192.168.123.134 , and any external requests to 173.13.139.236 get translated to the internal IP and back.
With the new router, I had to additionally setup hairpin NAT rules, so that internal systems could reach 173.13.139.236 , by having their requests translated to the internal IP but with a source IP on the router (i.e. masqueraded NAT).
(The specific issue, as I understand it, is that if you just NAT a packet that is from an internal address so that its destination is also to an internal address, then the reply just goes back directly to the requester, but the requester sent its packet to the router, so when it sees the reply come back from not-the-router, it drops the packet as invalid.)
With my DD-WRT router, I didn't have to do the hairpin NAT rule, and I don't understand why.
Specifically, the entire config for that IP on my DD-WRT system, as far as I know!, was:
iptables -t nat -I PREROUTING -d 173.13.139.236 -j DNAT --to 192.168.123.134
iptables -t nat -I POSTROUTING -s 192.168.123.134 -j SNAT --to 173.13.139.236
iptables -I FORWARD -d 192.168.123.134 -j ACCEPT
This did, in fact, work. Indeed, it worked for years. Why?
It's totally possible that there's some other config in the DD-WRT setup that handles this, but if there is, I have no idea where it would be; I reviewed the entire config when I changed routers, and I saw nothing else related to those IPs.
I think the DD-WRT interface used the term "Internet NAT Redirection" for the correction of hairpin NAT issues which was active by default and because it probably "just work as expected" you simply were not aware of its existence.
Rather than on specific IP-addresses (and port numbers) that was probably effected in/with iptables with a generic and not very obvious looking rule for traffic to the WAN interface (not necessarily listed by it's IP-address) originating from your LAN networks/interfaces or with a similar effect, for traffic NOT originating from the WAN.
Think along the lines of
Source: https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=545301
Following from some of the threads laid by HBruijn's answer, and some iptables dumping from the router itself, I think I found it. I couldn't have gotten there without HBruijn's answer, but it wasn't at the level of detail I wanted, so I thought I'd share.
https://svn.dd-wrt.com/ticket/1868 is a bug report on an issue where loopback was broken, and it gives the example simple command of:
A number of places mentioned a particular option, such as https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=82919&postdays=0&postorder=dsc&start=0 :
Which led me to https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=643132 , which shows the specific changes that that option causes, which I was able to confirm on my own router directly.
With "Filter WAN NAT Redirection" unchecked:
With "Filter WAN NAT Redirection" checked:
The difference is with it unchecked it has:
, and with it checked, that becomes a DROP rule.
So if I understand what's going on here correctly, with "Filter WAN NAT Redirection" unchecked (which it seems would do nothing), what actually happens, as y'all said, is the default behaviour of the router masquerading every connection on the local network that comes in from any non-WAN port.
So a connection from a random DHCP address, in my case say 192.168.123.10, to one of my static IPs, say 173.13.139.236, would go:
And then the return packet: