Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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  --  0.0.0.0/0            0.0.0.0/0           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  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:21 reject-with icmp-port-unreachable 

is one, which doesn't work.

share|improve this question

1 Answer 1

Try:

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

or:

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

 
discard

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.