What IP to listen on to see web server from outside LAN?

3

Okay, so I'm semi-new to networking and to back-end web development, and am learning Flask presently.

I just turned on a basic little HTTP server on my laptop ("Hello World!") and am running it on port 5000. If I go to 127.0.0.1:5000 in my browser, I see the message correctly.

And if (on another computer in the house) I go to 192.168.1.40:5000, the private IP of the computer being used for the server, then I can see it from there, too.

But what if I want a friend to be able to access it from outside the local network, from far away? How do they find it?

I asked google what my IP (IPv4) was and tried using that, but as I expected it didn't work, since (as I understand it) that just resolves to the router itself, not necessarily the particular computer running the server. What am I doing wrong here?

temporary_user_name

Posted 2015-01-09T04:22:44.067

Reputation: 915

Answers

5

If you are using your home Internet and behind your router, then you need to setup a simple port forwarding to your local PC. Open up your router configuration and specify that port 5000 should lead to your private address (192.168.1.40).

It's also advisable to switch over any private address from dynamic to static for machines that host services so that their address does not change and thus break the port forward. This can be done simply by specifying an address for the machine in its network config that is outside the routers dynamic address pool (can be changed) and then specifying the routers address as both gateway and DNS server.

Example pool space: 192.168.1.100 - 192.168.1.200
Example router IP: 192.168.1.1
Example web server private static IP: 192.168.1.2

Then someone else must go to your public IP address (you can check it by service like http://www.whatismyip.com/ or similar).

Your public IP is usually dynamic. That means it may change from time to time. You can either buy a static IP (not all ISP can offer it) or use special DNS services for such purposes (for example, http://www.no-ip.org/ , http://dyn.com and similar).

nochkin

Posted 2015-01-09T04:22:44.067

Reputation: 337

OH IS THAT WHAT PORT FORWARDING IS? I've wondered that forever. – temporary_user_name – 2015-01-09T04:29:38.023

Yes, that's for that purpose specifically. Please also note that some ISP block certain ports (i.e. 25, 80), but if you use something like 5000, then you should be fine. – nochkin – 2015-01-09T04:31:18.350

Do real web servers use port forwarding or do they have a much more complex hardware setup custom configured for receiving incoming traffic? – temporary_user_name – 2015-01-09T04:33:00.203

They usually have public IP directly assigned so they don't need to forward anything. There are also load-balancers where they use something similar to port forwarding but more complex. – nochkin – 2015-01-09T04:34:25.023

Lastly, I don't NEED a static IP, right? Only if I really intend for this to stay up and be usable long-term. If I'm just playing around tonight, it doesn't matter, correct? And what about what this other guy is saying about a firewall rule? Sorry to have so many questions. – temporary_user_name – 2015-01-09T04:35:59.967

Correct. Static IP is to "protect" your IP from changing from time to time. But if you are willing to give your friend a new updated IP whenever it changed, then you are fine with this approach. – nochkin – 2015-01-09T04:38:55.510

0

See http://www.howtogeek.com/117371/how-to-find-your-computers-private-public-ip-addresses/ for a good explanation of your public and private IP addresses. In addition, you'll need a firewall rule to enable a list of IP's or to enable all IP's to send incoming messages to your PC; you can restrict traffic to a port [e.g. 80 for HTTP] or an array of ports. You might wish to delete that firewall rule when your done.

In addition, your router might also need to be configured to enable incoming traffic.

DrMoishe Pippik

Posted 2015-01-09T04:22:44.067

Reputation: 13 291