Blocking FTP with iptables

7,774

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.

Share:
7,774
Alessandro Minoccheri
Author by

Alessandro Minoccheri

Updated on September 18, 2022

Comments

  • Alessandro Minoccheri
    Alessandro Minoccheri over 1 year

    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?

    • Alessandro Minoccheri
      Alessandro Minoccheri almost 11 years
      Yes but I wanna be sure what I set into iptables because I have a lot of site into this server
  • Alessandro Minoccheri
    Alessandro Minoccheri almost 11 years
    If I write the first iptables return me No chain/target/match by that name why? what is wrong?