IPTables: Difference between revisions

 
(7 intermediate revisions by the same user not shown)
Line 8:
= IPTables =
 
== Adding Rules ==
List rules
iptables -L
 
Allow SSH
Line 23 ⟶ 22:
Allow loopback
iptables -I INPUT 1 -i lo -j ACCEPT
 
== Reporting ==
 
List rules
iptables -L
iptables -L --line-numbers
 
Logging
iptables -I INPUT 5 -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
 
Check Stats
Saving rules
iptables -savenvL
iptables-restore
 
Reset Packet Counts and Aggregate Size:
Stop iptables
iptables -restoreZ
 
== Deleting Rules ==
 
Delete a Rule
iptables -D INPUT -p tcp --dport 80 -j ACCEPT
iptables -D INPUT -i ens160 -s 10.140.198.7 -j DROP
 
Delete by Rule Number
iptables -D INPUT 3 # Chain name = INPUT
 
Flush Chain
iptables --flush MYCHAIN
 
Flush Iptables
iptables -F
 
Delete Empty Chain
iptables -X MYCHAIN
 
 
== Saving Rules ==
SavingExport rules
iptables-save > /etc/iptables.conf
 
Restore them on every reboot
sudo nano /etc/rc.local
iptables-restore < /etc/iptables.conf
 
= UFW =
Line 77 ⟶ 107:
sudo ufw show logging-rules
 
Manage Application Traffic:
sudo ufw app list
sudo ufw app info Samba
sudo ufw allow from 192.168.1.0/24 to any app Samba
 
Rate Limiting:
sudo ufw limit 53/udp
sudo iptables -L | grep domain
 
Check Stats: