In this article, How to Setup a Firewall on a Dedicated Server will be taught. A firewall is one of the most important security aspects of any system. In fact, the firewall prevents malicious traffic hackers, and unauthorized access to your system. The function of the firewall is to switch and route packets between networks. Thus, it can control the incoming and outgoing traffic and allow the user to enter and access based on the defined rules. Choose and buy a cheap dedicated server from NeuronVM and run your firewall on it.
In this section, we are going to configure a firewall using IP tables. Doing this using IP tables is because IP tables enable you to have full control over Transmission Control Protocol (TCP) and Secure Shell (SSH) connections, etc.
The first requirement to configure the firewall with this method is that you must have access to the iptables program. The first step is to run the following command to check for any default rules being set:
iptables -L
Now you can add a new rule to a specific chain by running the following command. It should be noted that in the following command, incoming TCP is activated through port 7822. It is interesting to know that port 7822 is used by SSH:
iptables -A INPUT -p tcp -m tcp --dport 7822 -j ACCEPT
The following command allows you to enable incoming TCP connections on port 80 (HTTP):
iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
If you have set an SSL certificate for your site and want to enable access through port 443, you can use the following command.
Note: Port 443 is the default port for HTTPS.
iptables -I INPUT -p tcp -m tcp --dport 443 -j ACCEPT
To block a specific IP address from accessing your server, you can run the following command:
iptables -I INPUT rulenum -s 'IP address goes here' -j DROP
Another option is to substitute the original method with the Advanced Policy Firewall (APF). In this way, you can configure the firewall using a simple text editor. Go to the following path to access the configuration file:
/etc/apf/conf.apf
You can now open the configuration file using any text editor of your choosing, using the following command:
vi /etc/apf/conf.apf
Once the configuration file is opened, search for the commands below and adjust their values accordingly:
SET_MONOKERN="0"
HELPER_SSH_PORT="22"
IG_TCP_CPORTS="22"
Modify the values in the commands above like this. Then save the configuration file and exit:
SET_MONOKERN="1"
HELPER_SSH_PORT="7822"
IG_TCP_CPORTS="80, 7822, 443"
To initiate the APF program, execute the command below.
apf --start
Setup a Firewall on a Dedicated Server is a crucial step in securing your system and protecting it from cyber threats. By following the steps outlined in this article, you can configure a firewall effectively to control incoming and outgoing traffic, prevent unauthorized access, and monitor network activity. Regularly review and update your firewall configuration to adapt to changing security threats and ensure that your server remains secure. It may be interesting and useful for you to read the article What to Consider When Purchasing a Dedicated Server.
How useful was this post?
Click on a star to rate it!
Average rating 5 / 5. Vote count: 3
No votes so far! Be the first to rate this post.
Have you ever worked with Termux? If this is the case, you may have encountered some problems in thi...
Traceroute, is a computer network diagnostic tool that tracks the path of network packets from a sou...
What is your opinion about this Blog?