I am planning to host my web-server on raspberry PI 3. I just went through the process of how to create web-server on raspberry pi.


It says basically we need to use port forwarding;

The router has an external IP address which it uses to communicate with the internet, and it has another IP address which it uses to communicate with your home network.

Let's say the router's external IP address is The router's internal address acts as a gateway for all the devices on your network. When your PC requests data from the internet, requests are automatically sent to the gateway address, and the router forwards the request to the internet. The gateway address is usually something like

So, my understanding is that basically, I need to get public ip e.g. and add this IP address to my router which is connected to raspberry pi.

My question is now if I have to access my page ( from outside my local area network (i.e. other connection which is connected with router and pi, is it accessible?

How to get public ip addresses? Is it free or paid monthly or yearly service?

Thanks, Jyoti Raj Sharma

  • You can find out your Public IP address my typing myip on google search box. If you just want to try to see whether you could access your raspberry pi via a public IP, port forwarding on your router is sufficient. However, if you truly want to host a website on your Raspberry Pi, it take more steps than just the tutorial you quoted, I've done a complete approach that may give you an idea on what are the considerations.
    – hcheung
    Commented Aug 31, 2017 at 2:00
  • Your link is based on nginx and php. But I have implemented node.js server which is currently running on my windows machine which now I want to move it to raspberry pi machine. Is it possible? Commented Aug 31, 2017 at 2:58
  • It doesn't matter what kind of server you are based on, Nginx, Apache or something else. The server settings might be different but the rest should be the same.
    – hcheung
    Commented Aug 31, 2017 at 6:16
  • There are serious potential risks to port forwarding if done carelessly. The level of your question suggests that this might not be a good thing for you to try just yet. No disrespect intended - Just don't want to do get burned by accidentally exposing your entire personal network to the whole world.
    – Brick
    Commented Aug 31, 2017 at 19:05
  • I have hosted my server code on AWS EC2 instance 8GB linux OS but that is chargeable after 1 year of free subscription. I am now publishing my data from raspberry pi 3 to AWS linux OS. Do you think this is good idea? The reason I asked to host on Raspberry Pi 3 is use to resources available with me rather than on cloud. Which one will be a better idea AWS linux OS or Raspberry pi3? Commented Aug 31, 2017 at 21:52

1 Answer 1


The concept you tried to look up is "NAT" (Network Address Translation). As you said correctly, it "masquerades" the traffic from inside your private network as it travels out of it.

If you want to access your webservice from outside your private network, the most precise request you can create is "Request on Port 80" (or another port, although 80 is default in browsers for plain HTTP). This request is delivered to your router, which is not able to do something with it, as its Port 80 will hopefully be closed (which should be the case, except there is a good reason to open it, like your scenario). You simply cannot talk to your Raspberry Pi specifically, if it is hidden in a NAT-Network.

Port forwarding solves the problem caused by NAT (which is imho a hack in itself). You basically have to tell your router "Forward every request from your outside IP on Port XX to Device YYY.YYY.YYY.YYY Port ZZ", where XX is the Port of your router being forwarded, YYY is the internal IP of your Raspberry Pi and ZZ being its Port (probably 80 and maybe 443).

In your scenario, you want your Router to forward every request to its outside IP on Port 80 (and maybe 443 for HTTPS) to the inside IP of your Raspberry Pi on Port 80 (and 443 respectively).

Static IP or Dynamic DNS: You can contact your ISP and just ask, if they offer it. It may cost additional money! You may also use services like DynDNS to get a domain which points to your Routers IP Address. Your router then contacts DynDNS after a change (or the Dynamic DNS service of your choice) to inform it. Using this, the domain always resolves to your routers IP address, even if it changes over time (this is good for testing purposes).

A serious word of warning: If you set up your router to do port forwarding, you open a gate into your private network. If your Raspberry Pi is compromised in any way, an attacker may gain access to your network and compomise other devices, so be VERY careful, if you set this up. Reading about DMZ or firewalls, may be a good idea. Keep this in mind. If your can access it from outside, chances are a malicious person can do it aswell. Make sure your network is configured properly

Edit: You may consider using a Web Hoster for a few bucks to host your website. You can develop it there without exposing your Raspberry Pi in your private network. If this is an option and your project is not about learning something regarding RaspPi specifically, I'd suggest this method. I don't know how much you know about network security, but simply Port Forwarding connection from outside to a potentially vulnerable device inside your private network is a serious threat, if not configured carefully.

  • I used dynamic DNS for 5 years when I hosted my server at home, it had a couple of hiccups but that have my hosted solution had as well...
    – MatsK
    Commented Aug 31, 2017 at 19:09
  • Yes, this is definitely an option, especially if a web service is still in development. However, I don't like the idea of a publicly accessible device inside my network. Assuming OP does not know much about network security (as this question about NAT is a pretty basic one), it may even be a considerable risk to every device inside the private network.
    – GxTruth
    Commented Aug 31, 2017 at 19:17
  • That is another question and not related to DynDNS, I used pfSense with multiple interfaces and I agree that running a server inside the home LAN instead of in a DMS is NOT RECOMMENDED.
    – MatsK
    Commented Sep 1, 2017 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.