Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to set up iptables to log connection attempts to port 21 on a server, then deny the connection. The logging works, but I can't get iptables to actually reject the connection or drop the packets, no matter what I try.

Logging rule:

Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    LOG        tcp  --             tcp dpt:21 LOG flags 0 level 7 prefix `FTP connection: ' 

I've tried getting iptables to DROP and REJECT port 21 as the second rule, but it doesn't work and I can still reach the server on 21.

2    REJECT     tcp  --             tcp dpt:21 reject-with icmp-port-unreachable 

is one, which doesn't work.

share|improve this question


iptables -t filter -A INPUT -p tcp -m tcp --dport ftp \
         -j LOG -log-level 7 --log-prefix 'FTP connection: '
iptables -t filter -A INPUT -p tcp -m tcp --dport ftp -j DROP


iptables -t filter -N FTP
iptables -t filter -A FTP -j LOG --log-level 7 --log-prefix 'FTP connection: '
iptables -t filter -A FTP -j DROP
iptables -t filter -A INPUT -p tcp -m tcp --dport ftp -j FTP
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.