NAT

MikroTik Hairpin NAT: Open Your Public IP or Domain from Inside the LAN

Why a forwarded server works from outside but not from inside your own network, and how to fix it on MikroTik with hairpin NAT or a static DNS entry.

Commands in this article follow RouterOS v7 documentation but have not yet been marked as lab-tested on this site. Always test changes in a lab or maintenance window and keep a backup.

Problem

Your web server or NVR works from the internet through port forwarding, but when you use the same public IP or domain from a PC inside the office, it does not open.

Symptoms

  • http://your-domain.com works on mobile data but times out on office Wi-Fi.
  • The server sees the connection with a strange source address, or none at all.

Likely causes

The dst-nat rule matches only traffic coming in on the WAN, so LAN traffic to the public IP is not forwarded. Even when it is forwarded, the server replies directly to the LAN client (same subnet), and the client drops the reply because it expected an answer from the public IP. Hairpin NAT fixes both parts.

Prerequisites

  • A working port forward (see MikroTik port forwarding).
  • Example: public IP 203.0.113.10, server 192.168.88.20 port 80, LAN 192.168.88.0/24 on bridge-lan.

Solution (WinBox / CLI)

1. Match the public IP, not the WAN interface:

RouterOS CLI
/ip firewall nat add chain=dstnat dst-address=203.0.113.10 protocol=tcp dst-port=80 action=dst-nat to-addresses=192.168.88.20 comment="Web server"

If your public IP changes, enable IP > Cloud DDNS and add the DDNS name to an address list, then use dst-address-list instead:

RouterOS CLI
/ip cloud set ddns-enabled=yes
/ip firewall address-list add list=my-public-ip address=YOUR_SERIAL.sn.mynetname.net

2. Masquerade LAN-to-server traffic so replies come back through the router:

RouterOS CLI
/ip firewall nat add chain=srcnat src-address=192.168.88.0/24 dst-address=192.168.88.20 protocol=tcp dst-port=80 out-interface=bridge-lan action=masquerade comment="Hairpin"

Place both rules above other NAT rules if needed.

Alternative: split DNS. If you use a domain name, point it to the inside address for LAN users only:

RouterOS CLI
/ip dns static add name=your-domain.com address=192.168.88.20

This works when LAN clients use the router as their DNS server.

Verification

From a LAN PC, open http://203.0.113.10 or your domain. Check the counters with /ip firewall nat print stats.

Common errors

  • Using dst-address-type=local without excluding the router's LAN IP: you also forward the router's own WebFig.
  • The server logs show every LAN visitor as the router's IP. That is expected with hairpin masquerade.

Rollback

RouterOS CLI
/ip firewall nat remove [find comment="Hairpin"]
Go deeper in class

This topic is covered hands-on in MTCNA — MikroTik Certified Network Associate.

View MTCNA
WhatsApp