DNS Setup and Port Forwarding
Introduction
When you buy your own domain form one of the many companies selling the service, the first thing you need to is to set your DNS setting. The goal is to route the traffic of the domain to your own IP address. But before going to that, let's talk about different types of IP addresses.
Dynamic vs Static IP address
IP address is the digital of your internet connection. It is set by your Internet Service Provider (ISP). There are two different types of IP address services you can get: Dynamic IP Address and Static IP Address. Normally you will be assigned a dynamic IP address unless you pay for a static one. The main difference between the two is that ISP will reserve and guarantee the IP address assigned to you, while the dynamic IP address can change. This potentially means that if you have a dynamic IP address and route the traffic of your domain to that address, it can change at any moment and makes your server unavailable. A decade ago, having a static IP address was mandatory; but for a personal server with services that will be used by only a handful of people, it shouldn't be a problem now. My dynamic Ip address has changed three times in the last six years, and it only happened when I changed my router.
Setting Up DNS
TO route the traffic from your domain to your server, first the DNS record must be set. This is done through the domain provider (where you registered your domain). Every provider's website is different, but generally, you will see these:
- Name: use @
- Type: A
- TTL: 1h
- Data: Here, you need enter the IP address provided by your internet provider. The easiest way to find this to just search 'What's my ip' on the internet when connected to the WiFi at home. Make sure you are not using any VPN services when you do this.
Directing traffic from your router to your server
Using the DNS settings, the traffic of your domain will be sent to your modem and then router in your home. Next, you need to redirect that to your server. This is done in the setting page of your router. The keyword you should look for in the setting page is "port forwarding" or "Virtual Server". Each port you need to access needs to be added here. In that page, you will generally see these fields:
- External Port: The port that the traffic is sent from.
- Internal Port: The port on the server you want to redirect the traffic to.
- Internal IP: Your Server IP Address
For example, for web traffic, you need to redirect ports 80 and 443, for OpenVPN port 1194, SSH port 22 are needed. IP address of your server in your own network can be found by running ip a on the server.