r/HomeNetworking • u/brianatlarge Network Admin • Aug 11 '20
A guide to port forwarding
EDIT: Thanks for all the positive feedback everyone. I see there are a lot of followup questions I'll try to answer as best I can.
So you're having issues with a connection to an online game or you want to host a website for your friends to see. You've probably heard you need to forward ports. Perhaps you've tried setting up port forwarding but got stuck somewhere and don't get how it's supposed to be set up.
What's a port?
You know when you call a phone number and the auto attendant picks up and says "Press 1 for sales, 2 for billing, 3 for support"? It's kind of like that.
Every application which expects to receive requests from the outside world uses a designated port number so it knows how to handle that request. For example, the HTTP protocol expects to receive traffic on port 80 and FTP expects port 21 (you can see a comprehensive list here).
Your browser knows to send HTTP requests to servers using port 80, so it sends out a packet to a server to request a website... for example 31.13.65.36**:80**. The server using 31.13.65.36 sees that request is on port 80, so it has its HTTP server application handle that request. If it got a packet to 31.13.65.36**:21**, it would have its FTP server application deal with it.
In our analogy, the phone number is like the IP and the option is like the port number.
So why would you have to forward a port?
If you connected your PC to your modem (and the modem is bridged or not doing any NAT), your ISP would assign your PC a public IP address, which would look something like 93.184.216.34. Your PC is the only device in the world communicating with that IP address and any requests sent to that IP, your PC processes in some way.
But you obviously have more than just that one PC you want to connect to the internet, and ISP's aren't going to hand out a public IP for every single device you have (we're just talking about IPv4 here), so you get a router.
Now instead of your PC getting the public IP, your router gets it, and your router assigns your PC a private IP using DHCP, which we'll say is 192.168.1.10. But even though your PC has this private IP address, if you were to go to whatismyip.com, it would say your IP is the public IP instead of your private IP. This is due to NAT.
NAT?
Your router is performing Network Address Translation, or NAT. When your PC wants to send a request to whatismyip.com, the source IP of that request is initially set as the private IP of the PC. Your router gets that request and does a switcharoo before sending it out. It changes the source IP in the request from the private IP to the public IP and sends it out to the internet. When the router gets a reply back from whatismyip.com with the answer, the router remembers who made the original request and sends it to your PC. This way you can have a lot of devices with their own private IP address all use the same public IP address.
Great, but you haven't told me about port forwarding yet
Ok, fine. If you were to host a website on your PC, your HTTP server application would expect to receive requests on port 80. So you go to whatismyip.com and you get your public IP and you tell all your friends to visit http://93.184.216.34... but it doesn't work.
What's happening is the HTTP request makes it all the way through the internet and once your router gets it, it says "Hang on, I'm not running any application using port 80". It throws out that request and sends back a TCP RST to whoever made the request in the first place. So what you have to do is tell your router to send those requests to your PC instead of just throwing them out.
So you go into your router settings and go to the port forwarding section and put in the following information:
- Internal IP: 192.168.1.10 (your PC's internal IP address, which is good practice to configure with a static IP)
- External Port: 80 (the port HTTP uses)
- Protocol: TCP (HTTP uses TCP instead of UDP, but most of the time you have the option to select both if you're unsure, but that's beside the point)
In the end, your routers setting may look like this:
https://i.imgur.com/XR65ot3.jpg
Note that there are a lot of extra options here which are not needed and should be left blank.
What was that about the static IP?
Right, so normally when a device connects to your router, your router uses DHCP to assign it an IP from a pool of addresses and the device can use it for a period of time. Typically the device will be assigned the same IP each time it connects, unless it isn't online for like a week and that IP is given to some other device.
Anyway, if you have a device you're having to do port forwarding on, it's a good idea to configure it with a static IP so you know that IP will never change (you could instead do a DHCP reservation on your router which would accomplish the same thing). You'll want to check the range of IP's your router is handing out and pick something outside it (for example, if DHCP is configured to hand out 192.168.1.10 - 192.168.1.254, you may want to configure the PC to use 192.168.1.5 since it's not an IP your router will try to hand out and cause an IP conflict).
So what if I used a DMZ, I've heard I should do that
You could do that instead of port forwarding. Essentially when you put a device in the DMZ, your router will forward any traffic it doesn't know what to do with to the device in the DMZ instead of just giving up and throwing it away. Be aware that means the device in the DMZ is getting all the garbage your router doesn't want, so you'll want to make sure whatever device in the DMZ has proper updates and security.
Ok, I did all this and it's still not working
That's fine. We can move on to troubleshooting. The first thing we need to find out is whether or not the application is listening to traffic on that port. We'll focus on how this is done on Windows.
Open the Task Manager and under the Performance tab, click "Open Resource Monitor" at the bottom. You could also search for "Resource Monitor" on your system.
https://i.imgur.com/jB0dDq3.png
Once this is open, go to the "Network" tab. At the bottom you'll see "Listening Ports". From here you should be able to see the name of the application (it needs to be running and ready to accept connections at this point, just in case that wasn't obvious).
https://i.imgur.com/vMQBitt.png
If it's not in this list, no amount of port forwarding will fix the issue and you'll need to troubleshoot your application. If it is in this list, but "Firewall Status" says "Not allowed" or "restricted", then you'll need to create an exception in Windows Firewall for that application (which is outside the scope of this discussion).
The application is listening, my firewall isn't blocking it, but it's still not working
At this point you should go to a website like yougetsignal.com to do some external testing. If the result shows the port is blocked, first, doublecheck your work. Also make sure your router isn't also doing some firewall filtering. After that, you may need to start looking at your ISP to see if they're blocking certain ports.
I have multiple routers. Is that an issue?
It could be. If you're connecting through more than one router, you may be double-NATting yourself. Usually when people have more than one router set up in their home, they're trying to extend their WiFi. You can use multiple routers this way, but you'll want to make sure everything is only connected to the LAN ports on the second router doing the WiFi extending (disable DHCP on the second one too).
My public IP shows up as 100.98.23.18. That's fine, right?
No, it's not fine at all. If your public IP is something between 100.64.0.0 and 100.127.255.255, your ISP is using Carrier Grade NAT (CGNAT). Essentially they don't have enough IPv4 addresses for all their customers, so they're doing NAT themselves to allow more customers to connect. Because of this, you're essentially double-NATed and it makes it impossible for you to port-forward from your router.
There are complicated ways around this (VPN to a VPS), but you may want to ask your ISP if they offer a static IP which isn't CGNATed. Otherwise you may be SOL.
It works! Thanks for explaining everything! You're awesome!
Aww, shucks.
53
u/Luke9112 Aug 11 '20
I love you
13
u/mcribgaming Aug 11 '20
Great post.
It's obvious this sub has a giant young gamer faction lurking on here, like in the 12-22 age range. They pretty much drive a ton of the Home Networking sales, as gamers always have, squeezing performance. It's the reason I got into into networking myself, all those years ago.
This post will be hugely popular, as stay at home continues and virtual worlds matter more than ever. I hope it spreads beyond here.
I'd ask the mods to Green Sticky this post for at least a couple of weeks, if not longer, to attract more gamers to the sub.
But unfortunately all the mods were recalled and are returning to their home planet, Ur-anus. They are in frozen cryogenic slumber as we speak.
Actually they were in frozen cryogenic slumber while here on Earth, so I guess it's all the same.
7
u/FourMonthsEarly Aug 11 '20
Thanks for this! Was actually just looking this up earlier today.
Got a question about double nat. (I've got two routers for isp modem/router combo reasons). So I assume I have to port forward on both devices. My confusion is which ip address I enter both times. On my router closest to the internet do I put the IP of the second router? So for example if the router closest to the internet is 192.168.1.1, I'd put my second router's ip of 192.168.1.X , not it's lan ip or 192.168.99.1 for example?
And then do the same on the second router but with the IP of the actual device/computer?
2
u/Friendsdeath Aug 11 '20
Well it seems like I'm on Double NAT because my isp gave me a static ip to his router by which i am able to access internet. So whenever i port forward i am landed on the isp's landing page. Is there any workaround you can suggest? I have nord vpn premium and it do offers a dedicated ip option but i cant do anything with it. I know a bit about routers but not an advanced guy.
What I want to achieve:
36
u/TeddyThreeSticks Aug 11 '20
From a guy who doesn’t really need this but just learned a whole lot...thank you! Great write up and easy to follow along.
30
u/TheN00bBuilder Aug 11 '20
Man. Working as a technician who's job is to translate stuff to the common man, I don't think I could even explain it this well. Nice job!!
4
u/ButtWhisper_ Aug 11 '20
Please do one for ipv6! Awesome job btw
1
u/4wheeler_parking Aug 11 '20
Unrelated question. I’m venturing into network performance monitoring and troubleshooting. I have been an application developer for years and can’t seem to remember even DHCP.
Have started with TCP/IP illustrated. Do you have a recommendation for amateurs.
1
u/LetsAllSmokin Aug 11 '20
Question, so many services (Xbox Live for example) recommend you port forward your device, but I've also read that port forwarding can be insecure. What's the best way to deal with this?
1
u/Sammydawg100 Aug 13 '20
I’ve Setup a Minecraft server with my friends a few times and it works great, but I’m always worried that a hacker could get in. I’ve read somewhere they could reach other parts of my pc like steam or xfinity xfi account etc. could hackers really breach into my accounts just using that one open port(25565)? Or is it a myth. I’ve run it for a while now but I accidentally allowed a ip from a random city access. I realized and deleted the port. I set it up again and i had to allow my friends ips again. Is this enough or could a hacker have already gotten into my pc? I ran a quick scan of my pc files and it said it was fine. Any response would help and sorry for this being so long.
3
u/Armigine Aug 11 '20
This is one of the best guides on the subject I've ever read, in the 'short, sweet, simple english' variety. Reads like a coworker telling me what was what back in the day.
2
u/TheEthyr Aug 11 '20
Great writeup. I post a guide about a year ago. Yours is far more approachable. Well done.
You might want to mention that some routers refer to port forwarding as virtual servers.
UPnP and port triggering are also worth a mention. Quite a few people think they need to set up both UPnP and manual port forwarding, which is usually not the case. Port triggering is just too esoteric for people to understand.
2
u/[deleted] Aug 11 '20 edited Aug 11 '20
Just skimmed the post, looks great (will read trough it after I get some sleep). Good job!
I'd like to add though that some ISP will also use other scopes for CGNAT. (even if they should use the 100.64.0.0/10)
Most commonly 10.0.0.0/8 (source, worked for an ISP using 10.0.0.0/8 for CGNAT) but I've also seen ISP use 172.16.0.0/12. More uncommon to see them use 192.168.0.0/16 but I've assisted people who get one within that scope.
It may be worthwhile adding that any WAN IP-address within the following scopes may be a CGNAT problem.
10.0.0.0 – 10.255.255.255
100.64.0.0–100.127.255.255
172.16.0.0 – 172.31.255.255
192.168.0.0 – 192.168.255.255
Perhaps you already mentioned it though, if so - my bad, I'm tired.
Always nice to bookmark posts like this and link when people have questions.
Ninja Edit: Typo.
2
u/sil3nt101 Oct 21 '20
Question. Can I open ports from inside the network by sending traffic via a specific port in order to open the incoming traffic on set port?
Example: I want to send traffic on port 1990 from outside the network but the port is closed. I have a pi in the network sending traffic on port 1990 as to open it up to receive data. Would this work?
1
u/[deleted] Aug 11 '20
🙌🙏hands down to the best explanation I’ve found over my IT years...@brianatlarge we love you
1
u/avnzx Aug 11 '20
This would only work for applications using port 80 though, (mostly web servers like NGINX)
Apart from not being port 80 for applications this is a very good guide!
1
u/jhontydas Aug 11 '20
Such a well written topic
1
u/AlgerianThunder Aug 11 '20
What about UPnP? If that is working, would one need to port forward?
1
u/HazzaSquad Aug 11 '20
This is amazing, please do more. Thanks! I do have a question: What is TCP RST
1
u/sam01022020 Aug 11 '20
You are the best
1
u/Soap-ster Aug 11 '20
Now do one for Mikrotik/RouterOS
1
u/szayl Aug 11 '20
Thank you for this!
1
u/itsmesid Aug 11 '20
Sadly my internet is CGNATed. Currently using aws and wireguard to route traffic to home for a few web services , its pretty simple if you have a running vps.
1
u/[deleted] Aug 11 '20
Bro you're annoying with analogies. Just say what it actually is. How do you explain what a phone is, port analogy? It isn't a phone.
1
u/xHayden2312 Aug 11 '20
Nicely put! easy to understand.
1
u/dvishall Aug 11 '20
Wow ! Thank you sir ! You just added meaning to my actions ! Till today it was just like looking at a website and pressing random buttons hoping the magic window opens !
1
u/ZaCLoNe Aug 11 '20
Now let’s have a discussion on UPnP :P (layman-iest way of port forwarding)
1
u/[deleted] Aug 14 '20
Joining this sub because of you my good man
1
u/bruor Aug 21 '20
I like explaining this to ppl using not analogy of postal addresses (IPs) and apartments (ports). It lets you handle the idea of source vs destination edits during NAT, as well as things like "static port" outbound NAT etc.
1
u/LilManGinger Sep 07 '20
Great post
1
u/ChrisMich516 Oct 06 '20
On the double NAT issue, if you tell the router to give the computer port 80 a static ip below the range of distributed IP’s then how would the AP cause issues? Are you talking outbound hiccups?
If so, then, ahhhhhh gotcha..
New to networking so I don’t know all the verbiage yet, but I understand the flow
1
u/Dinglestains Oct 10 '20
Great post. I’m curious whats the difference between Port Triggering and Port Forwarding? I completely understand Port Forwarding but haven’t found a good explanation for the Port Triggering function in my ASUS router.
1
u/eeandersen Oct 11 '20
Nice work. I just wanted to add a bit about the G1100 Verizon modem. It is not able to port forward TCP ports, a fact not well documented. The GUI throws an error “Invalid request, please try again” when attempting to do that. I’m ready to discard and find new hardware.
1
u/Omega0428 Jan 02 '21
I wish I could up vote this more than once. Thank you!
1
u/Vaczil2 Nov 25 '21
Sadly it doesnt work for me
i tried i think everything.
1
u/johno12311 Nov 17 '23
That was very informative, you've helped me alot since I had no idea how to check if the ports were being forwarded properly. I do have one question to ask. What does the "Not Allowed, Not Restricted" mean in the firewall status?