Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
Networking

MikroTik port forwarding on RouterOS 7: dst-nat done right

Forward ports on a MikroTik router with RouterOS 7: dst-nat in WinBox and the CLI, the default firewall, hairpin NAT, dynamic WAN addresses, CGNAT and IPv6.

CloudSat teamNovember 18, 20266 min read
Abstract illustration of a router block redirecting one bright incoming stream through a narrow labeled gate to a single device behind it
On this pageBefore you forward anything

Port forwarding on a MikroTik router is one destination NAT rule: traffic that arrives on a public port is rewritten to an address and port inside your network. The rule takes a minute to write. The details around it decide whether it works from everywhere, including from inside your own network, and whether it opens more than you meant to. This guide uses RouterOS 7 with the default configuration, and shows each step in WinBox and on the command line.

If you configure the router remotely, press Ctrl+X in the terminal, or use Safe Mode in WinBox, before you start. If a change cuts your connection, RouterOS rolls it back.

Before you forward anything

Check three things first:

  1. The device inside has a fixed address. Give it a static IP or a DHCP reservation (IP > DHCP Server > Leases, then Make Static), or the rule will point at the wrong machine after a renewal.
  2. The service works on the LAN. Test https://192.168.88.10 from another computer before involving NAT.
  3. Your router really has a public address. Compare the address on the WAN interface with what the internet sees. RouterOS can tell you:
/ip address print where interface=ether1
/ip cloud set ddns-enabled=yes
/ip cloud print

If the WAN address starts with 100.64 to 100.127, or any private range, and differs from the public-address that IP Cloud reports, your ISP uses carrier-grade NAT. No rule on your router can make you reachable then; skip to the CGNAT section.

Create the dst-nat rule

The example forwards public TCP port 8443 to a web server at 192.168.88.10 on port 443.

In WinBox: open IP > Firewall, the NAT tab, and click +.

  • General tab: Chain dstnat, Protocol 6 (tcp), Dst. Port 8443, In. Interface List WAN.
  • Action tab: Action dst-nat, To Addresses 192.168.88.10, To Ports 443.
  • Add a Comment so the rule explains itself later.

The same rule on the command line:

/ip firewall nat add chain=dstnat action=dst-nat in-interface-list=WAN \
    protocol=tcp dst-port=8443 to-addresses=192.168.88.10 to-ports=443 \
    comment="web server 8443 to 443"

Matching on the WAN interface list instead of the public IP means the rule keeps working when your ISP changes the address. Leave To Ports empty to keep the same port number. For a game server that uses UDP, set protocol=udp, and for a range write dst-port=27015-27030.

Why the default firewall lets it through

The default configuration drops new connections that come in from the WAN, with one exception, visible in the forward chain:

/ip firewall filter print where chain=forward

The rule commented defconf: drop all from WAN not DSTNATed drops new connections from the WAN unless a dst-nat rule translated them. So a dst-nat rule is enough on a router with the default firewall. If you replaced the defaults with your own rules, add a forward rule that accepts the translated traffic, for example with connection-nat-state=dstnat, above your final drop.

Limit who can reach it

A forward opens the inside service to the whole internet. If only known people need it, restrict the source with an address list:

/ip firewall address-list add list=allowed-remote address=198.51.100.24 comment="office"
/ip firewall nat set [find comment="web server 8443 to 443"] src-address-list=allowed-remote

Never forward management services such as RDP, SSH or a NAS admin page to the whole internet. Put them behind a VPN instead: RouterOS 7 includes WireGuard, so remote devices can reach the LAN through one UDP port with keys rather than exposed logins.

Also keep public ports clear of the ones the router itself uses, such as 8291 for WinBox and 80 or 443 for its web interface, and check that those services are restricted under IP > Services.

Test from the outside

Testing from inside your own network tells you nothing about the forward, because LAN traffic to the public address takes a different path (see hairpin NAT below). Use a phone on mobile data, a server elsewhere, or an online port checker:

nc -vz 203.0.113.5 8443
curl -kI https://203.0.113.5:8443/

Watch the rule's counters while you test. If the packet counter of the NAT rule does not move, the traffic never reached the router on that port: check the ISP, CGNAT, or a firewall in front of you. If it moves but the connection fails, look at the device inside, its own firewall, and whether it uses the router as its gateway.

/ip firewall nat print stats where chain=dstnat

Hairpin NAT: reaching the public address from inside

People on your LAN who use the public address, or a domain name that points at it, usually find the forward does not work for them. Two things go wrong: the dst-nat rule matches only traffic coming in on the WAN, and the server's replies go straight back to the LAN client, which drops them because they come from an address it did not contact.

The cleanest fix is DNS: give LAN clients a local record that points the name straight at 192.168.88.10, which RouterOS can serve itself, as shown in MikroTik DNS on RouterOS 7. If that is not possible, use hairpin NAT. First replace the forward with a version that matches the router's own addresses instead of the WAN interface, so LAN traffic to the public address is translated too (add src-address-list again if you used one):

/ip firewall nat remove [find comment="web server 8443 to 443"]
/ip firewall nat add chain=dstnat action=dst-nat dst-address-type=local \
    protocol=tcp dst-port=8443 to-addresses=192.168.88.10 to-ports=443 \
    comment="web server 8443 to 443"

Then add a source NAT rule so the server replies through the router:

/ip firewall nat add chain=srcnat action=masquerade protocol=tcp \
    src-address=192.168.88.0/24 dst-address=192.168.88.10 dst-port=443 \
    out-interface=bridge comment="hairpin for web server"

The trade-off is that the server now sees the router's LAN address as the source of every inside request, so its logs lose the real client address for LAN visitors.

IPv6 has no port forwarding

With IPv6, the device inside has its own global address, so there is nothing to translate. Instead, allow the traffic in the IPv6 forward chain, above the default rule that drops everything not coming from the LAN:

/ipv6 firewall filter print where chain=forward
/ipv6 firewall filter add chain=forward action=accept in-interface-list=WAN \
    protocol=tcp dst-address=2001:db8:1:2::10 dst-port=443 \
    comment="web server v6" place-before=<number of the final drop rule>

Behind CGNAT: borrow a public address

When the ISP's carrier-grade NAT sits in front of your router, the forward has to happen somewhere that does have a public address. Ask the ISP for a public IPv4 address, often available on request or for a fee, or rent one: a small virtual router with a public IP can receive the traffic and pass it to your home router over a WireGuard tunnel. MikroTik's CHR edition runs on a VPS for exactly this, and CloudSat offers it as a RouterOS image.

FAQ

Do I need a filter rule as well as the NAT rule?

Not with the default configuration, whose forward chain accepts anything a dst-nat rule translated. With a custom firewall, add an accept rule for connection-nat-state=dstnat traffic above your final drop.

Why does the forward work from my phone but not from my laptop at home?

Your laptop is inside the LAN, so its traffic to the public address needs hairpin NAT or a local DNS record. The forward itself is fine.

Can I forward the same public port to two devices?

No. One public port and protocol leads to one inside address. Use different public ports, or a reverse proxy on one device that sends traffic to the others by hostname.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.