What is iptables?
iptables is a tool used in Linux-based operating systems for configuring firewall rules. It allows filtering and forwarding of network packets based on various criteria such as IP addresses, ports, and protocols. It can be used for both protecting against network attacks and managing network traffic within the system.
Useful rules
iptables -A INPUT -p tcp --dport 80 -j ACCEPT: This command adds a rule to thefiltertable that accepts incoming TCP packets on port 80.iptables -A INPUT -s 192.168.0.0/24 -j DROP: This command adds a rule to thefiltertable that drops incoming packets from IP addresses in the range 192.168.0.0/24.iptables -A FORWARD -i eth0 -o eth1 -p icmp -j ACCEPT: This command adds a rule to thefiltertable that accepts ICMP packets passing through theeth0interface and exiting through theeth1interface.
Where:
-Aindicates adding the rule to the end of the chain (the table and chain must already exist),-pspecifies the protocol,--dportindicates the destination port,-sspecifies the source IP address or IP address range,-jindicates the action to be taken for matching packets (e.g.,ACCEPT- accept,DROP- drop).
Of course, there are many other options and combinations that can be used in iptables to customize filtering rules according to specific needs.
