How to Block Ftp Access/Port using iptables OR CSF?

Posted by admin     Category: Linux Administration

The default firewall that comes along with Linux is “iptables” and you can use iptables to block Ftp access/port on your server.

Completely block Ftp access on the server:

# iptables -A INPUT -p tcp --dport 21 -j DROP

Block Ftp access for a specific IP address, say 11.12.13.14

# iptables -A INPUT -p tcp -s 11.12.13.14 --dport 21 -j DROP

Block Ftp access for a specific subnet

# iptables -I INPUT -p tcp -s 11.12.13.0/24 --dport 21 -j DROP

Make sure you save the iptable rules else they will be erased after a iptable/server restart:

# service iptables save

CSF firewall use iptables in the background to apply it’s rules. Edit the csf configuration file,

# pico /etc/csf/csf.conf

Remove port 21 from the TCP_IN list and restart the csf firewall

# csf -r

Block Ftp access for a specific IP address, edit the csf.deny file

# pico /etc/csf/csf.deny

and place the following line

tcp:in:d=21:s=11.12.13.14

Save the file and restart the csf firewall.

Tags: , , , , , ,

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image