Recently, when I was working on a personal web application being built on my laptop I wanted to have my friends test it over the internet.
I did not have a domain purchased yet and it was not ready as a production version. I did not want to buy a domain at testing phase of the site. After a few trial and errors, I figured out how I have my development laptop act as a webserver and allow external users to connect.
This tip describes some simple steps which can be done to achieve this.
Using the Code
There is no coding needed for this - I will show here how to allow incoming traffic to your network end up routing the traffic to your local http server.
In my case, I was using a Microsoft IIS server, but this same trick can be applied for an application running on Java and using Apache server.
Considering you're using a Windows OS, first you need to figure out the IP address of your laptop. If you're inside a home network beside your ISP provided router, the router allocates different internal IPs to each of the latops connected to this network. These are internal IPs inside your network and not the IP on the world wide web.
First, you need to figure out what is your laptop's IP inside the network.
To get this, go to Windows command prompt and type
ipcofig|more - because the
ipconfig output sometimes is too big). In the output of the command, you will see a line like this:
The IPv4 address is the address of your latop (considering your ISP is using IPv4 protocol), in this case it is 192.168.0.3.
The default gateway address (192.168.0.1) is the one of your home routers. The gateway has a very important role to play in allowing incoming traffic and routing those to your laptop, but we will discuss that shortly.
Remember, none of these addresses are public IP address, these are merely internal IP addresses inside your network.
Now, as my application was a .NET application, I needed to publish it and run it on my IIS webserver. If you are publishing a J2EE application, you would have deployed it on your Apache tomcat or websphere or weblogic. etc.
My web application was deployed on my local IIS server on Windows on port 9881 -
See the binding details which says the application "onlineplat" is running on IP address 192.168.0.3 and listening on port 9881.
Now, my friends sitting outside of my network cannot connect to this application using the IP 192.168.0.3 - as this address is not visible to the outside world. How do I allow anyone else to connect to my applcation then? The trick is "IP-forwarding".
You have seen in the above screenshot where I did
ipconfig and got the address of the dafault gateway or my router: 192.168.0.1.
This address is mostly the same for all routers for home network world wide. You need to now type this IP on your browser.
Your router will now prompt for an id/password. In most of the cases, the id is something like "
admin" and the password is "
password" if you have not changed it. If you did not set it or don't remember, you can check your router version and search on the internet for the deault password for the router.
If you had already set the password and forgot it, you can press the "reset" button of your router and then open this same url (http://192.168.0.1), where you can change the password.
Here is the screenshot from my router's home page -
Different models of router will have different looking homepage, but all of them have a section "
ip-forwarding". You can search on the internet for your router's
ip-forwarding menu option. It generally is easy to find if you just search over the menu items.
The following screenshot shows the port forwarding rule I setup for my web-application:
What it means is, all incoming traffic to my home network on port 9881 will be forwarded to my laptop with address 192.168.0.3 which is the IP address (internal IP address within my home network) of my laptop running the application.
You also need to make sure that the port 9881 on your laptop is not blocking incoming traffic. To ensure this, type "firewall" in your windows run menu and setup an inbound rule to allow traffic on port 9881:
Now, the last part is to figure out your gateway's exact IP address over the work wide web - which you can find out from sites like - https://www.whatismyip.com/ (this is not the only one). Basically, these sites poll your gateway and show your IP address.
For me, the IP address was 220.127.116.11
So now I told my friends to type http://18.104.22.168:9881/onlineplat on their browser's URL and they were able to connect to my home made webserver over internet.
Of course, they were connecting using http and not https because I did not create my https settings - but that's part of a different discussion.
- 11th May, 2015: Initial version