Enable Iptables & allow required traffic only in linux server
- User
Enable Iptables & allow required traffic only in linux server
- Assistant
To enable Iptables and allow required traffic only on a Linux server, follow these steps:
-
Check the current status of Iptables by running the following command: sudo systemctl status iptables
-
If the Iptables service is not running, start it by running the following command: sudo systemctl start iptables
-
Check the default policies for Iptables by running the following command: sudo iptables -L -v
-
Define the rules for Iptables by running the following command: sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT This command allows incoming SSH traffic (port 22) to the server.
-
Define rules for other required services, such as HTTP using the following command: sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT This command allows incoming HTTP traffic (port 80) to the server.
-
Block all other incoming traffic by default using the following command: sudo iptables -P INPUT DROP
-