To manage IP access using iptables
, here are some common commands:
iptables -A INPUT -s xx.xx.xx.xx -j DROP
- Block an IP address from a specific port:
iptables -A INPUT -p tcp -s xx.xx.xx.xx --dport PORT -j DROP
(Replace xx.xx.xx.xx
with the remote IP address and PORT
with the specific port number.)
- Allow access from an IP address:
iptables -A INPUT -s xx.xx.xx.xx -j ACCEPT
- Allow access from an IP address to a specific port:
iptables -A INPUT -p tcp -s xx.xx.xx.xx --dport PORT -j ACCEPT
(Replace xx.xx.xx.xx
with the remote IP address and PORT
with the port number.)
- Block a scanner or specific traffic:
iptables -I INPUT -p tcp --dport 80 -m string --algo bm \
--string 'GET /blablabla.at.ISC.SANS.' -j DROP
For more details on common iptables
rules, refer to our guide on basic and most common iptables rules.