How to convert your laptop/desktop into a server and host internet accessible website on it: Part 2

1*j0u815XhZlvgrcRbswSi w

This is the part 2 of the article series on hosting a website on the internet using your own laptop. In part 1 we developed the concepts of internet structure and functionings. In this part, I will guide you through the process of getting the website hosted and running on the internet.

Here is the demo of a live server running on my laptop:

https://janishar.com/

Part 1 link: CLICK HERE

I have also created FREE video lessons for understanding Internet: Here is the link

One important concept in the communication over the internet, are ports. So, what is a port?

A port that we generally heard of are used to connect monitor, webcam, speakers etc. On the physical layer, a computer port is a specialized outlet on a piece of equipment to which a plug or cable connects.

But the port that we are referring to from the internet or software perspective has a different meaning. In the internet protocol suite, a port is an endpoint of communication in an operating system, in software, it is a logical construct that identifies a specific process or a type of network service.

A port is always associated with an IP address of a host and the protocol type of the communication, and thus completes the destination or origination network address of a communication session. A port is identified for each address and protocol by a 16-bit number, commonly known as the port number. For example, an address may be “protocol: TCP, IP address: 1.2.3.4, port number: 80”, which may be written 1.2.3.4:80 when the protocol is known from context.

What the above text basically mean is that any communication between network devices take place over a port, which is a software construct that helps in data reception and processing for the network devices. The port, which is the number after “:” in the IP address defines the port on which the data has to be sent. We must have seen port numbers in the URLs. By default, HTTP uses port 80 and HTTPS uses port 443, and we don’t add them in the browser but are implicitly handled by the browsers. But a URL like http://www.example.com:8080/path/ specifies that the web browser connects instead to port 8080 of the HTTP server.

What is port forwarding?

Port forwarding or port mapping is an application of network address translation (NAT) that redirects a communication request from one address and port number combination to another while the packets are traversing a network gateway, such as a router or firewall. This technique is most commonly used to make services on a host residing on a protected or masqueraded (internal) network available to hosts on the opposite side of the gateway (external network), by remapping the destination IP address and port number of the communication to an internal host.

What this mean is that when a request arrives at a router at a specific port then it reroutes this request to a server in the local network of the router so to be able to process it (if configured on NAT settings). So, it in a way works as a gatekeeper.

The IP address on the web server in a number like 123.123.123.123 but how does http://www.example.com be able to communicate with that server?

example.com is called as a Domain name. Domain names are the human-friendly forms of Internet addresses and are commonly used to find websites. The domain name system(DNS) is essentially a global addressing system. It is the way that domain names are located and translated into Internet Protocol (IP) addresses, and vice versa. A domain name such as example.com is a unique alias for an IP address http://123.123.123.123:80, which is an actual physical point on the Internet. The Internet Corporation for Assigned Names and Numbers (ICANN) is a non-profit organization responsible for coordinating the maintenance and procedures of several databases related to the namespaces of the Internet. We can buy a domain name like I did with janishar.com from a vendor like GoDaddy and others for a period and then tell that domain to point to an actual server address using the websites of those vendors.

What is public IP address?

A public IP address is an IP address that our home or business router receives from your ISP. Public IP addresses are required for any publicly accessible network devices, like for our home router as well as for the servers that host websites.

Public IP addresses are what differentiate all devices that are plugged into the public internet. Each and every device that’s accessing the internet is using a unique IP address. It’s this address that each Internet Service Provider uses to forward internet requests to a specific home or business.

We now have developed all the concepts required to build our own server for the internet.

First, we will setup the router for receiving the request on its public IP address and then forward the request to a computer in the local network.

Access your router software using a browser by entering its local IP address. You can find the local IP address using network details option in the connectivity of your laptop or using netstat -rn on linux terminal. It is the Default gateway address(Mine is 192.168.1.1).

Provide the user name and password which generally is written at the bottom of the router or is “admin” for both entries. The steps you will take will vary according to the brand and model of your router but the process will be more or less the same. My router in of Tenda.

This site provides steps for port forwarding for most of the Routers: https://portforward.com/router.htm

Find your Router in that site and follow those steps. I will cover Tenda router settings in this article.

Step 1: Find the public IP of the router:

Advanced(top right) > Device Info(top left menu) > Table WAN status > WAN IP Address

(If you will enter the WAN IP Address then you will see your router’s login page.)

Step 2: Free the port 80 and 443 if being used in the router.

This was trickier for my router.

Advanced(top right if not there) > Management > Access Control > AccessCtrl

Enable WAN for HTTP > Change Port to 8080 > Disable WAN for HTTP

Enable WAN for HTTPS > Change Port to 8081 > Disable WAN for HTTPS

Apply/Save

Step 3: Change router password for security

Advanced(top right if not there) > Management > Access Control > Passwords > Apply/Save

Step 4: Setup NAT

Advanced(top right if not there) > Advanced Setup > NAT > Virtual Servers > Add

Custom Service: > enter a name > Server IP Address:> add the ip address of the laptop that will be a server (put it 192.168.1.250 and we will setup this ip address manually on the laptop)

Fill the table entry as:

External Port Start > 80 > External Port End > 80 > Protocol> TCP > Internal Port Start > 80 > Internal Port End > 80 > Apply/Save

Similarly add another NAT entry for 443 if you want to configure HTTPS like I have in my https://janishar.com site.

Step 5: Restrict the DHPC to allot the 192.168.1.250 IP to any other device

NOTE: You should add 250 as your host if your default gateway is 192.168.0.1 then use 192.168.0.250

Advanced(top right if not there) > Advanced Setup > LAN > Enable DHCP Server > End IP Address > Enter 192.168.1.245 > Apply/Save

Step 6: Setup 192.168.1.250 IP address for connection in Ubuntu or any OS you are running on your laptop.

I will tell you to use the GUI as it is simpler.

Connection (Top right option) > Connections Information > Keep it open to copy paste

Connection (Top right option) > Edit Connections > You current connection name > Edit > IPv4 Settings > Add (if there is no entry)

Address > 192.168.1.250 >Copy rest from the Connections Information > Save

Now reconnect the wifi or LAN wire connection.

Step 7: Run a server program on your laptop.

I am running Nginx. You can run any such program, Apache, Tomcat, etc. I will not explain the process of setup for these in this Article. You should find a relevant tutorial on them and do it yourself.

For Nginx setup, you can refer: https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04

My Nginx server is listening on port 80 and serving the static website that you can see here https://janishar.com.

For HTTPS I have used Certbot. Link is here for Nginx : https://certbot.eff.org/#ubuntutrusty-nginx

Step 8: Point your domain to your Public IP address:

When you enter your public IP address on your browser you can hopefully see your website if everything is configured well. But we want a name like janishar.com to be able easily to access it on the internet.

Buy a Domain from any merchant and then put your public IP in the “A” record and it will be live for the user on the internet.

You can see my live website https://janishar.com.

This ends this Article series. Hope you learned from it and be able to build your own website or API server and make it live from your local machine.

I have also created video lecture for understanding Internet.