There are many routers whose guts are an embedded Linux, which allows us great flexibility. This time we will explain how to avoid the Hairpinning problem, which consists of not being able to use the router’s WAN IP from within the LAN.
To solve this problem, two solutions can be chosen:
- Configure a proxy
- iptables rules
Taking into account that the iptables flow scheme is as follows:
In the PREROUTING chain, we modify the destination address:
NOTE: With this, we would already have the outbound connection, but if we left it like this, the connection initiated by the client would have the WAN IP as its destination, on the other hand, it would respond with LAN_IP_SERVER, as it has no record of this connection, the client would reset the connection through an RST.
Now we tell it to do SNAT within the same LAN:
With this, we would already have it ;)