How to Set Up Port Forwarding (Step by Step)

Setting up port forwarding comes down to four moves: give the target device a fixed local IP address, create a rule in your router sending a chosen external port and protocol to that device's IP and port, allow the port through the device's own firewall, then test it from outside your network. None of it works, though, unless your router has a real public IPv4 address - so check for CGNAT first.

Port forwarding is what lets a connection starting out on the internet reach a specific device sitting behind your router - a game server, a camera, a self-hosted app, whatever it is. Your router normally drops unsolicited inbound traffic, simply because it has no idea which device it's meant for; a forwarding rule tells it. This guide walks through each step, then testing, troubleshooting and security.

Before you start: check you have a public IP

Port forwarding on your router gets you nowhere if the router itself isn't directly reachable from the internet. So do this two-minute check first:

  1. Note the public IPv4 address shown on the What's My IP Number page.
  2. Log in to your router and find the WAN or internet IPv4 address on its status page.
  3. Match? Good, carry on. If the router's WAN address starts anywhere from 100.64 to 100.127, you're behind carrier-grade NAT. If instead it's a private address like 192.168.x.x or 10.x.x.x, you've got either CGNAT or a second router sitting in front of yours (double NAT). Both get covered in the troubleshooting section below.

Step 1: Give the device a fixed local IP

A forwarding rule points at a local IP address, and that's the catch: if your device picks up a different address from DHCP next week, the rule breaks silently and you won't even know why. Fix the address in place with a DHCP reservation:

  1. Find the device's current IP and MAC address. On Windows run ipconfig /all; on macOS or Linux run ip addr or ifconfig; on consoles look in the network settings.
  2. In the router, open the DHCP or LAN settings and look for "Address reservation", "Static lease" or "DHCP binding".
  3. Bind the device's MAC address to an IP, for example 192.168.1.50, and save.
  4. Reconnect the device and confirm it received the reserved address.

Or skip the reservation and just set a manual static IP on the device itself, picking an address outside the router's DHCP pool. Our guide to how DHCP works explains pools, leases and reservations in detail.

Step 2: Create the forwarding rule

Log in to the router's admin page, usually sitting at the default gateway address like 192.168.1.1. Look for a menu called Port Forwarding, Virtual Servers, NAT, Applications or Gaming - it's often tucked under Advanced or Firewall. Every router labels its fields a little differently, but underneath, they all map to the same concepts:

FieldWhat to enterExample
Name / ServiceAny label you will recognise laterMinecraft
ProtocolTCP, UDP or Both, matching what the application usesTCP
External port (WAN / public port)The port people connect to from the internet; a single port or range25565
Internal port (LAN / private port)The port the application listens on; usually the same as the external port25565
Internal IP (server / device IP)The reserved address from step 1192.168.1.50
Source IP / remote hostOptional; restricts who may connect. Leave blank or 0.0.0.0 for anyone203.0.113.7
EnabledMake sure the rule is switched onOn

Check the application's own documentation for its ports and protocols - plenty of games need a UDP range on top of the TCP port. Using a different external and internal port (external 2222 mapped to internal 22, say) is perfectly allowed, and it's sometimes the only option when two devices both want the same service port. Our list of common network ports covers the usual defaults.

Step 3: Allow the port in the device's firewall

The router will deliver the traffic now, sure, but the device's own firewall can still block it cold.

Windows

Windows usually prompts the first time an application listens on the network, so just allow it on the appropriate network type. Want to add a rule explicitly instead? Run PowerShell as administrator:

New-NetFirewallRule -DisplayName "Minecraft TCP 25565" -Direction Inbound -Protocol TCP -LocalPort 25565 -Action Allow

Or go through Windows Defender Firewall with Advanced Security → Inbound Rules → New Rule → Port. One gotcha: rules apply per network profile, so if Windows has classified your home network as Public, a rule limited to the Private profile simply won't apply.

Linux with ufw

sudo ufw allow 25565/tcp
sudo ufw status verbose

Check the application is listening

The service has to be listening on the LAN address, or on all interfaces - not just 127.0.0.1:

sudo ss -tlnp | grep 25565

On Windows, run netstat -ano | findstr :25565 in Command Prompt instead.

