title: How to allow mail through iptables?
body: <p>I'm securing my server (with iptables) so that only http and ssh ports are open and that is fine, although I use the <code>mail</code> command (server: CentOS 6.2) in some applications and it does not get through now thanks to iptables blocking everything.</p>
  
  <p>What ports do I allow it access to?</p>
  
  <p>Mail usage: <code>echo "{{message}}" | mail -s "{{subject}}" me@mail.com</code></p>
  
  <p>I've tried the standard mail port 25, but I have had no success with that.
  Here is the current setup:</p>
  
  <pre><code>iptables --flush
  
  iptables -P INPUT DROP
  iptables -P OUTPUT DROP
  
  # incoming ssh
  iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT 
  iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT 
  
  # outgoing ssh 
  iptables -A OUTPUT -o eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT 
  iptables -A INPUT -i eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT 
  
  #HTTP
  iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT 
  iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT 
  
  # mail (does not work)
  iptables -A INPUT -i eth0 -p tcp --dport 25 -m state --state NEW,ESTABLISHED -j ACCEPT
  iptables -A OUTPUT -o eth0 -p tcp --sport 25 -m state --state ESTABLISHED -j ACCEPT
  </code></pre>
  
  <p><strong>(EDIT) ANSWER: The working iptables rule:</strong> </p>
  
  <pre><code>iptables -A OUTPUT -o eth0 -p tcp --sport 25 -m state --state NEW,ESTABLISHED -j ACCEPT
  iptables -A OUTPUT -o eth0 -p tcp --dport 25 -m state --state NEW,ESTABLISHED -j ACCEPT
  iptables -A INPUT -i eth0 -p tcp --sport 25 -m state --state ESTABLISHED -j ACCEPT
  </code></pre>