1

While setting up the IPtables rules for a new server, I set up Postfix and send an email to try it out. To my surprise the email arrived without me declaring a rule for the port in IPtables.

Additionally, I am using SquirrelMail and I had to make a rule specifically for it to being able to connect to using IMAP:

-A INPUT -p tcp -s 127.0.0.1 --dport 993 -j ACCEPT

When I previously inputed this rule to allow all connection on localhost

-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT

Probably I am making things wrongs, can you give me a clue?

This is what my IPtables rules looks like:

#  Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT

#  Accept all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

#  Allow all outbound traffic - you can modify this to only allow certain traffic
-A OUTPUT -j ACCEPT

#  Allow SSH connections
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

#  Allow HTTP and HTTPS connections from anywhere
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

# Allow IMAP connections only from localhost
-A INPUT -p tcp -s 127.0.0.1 --dport 993 -j ACCEPT

# Allow SVN server
-A INPUT -p tcp --dport 3690 -j ACCEPT

#  Allow ping
-A INPUT -p icmp -j ACCEPT

#  Log iptables denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7

#  Drop all other inbound - default deny unless explicitly allowed policy
-A INPUT -j DROP
-A FORWARD -j DROP

COMMIT
  • 3
    Did you send an email TO the server or FROM the server? – barrycarter Nov 3 '14 at 20:31
  • 1
    You might want to make sure you have the firewall turned on (e.g. /sbin/service iptables status) – Jonathan Nov 5 '14 at 20:57
  • 1
    Instead of adding DROP as last rule, use default policy (-P switch)! – F. Hauri Dec 21 '15 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.