See a line showing 0.0.0.0:25565, [::]:25565 or 192.168.1.50:25565? Good. 127.0.0.1:25565, though, means only the device itself can connect.

Step 4: Test from outside

With the application up and running, enter the port into our open port checker. It connects to your public IP from out on the internet, which is really the only reliable test there is. Keep in mind:

  • The checker only tests TCP. UDP has no handshake to speak of, so to test a UDP-only service, use the client application itself from an outside connection, like mobile data.
  • A port shows as closed whenever nothing's listening, even if the rule itself is correct. Start the service first, then test.
  • Testing your public IP from inside your own network only works if the router supports NAT loopback (hairpin NAT). Plenty don't, so a failed test from inside doesn't really prove much.

Troubleshooting a port that stays closed

CGNAT

If your router's WAN address sits in 100.64.0.0/10 or some other private range, and there's no second router at home, your ISP is sharing your IPv4 address with other customers. No setting on your router can open a port on the ISP's NAT - that's simply not yours to configure. Ask the ISP for a public IPv4 address, switch to IPv6, or use an outbound tunnel instead.

Double NAT

Got an ISP modem-router plus your own router? That's two NATs stacked on each other. Fix it one of these ways:

  • Put the ISP device in bridge or modem-only mode, so your own router grabs the public IP.
  • Forward the port on the ISP device to your router's WAN IP, then again on your router to the final device.
  • Set your router's WAN IP as the DMZ host on the ISP device, then forward ports only on your own router from there.

Other common causes

  • The device's IP changed - no reservation was ever made.
  • Wrong protocol, a TCP rule for a UDP service being the classic example.
  • ISP port blocking. Some residential ISPs block inbound ports like 25, 80 or 445 outright. Try a high port such as 8443 to test around it.
  • Port clash with the router itself - forwarding 443, say, when the router's own remote management uses it too.

UPnP: automatic port forwarding

Universal Plug and Play (UPnP IGD) and the similar NAT-PMP/PCP protocols let applications ask the router to open ports on their own behalf. Consoles and game launchers lean on these to get that "open" NAT type everyone wants.

  • Pros: no manual setup needed; ports only stay open while the application is actually running; works fine for software that picks random ports.
  • Cons: any program on your network - malware or a compromised smart device included - can open ports without so much as asking you. Some router UPnP implementations have had genuinely serious vulnerabilities, and you lose any clear record of what's actually exposed.

A reasonable middle ground: leave UPnP off and set up manual rules instead, or, if you need UPnP for gaming, at least check the router's UPnP mapping table every now and then.

Security best practices

  • Forward only what you actually need, to one device, and delete rules the moment you stop using them.
  • Never expose management services like Remote Desktop (3389), SMB (445), router admin pages or camera admin panels directly. These get scanned and attacked constantly - use a VPN into your network instead.
  • Avoid the DMZ host setting for ordinary devices; it forwards every unrequested port straight to them.
  • Keep the exposed software updated, and use strong, unique passwords or key-based authentication.
  • Restrict sources wherever your router allows it, if only a handful of known addresses actually need access.
  • Switching to a non-standard port cuts down the log noise from automated scans, but don't mistake it for real protection.
Tip: If your public IP ever changes, anyone connecting by IP loses access. A dynamic DNS hostname, kept updated by your router, gives you a stable name pointing at whatever address you currently have.

Frequently asked questions

Is port forwarding safe?

Only as safe as whatever service you're exposing. Forward a port to an up-to-date game server with no admin interface, and the risk is minimal; forward one to an old camera or a Remote Desktop session, and you're inviting attacks. Expose as little as you can get away with, and patch whatever you do expose.

Do I need port forwarding with IPv6?

No address translation is needed there, since every device already has a global IPv6 address. You still have to allow the inbound connection through the router's IPv6 firewall, though - most routers call that a firewall exception or a pinhole rather than port forwarding.

Why does the port checker say closed when my rule is correct?

Usually it's one of these: the application isn't running, or it's bound to 127.0.0.1; the host firewall is blocking it; the service uses UDP; or you're behind CGNAT or double NAT.

Essayez vous-même

Mettez ce guide en pratique avec nos outils gratuits.

Commentaires

Partagez une astuce, posez une question ou racontez comment l’outil a fonctionné pour vous.

À lire aussi

Copié dans le presse-papiers