Linux – Blocking FTP with iptables

iptableslinuxUbuntu

Hi all into my ubuntu server I want to block the ftp port for all except my ip:
123.123.123.123

How is possible this?

Best Answer

Write a rule which blocks all the incoming traffic for FTP, assuming the FTP port is 21:

iptables -A INPUT -p tcp --destination-port 21 -j DROP

Then write the following rule to exclude your IP from being blocked:

iptables -I INPUT -s 123.123.123.123 -p tcp --destination-port 21 -j ACCEPT

The -I parameter will insert the rule at the top of the stack. Since we didn't provide any rule number, it will be inserted at the top by default.