Linux(Application Security): Steps to open all incoming connections and block all incoming connections
Lets say, We want to open all incoming connections to Nginx’s port(8095) and block all incoming connections to Apache’s port(8085). Also make sure rules are permanent.
Step 1:
Flush the current iptables rules
iptables -F
Step 2:
Allow incoming traffic on Nginx’s port (8095)
iptables -A INPUT -p tcp --dport 8095 -j ACCEPT
Step 3:
Block incoming traffic on Apache’s port (8085)
iptables -A INPUT -p tcp --dport 8085 -j DROP
Step 4:
Save the changes to the iptables rules
iptables-save > /etc/sysconfig/iptables
Step 5:
Restart the iptables service to apply the changes
systemctl restart iptables
With these steps, incoming connections to Nginx’s port 8095 will be allowed and incoming connections to Apache’s port 8085 will be blocked. To make the rules permanent, you need to add the iptables-save command in the appropriate script that runs at boot time.