Port Forwarding: How to Do It and When Not To
Set up a port forward step by step, test it correctly, understand the risk you take on and choose safer ways to reach home devices.
Key takeaways
- A forward maps a port on your public address to one device and port on your local network.
- The target device needs a stable local address, normally through a DHCP reservation.
- Forwarding fails behind carrier-grade NAT or an upstream router unless that layer is handled too.
- Never expose remote desktop, file sharing or router and camera admin pages directly to the internet.
- Remove forwards you no longer use, and keep whatever is exposed updated and password protected.
Port forwarding tells your router to pass unsolicited connections arriving from the internet on a chosen port to one particular device inside your network. To set it up, you give that device a fixed local address, create a rule with the port, protocol and address, allow the port in the device's own firewall, and test from outside your home.
Before you do, ask whether you need it. A forward exposes a service to anyone on the internet who finds it. For reaching your own files or computer remotely, a VPN or a tool built on outbound connections is usually safer.
Why inbound connections need help
Most home networks use network address translation (NAT): many devices share one public address. When your laptop contacts a website, the router remembers the connection and sends replies back to the laptop.
A connection that starts outside has no such memory. The router sees a request for its public address on some port and has no idea which device should get it, so it drops it. A forward supplies the answer. NAT explained covers the mechanism.
A port is a number from 0 to 65535 that identifies a service on a device. A rule also names a protocol, TCP or UDP; see TCP versus UDP.
When a forward is and isn't needed
You need a forward only when someone outside your network starts a connection to something inside it. Many things people assume require one don't:
- Browsing, streaming, email and video calls start from your side.
- Most online games connect you to servers run by the publisher.
- Cloud-managed cameras and smart devices keep their own outbound connection to the maker.
- Calling apps use techniques for NAT traversal, with relays as a fallback.
You are more likely to need one when you host a game server, run your own VPN endpoint, serve a website from home or connect directly to a device from elsewhere. Some games with player hosting also benefit.
If a guide tells you to forward a long list of ports to fix a vague connection problem, be cautious. Diagnose first. A forward added on hope tends to stay for years.
The parts of a rule
| Field | Meaning | Example |
|---|---|---|
| Name | Your label | minecraft |
| External port | Port on your public side | 25565 |
| Internal IP | The device that receives it | 192.168.1.40 |
| Internal port | Port the service listens on | 25565 |
| Protocol | TCP, UDP or both | TCP |
| Source restriction | Optional allowed outside addresses | A friend's address, if supported |
25565 is the usual port for a Java edition Minecraft server. Always take port numbers from the documentation of the software you run, and open only what it asks for.
How to set it up
- Get the service working locally. From another computer at home, connect to it using its local address. If that fails, forwarding won't fix it.
- Fix the device's address. Create a DHCP reservation so the rule doesn't end up pointing at a different device later.
- Create the rule. Sign in to the router and look for "Port forwarding", "Virtual server" or "NAT". Enter the fields above.
- Allow it on the device. The computer's firewall must accept the incoming port. On Windows, in an administrator PowerShell:
New-NetFirewallRule -DisplayName "Game server" -Direction Inbound -Protocol TCP -LocalPort 25565 -Action Allow On a Linux system using ufw:
sudo ufw allow 25565/tcp - Find your public address. The router's status page shows its internet-side address.
- Test from outside. Use a connection that isn't your home network, such as a phone on mobile data, or ask a friend.
A worked example
Say you want a friend to join a game server on your desktop. Your router's local network is 192.168.1.x, your desktop currently has 192.168.1.40, and your public address, in this example, is 203.0.113.7.
You reserve 192.168.1.40 for the desktop. You start the server and join it from a laptop at home using 192.168.1.40. That works, so you add a rule: TCP, external 25565, internal 25565, to 192.168.1.40. You add the matching Windows firewall rule. Your friend then connects to 203.0.113.7.
When the evening is over, you disable the rule. Most routers let you keep a disabled rule for next time. That limits exposure to the hours you actually need it.
Testing correctly
Testing from inside your own network using the public address can fail even when the rule is correct, because not every router supports looping that traffic back (often called hairpin NAT).
First confirm something is listening on the device:
# Windows, on the server
Get-NetTCPConnection -State Listen -LocalPort 25565 # Linux, on the server
ss -tln Then, from a computer outside your network that you control:
Test-NetConnection 203.0.113.7 -Port 25565 Substitute your real public address. Test only your own systems. UDP services are harder to check, since silence is normal for many of them; use the application itself.
When it still fails
Double NAT. If your router's internet address is private (starting 10., 192.168., or 172.16. through 172.31.), there is another router in front. Forward there too or switch it to bridge mode; see bridge mode and double NAT.
Carrier-grade NAT. If your provider shares public addresses among customers, you can't create the upstream rule. Ask whether a public address is available, or use a method that connects outward. Carrier-grade NAT has more.
Changing public address. Home addresses often change. A dynamic DNS service keeps a name pointed at your current one. Static versus dynamic addresses explains why.
The risk you take on
Automated scanners probe public addresses constantly. Assume an open port will be found quickly. What happens next depends on the service behind it: unpatched software or a weak password can hand over that device, and from there the attacker may reach others on your network.
Do not expose these directly:
- Remote desktop and screen sharing services.
- Windows file sharing and similar storage protocols.
- Telnet.
- Router, camera, printer or storage admin pages.
- Databases and development servers.
If you do expose something, keep it updated, use strong unique credentials and multi-factor authentication where possible, limit allowed source addresses, and watch its logs. Consider putting the server on a separate network from your personal devices. Changing the external port number reduces noise in the logs but doesn't make a weak service safe.
Narrow what you open
If you decide to forward, shrink the target:
- Forward one port, not a range, unless the software requires the range.
- Choose only TCP or only UDP when the documentation says one is enough.
- Restrict allowed source addresses if your router supports it and your visitors have stable ones.
- Run the service under an account with limited rights, on a machine that holds nothing precious.
- Turn on the service's own access list or allow list, so a stranger who finds it still can't get in.
- Check logs now and then for repeated failed logins or unfamiliar addresses.
If something looks wrong, disable the forward first and investigate afterward. Update or rebuild the affected device and change any passwords it held before opening it again.
Safer alternatives
| Need | Better option |
|---|---|
| Reach home files or computers yourself | A VPN into your home, such as WireGuard |
| Same, behind carrier-grade NAT | A mesh VPN service that connects outward |
| Publish a small website | Hosted service, or an outbound tunnel with access controls |
| Camera viewing | The maker's secured service, with a strong account |
| Play a game with friends | A hosted server or the game's own matchmaking |
A VPN still typically needs one forwarded UDP port at home, but it presents a single, purpose-built, authenticated service instead of many weak ones. Self-hosting a VPN walks through the choice.
UPnP and automatic forwards
UPnP lets devices create forwards themselves. It saves effort for games and calls, and it means rules appear without your review. Check the router's UPnP table now and then, or turn the feature off and add only what you want. See UPnP.
IPv6 is different
With IPv6, devices usually have their own globally reachable addresses and there is no address translation to forward through. The router's firewall still blocks unsolicited inbound traffic by default on a sensibly configured router. You create a firewall pinhole for a specific device and port, and the same cautions apply.
Check your terms
Some providers' terms limit running servers on residential connections, and some block particular inbound ports, commonly ones associated with mail or file sharing. Rules differ by provider and plan, so read yours. If you host for other people, you also take on responsibility for their data and for keeping the service patched.
At work, in shared housing or on any network you don't run, ask the person in charge instead of changing the router. A forward affects the security of everyone behind it.
Clean up
Review your forwarding list a few times a year. Delete rules for old games, retired devices and experiments, and remove the matching device firewall rules. On Windows:
Remove-NetFirewallRule -DisplayName "Game server" A list with nothing in it is a perfectly good result.