Before getting into port forwarding, let me explain a few basic networking concepts. Each device connected to a network has a unique identifier — the IP address. This address is used to identify and communicate with the device.
Consider your home network. You probably would have a router installed which is connected to the network of the Internet Service Provider (ISP) such as Verizon or Comcast. The router has an IP address — a unique public IP used to identify the device and to communicate with the internet. You connect various devices to this router — either using an ethernet cable or using wi-fi. Do these devices have their own IP address? Yes, they do. But they are private addresses, meaning these addresses are used to identify the device within your home network. These IP addresses are different from the public IP address of your router and devices outside your home network cannot communicate with your devices using just the private IP address. When one of the devices wants to communicate with the internet (devices outside your home network), the router replaces the private IP address with its public IP address for outgoing traffic and replaces the public address with the specific private IP address for all incoming traffic. This mapping is called Network Address Translation (NAT)
Let’s take a closer look at the device, say a laptop, connected to the router. It may be running multiple processes or services, e.g., SQL server, git server, TCP, FTP, etc. Just as the device needs a unique identifier, each service needs to be identified to enable communication. Port numbers help in identifying the services. Whenever a service needs to communicate, the port number helps identify the right destination/source on the device and helps in appropriate data transfer. To put it simply, IP address is the address of the device in the network whereas port is the address of a service on the device. The combination of IP address and the port number enables communication by identifying the source/destination of a particular service on a particular device. Most of the popular services have a default port associated with it, e.g., port 80 for HTTP, port 443 for https, port 25 for SMTP, port 20 for FTP, etc.
Port forwarding is the process of redirecting the communication addressed to one IP address/port combination to another address/port combination. But why do we need port forwarding? Port forwarding enables you to make a device connected to your private network available to access from the internet. Consider Gitstorage — an on-prem git server to safely store source code, for example. If you have connected it to your home network, you can access it using the private IP address and work without any additional setup.
However, what happens when you go for a coffee at a Starbucks and decide to access gitstorage? How can you access your device from the Starbucks wifi? For this to happen, you should have set up port forwarding. The router at home must be set up to direct all the incoming traffic at port 443 to gitstorage. TCP port 443 is the standard TCP port used for a website which uses SSL. Once this is set up, gitstorage is available on the internet, and you can access it outside your home network. Whenever there is a request sent to your router (using the public IP address) with port 443 as the destination, your router directs this traffic directly to your device. You can securely log in and continue your development. To reduce public exposure, it might be a better idea to use a non-standard port in port forwarding. This would avoid any danger from the scanners on the internet which continuously trying to access devices on standard ports.
Setting up port forwarding is straightforward. You would have to connect your device to your network, log in to the router, navigate to settings and under port forwarding. You should specify the specific port you want to forward to your device. As long as the port is open, your internet connection is working, and your device is connected to the network, you will be able to access it from anywhere outside your home network.
Gitstorage is the perfect device for people developing new software or considering alternatives to cloud git repositories.