Firewall Configuration
A proper firewall configuration ensures that only essential traffic is allowed while unauthorized traffic is blocked. In this way, the firewall acts as a protective barrier between the secure internal network and potentially untrusted external networks, such as the internet.
Configuration with IpTables
iptables
is a firewall rule management tool in Linux, used to control network traffic by defining which packets can enter, exit, or pass through the system. It allows you to configure security policies to filter, redirect, and block traffic based on various criteria such as IP, port, and protocol. For example:
-
Generic command to open a specific port with iptables (replace
<PORTA>
with the desired port number)Terminal inputiptables -A INPUT -p tcp --dport <PORTA> -j ACCEPT
-
Save the
iptables
rulesTerminal inputservice iptables save
-
Reload the
iptables
serviceTerminal inputservice iptables reload
In some Linux distributions, iptables may not be enabled by default. Use the following commands to check and enable iptables:
-
Check if iptables is installed
Terminal inputsudo iptables -L
-
Install iptables if necessary
2.1 For RHEL-based systems
Terminal inputsudo yum install iptables-services
2.2 For OpenSUSE
Terminal inputsudo zypper install iptables
Configuration with firewalld
firewalld
is a dynamic firewall manager for Linux that provides a simplified interface to configure and manage firewall rules in real time. It supports trust zones and allows flexible security policies without restarting the network service. For example:
-
Generic command to open a specific port with firewalld (replace
<PORTA>
with the desired port number)Terminal inputsudo firewall-cmd --zone=public --add-port=<PORTA>/tcp --permanent
-
Reload the rules
Terminal inputsudo firewall-cmd --reload
Here is how to configure PostgreSYS component ports in firewalld:
-
Defining the ports
Terminal inputPORTAS=(5432 80 443 6432 8008 9187 8080 1982 2379 2380 9090 3000 9093)
for PORTA in "${PORTAS[@]}"; do
sudo firewall-cmd --zone=public --add-port=${PORTA}/tcp --permanent
done -
Reload the rules to apply the changes
Terminal inputsudo firewall-cmd --reload
If you need to install and enable firewalld:
-
Installation
-
Enterprise Linux
Terminal inputsudo dnf install firewalld
-
OpenSUSE
Terminal inputsudo zypper install firewalld
-
-
Enable firewalld to start on boot
Terminal inputsudo systemctl enable firewalld
-
Start the firewalld service
Terminal inputsudo systemctl start firewalld