For web devs, server or VPS is not a strange concept anymore, but have you ever thought of building a private server at home to test code or dabble? In this article I will guide the most detailed ways to Build a private server at home to use as a personal VPS.
This server you can use with many needs from hosting, personal DNS, or the main thing in my post is to use as VPS and create hosting packages for the domain.
- Main steps taken
- Install OS
- Install panel for VPS
- NAT Port for Server
- Use dynamic IP for the domain
1. Requirements before execution
Knowledge: It is not necessary to know many advanced abilities but basically it is a must:
- About domain, hosting
- Know a little bit about modems being used at home.
- Using the linux operating system
- SSH connection method
- Know how to use the service of Cloudflare.com
- Know how to create bootable USB.
In terms of material ????:If you don’t have it, it’s okay, if it’s not good, it’s fine
- 1 USB at least 4GB to use as USB to install OS (may not need, if using a virtual machine)
- Any computer or laptop is fine as long as it has the ability to connect to the network. Used as a server.
I would like to talk more about the dynamic IP of the modem, which means that every time your house disconnects the power of the modem or disconnects the fiber cable when the modem reconnects it will be given a new IP. Thus, the domain you are pointing to the IP will no longer be able to enter, instead of manually accessing the management page and pointing to the new IP, I will guide you to do it automatically.
2. Prepare the necessary files
Operating system: You can use CentOS, Ubuntu Server, Fedora, …. but in this article I will install Ubuntu Server.
- Ubuntu Server 16.04 LTS: https://releases.ubuntu.com/16.04
- Ubuntu Server 18.04 LTS: https://releases.ubuntu.com/18.04
- Ubuntu Server 20.04 LTS: https://releases.ubuntu.com/20.04
- CentOS 7, 8: https://www.centos.org/download
- Fedora Server: https://getfedora.org/en/server/download
Tool to create USB boot: https://rufus.ie (I often use this guy because it’s simple to use)
Panel for VPS: You can use the paid panels for better support and higher security.
In this article I will use Cyberpanel: https://cyberpanel.net
3. Install Ubuntu Server operating system
After selecting the language, Go to Network connections …
Here you should plug in the network cable or connect to Wifi first so that it can receive the IP from the modem too, no need to configure it manually.
Next, Config proxy, Config Ubuntu Archive server …. Enter to go through the step. Via Guided Storage config, leave it as default if you have 1 hard drive in your computer, if there is more, just choose the one you need to install the OS.
Go to confirmation step, select Done.
Next is to enter the information for the server.
- Your name: Enter an arbitrary name, do not enter any special characters
- Your server’s name: Enter the server name written without accents
- Pick a username: The server administrator’s login name, write immediately without accent, do not enter the word admin
- Password: Server login password, remember to enter it.
For SSH Setup, remember to tick the settings (use a space on the keyboard) and continue.
Through the Feature server snap you do not need to care, select Done to start installing Ubuntu Server on your computer.
This installation process takes about 15 minutes more, after successful installation select Reboot Now to reboot the machine (remember to remove the USB).
4. Install Cyber Panel on the server
In this step you can use the screen and keyboard attached to the server to type or skip aside and SSH into the server for easy copy-paste.
The server’s IP is in the first step in the OS installation, if you forget it, go to the modem and review the DHCP Info section or install additional net-tools with the command.
sudo apt net-tools
Type this command to see the IP network card in use
After SSH is in, type sudo to grant root access to install Cyber Panel.
sudo su -
Paste in the Cyber Panel installation command
sh <(curl https://cyberpanel.net/install.sh || wget -O - https://cyberpanel.net/install.sh)
Wait a moment, choose number 1 to install.
Next, choose 1 right away.
The next steps you choose are by default
- Install PowerDNS, Postfix, Pure-FTPd … select Y
- Do you want to setup Remote MySQL … select N
- Select MySQL version …. Enter to install the latest version
- Please choose default admin password 1234567 …. Enter to set the default admin password (can be
- changed later) or enter your password and Enter.
- Install Memcached … select N (can install later)
- Install Redis … select N as Memcached.
- Install Watchdog … select Y by default.
Wait for the installation to take place and complete, you will receive information about the panel below, if you don’t remember it, you can copy and save it somewhere.
At the visit site: in the picture is your IP outside the internet environment, now you have not logged out the port, then cannot enter. Therefore, you need to change the IP to a local IP (the IP just now was SSH).
At this point, you guys go to create a new website first to point out the IP.
5. NAT Port for server
NAT Port roughly understands that you will open ports on the server so that the outside can access it, which means that you point the domain to your home IP, then that domain can access.
NAT Port on modems: Not all modems are the same for this reference and in order to access these settings you need to know the admin account to log in to the modem (if not, ask for the network operator).
VNPT: Advenced Feature> NAT> DMZ Host
Viettel: Advenced Setup> Application> DMZ Host
TP-Link: Forwaring> DMZ
As below, I made all the ports on the IP of the new server installed on the Internet.
This step is simple like that, here you try to use 4G to access Cyber Panel via IP Wan in the information section at installation, see if it is possible, you have succeeded.
6. Automatically update dynamic IPs for domain names
As I said above, every time your home modem’s IP changes, you need to update the new IP. If you are not at home, it is impossible to know who the new ones are.
So, the following way will help you automate updating new IP for domain names. Here you transfer your domain name to Cloudflare.
Step 1: SSH into the server if exited. Type the following in turn (Source: https://github.com/LINKIWI/cloudflare-ddns-client)
git clone https://github.com/LINKIWI/cloudflare-ddns-client.git
sudo make install
If you type the last command and get the error as shown in the picture, you will type this command. Then retype the last command above.
sudo apt install python-is-python3
Step 2: Get the Cloudflare API Key used for updating IP here: https://dash.cloudflare.com/profile/api-tokens. If this step is not clear, then you should Google more, and it’s simple.
Step 3: Go back to SSH and type
Step 4: Enter the information for the cloudflare-ddns configuration
Choose [T] oken or [K] ey: select the letter K and then Enter.
Email: your cloudflare login email
API Key: paste the API Key taken from step 2.
Comma-delimited domains: enter the domain that needs to be updated, and multiple domains are separated by semicolons (,).
Step 5: When you receive the message Configuration file written …. successfully. Type in the following command to update the IP in your domain.
Step 6: Add cron job to automatically update IP, type the following command
In the crontab editing interface, add this line at the end and save. This line means that each day will update IP once, you can change as you like.
0 0 * * * /usr/local/bin/cloudflare-ddns --update-now
Step 7: Restart the server.
So I have guided you through the most detailed steps to build a private server at home for research and dabble. In fact, you can use this server to run demo web sites for customers or “genuine” rather than being used as the main VPS for your web sites. However, in order for the web to work properly, you will have to consider storing backup charges for the server to avoid power outages.