Question:
We have one of our websites up and running on our Nautilus infrastructure in Stratos DC. Our security team has raised a concern that right now Apache’s port i.e 3004 is open for all since there is no firewall installed on these hosts. So we have decided to add some security layer for these hosts and after discussions and recommendations we have come up with the following requirements:
1. Install iptables and all its dependencies (including iptables-services) on each app server (stapp01, stapp02 and stapp03). iptables-services alone does not provide the iptables command, so install both packages before you enable the service.
2. Block incoming port 3004 on all app servers for everyone except the LBR (load balancer) host stlb01. Either DROP or REJECT is fine.
3. Make sure the rules remain, even after system reboot: save them to /etc/sysconfig/iptables and enable the iptables service. Do not reboot the servers; the check reads the saved rules and the service state.
Solution:
iptables is a command-line utility used to configure IPv4 packet filtering and network address translation (NAT) rules for the Linux kernel’s Netfilter firewall framework. It lets administrators allow, block, modify, or forward network traffic based on criteria like IP addresses, ports, and protocols
Step 0:
# SSH to load balancer server
ssh loki@stlb01
# Get load balancer IP
hostname -I
10.244.49.57
# Exit to jump host
exit
Step 1:
# SSH to App server 1
ssh tony@stapp01
# Install iptables and iptables-services
sudo dnf install -y iptables iptables-services
# Enable service on boot
sudo systemctl enable --now iptables
Created symlink /etc/systemd/system/multi-user.target.wants/iptables.service → /usr/lib/systemd/system/iptables.service.
# Check iptables service status
systemctl status iptables
● iptables.service - IPv4 firewall with iptables
Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; preset: disabled)
Active: active (exited) since Wed 2026-12-02 06:12:47 UTC; 3s ago
Process: 43714 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
Main PID: 43714 (code=exited, status=0/SUCCESS)
CPU: 12ms
Step 2:
Take a look at the already existing rules. Take a note of 5th rule. It says REJECT all network traffic that doesn’t match rules from 1 through 4
# List iptables rules
sudo iptables -L INPUT --line-numbers -n
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
If we need to add a new rule we must add it before 5th REJECT firewall policy. In this case I will add the below firewall rule to allow traffic only from the load balancer server (IP: 10.244.49.57) on port 3004
# Rule 1: Add Local balancer IP to ACCEPT traffic to port 3004
sudo iptables -I INPUT 5 -p tcp -s 10.244.49.57 --dport 3004 -j ACCEPT
# List rules
sudo iptables -L INPUT --line-numbers -n
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
2 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0
3 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
5 ACCEPT tcp -- 10.244.49.57 0.0.0.0/0 tcp dpt:3004
6 REJECT all -- 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Step 3:
# Save config to /etc/sysconfig/iptable
sudo iptables-save | sudo tee /etc/sysconfig/iptables
# View file
sudo cat /etc/sysconfig/iptable
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [43:7128]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -s 10.244.49.57/32 -p tcp -m tcp --dport 3004 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Enabling the iptables service we already did in step 1. Running once again
sudo systemctl enable --now iptables
# Get App server 1 IP
hostname -I
10.244.97.166
# exit from app server 1 to hump host
exit
Continue step 1, 2 and 3 for app server 2 and 3.
Time to check from Jump host Server (no response coming in):
# Exit to jump host
# Curl from jump host to App server 1
curl http://10.244.97.166:3004
curl: (7) Failed to connect to 10.244.97.166 port 3004: No route to host
# Curl from jump host to App server 2
curl http://10.244.49.36:3004
curl: (7) Failed to connect to 10.244.49.36 port 3004: No route to host
# Curl from jump host to App server 3
curl http://10.244.49.53:3004
curl: (7) Failed to connect to 10.244.49.53 port 3004: No route to host
Time to check from Load Balancer Server (we get responses from all app servers):
# SSH to Load Balancer Server
ssh loki@stlb01
# Curl from jump host to App server 1
curl http://10.244.97.166:3004
Got response...
# Curl from jump host to App server 2
curl http://10.244.49.36:3004
Got response...
# Curl from jump host to App server 3
curl http://10.244.49.53:3004
Got response...
References:
https://www.geeksforgeeks.org/linux-unix/iptables-command-in-linux-with-examples
