Hi. I’m struggling with the hairpin NAT configuration. Config is pretty standart, I have 5.xx.xx.xx external public ip on ether1 and 192.168.0.0/16 lan on ether2. I want to access local server 192.168.0.100 from inside, using 5.xx.xx.xx public ip. I’ve read tons of posts related to hairpin, and of course wiki article, but still cannot get it working.
Anyway, if I put public ip there, it contradicts the example in wiki. Also, IMHO the order is dst-nat → src-nat, so after my request to 5.xx.xx.xx dst address is translated to 192.168.0.100 (according to port forward rule), and then src-nat rule kicks in.
>
Can you reach the server from outside? I suspect that, since the rule above does not specify on which port to send the traffic.
It should be like this:
```text
/ip firewall nat
add action=dst-nat chain=dstnat comment=http disabled=no dst-port=80 in-interface=ether1-gateway protocol=tcp to-addresses=192.168.0.100 to-ports=80
Also, I see you have a bridge port. Is the ether2 port included in bridge? If yes, you either remove ether2 from bridge or in the hairpin nat rule, as outgoing-port you set the bridge.
Also, I see you have a bridge port. Is the ether2 port included in bridge? If yes, you either remove ether2 from bridge or in the hairpin nat rule, as outgoing-port you set the bridge.
I do have a bridge, and ether2 is in it, but I didn’t set it explicitly, it is a result of default config with quickset. I want to use it as a typical home router (1 wan, 4 lan+wifi), so I think bridging ether2+wlan1 is correct?
I’ve already tried that, when following wiki article… IMHO here dst-port also acts only as a narrowing filter, so that only http traffic is masqueraded, not all traffic coming to that host.
Well, at this point, all I can say is that I have tried hairpin nat successfully as per wiki.
I guess sth could be with your routing table, if it is not default.
May be it could be useful to see your routes as well /ip route print
/ip route print
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
# DST-ADDRESS PREF-SRC GATEWAY DISTANCE
0 ADS 0.0.0.0/0 5.xx.xx.xx 1
1 X S 0.0.0.0/0 192.168.34.254 1
2 ADC 5.xx.xx.xx/23 5.xx.xx.xx ether1-gateway 0
3 ADC 192.168.0.0/16 192.168.0.99 bridge-local 0
Not much here either… As I said, the config is pretty simple, typical NAT for internal users plus a few port forwards.
Ok, I see that the connected route for network 192.168.0.0/16 goes through interface bridge-local.
On the other hand, in /ip address, the address 192.168.0.99 is assigned to the wireless interface, and
in the hairpin nat rule as outgoing interface is assigned the ether2 one.
My opinion is that you should assign the IP address on the bridge-local, and also change the out-interface
on the hairpin nat rule to the bridge-local.
Just made a full reset, used AP quickset. Also upgraded to 5.21. Added just one port forward to internal server at port 80, and a hairpin rule. Still doesn’t work
Allright, a few beers later I’ve mastered the damn thing. However…
This combination works fine:
chain=dstnat action=dst-nat to-addresses=192.168.0.100 protocol=tcp dst-address=5.20.146.53 dst-port=80
chain=srcnat action=masquerade to-addresses=192.168.0.99 src-address=192.168.7.60 dst-address=192.168.0.100 out-interface=bridge-local
But this one does not work:
chain=dstnat action=dst-nat to-addresses=192.168.0.100 protocol=tcp in-interface=ether1-gateway dst-port=80
chain=srcnat action=masquerade to-addresses=192.168.0.99 src-address=192.168.7.60 dst-address=192.168.0.100 out-interface=bridge-local
I’ve created all my port forwards using “in-interface=ether1-gateway”, to isolate my rules from external IP change. But as far as I understand, hairpin request does not go in through “ether1-gateway”, therefore my usual rule does not work. Is it possible to use interfaces instead of specific IP addresses?