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

I have a web site which needs to send email to confirm orders and alert subscribed users of certain events. I do not need to send email through the server for any other reason, so I would like to prevent anyone outside of localhost from even connecting to port 25 for SMTP. I've tried to do this like so:

sudo iptables -A INPUT -p tcp -s 0.0.0.0 --dport 25 -j DROP

but I can still telnet to port 25 and type SMTP commands from another computer. What am I doing wrong? Also, is there a better way to achieve what I want? To clarify: what I want is a machine that can send emails (via SMTP), but only ones that originate from scripts running on the machine. And any configuration must "live" through re-boots.

I'm using Postfix on Ubuntu (Hardy).

share|improve this question

2 Answers 2

up vote 5 down vote accepted

I think that a better solution, if you don't want to be able to receive emails from outside, is to tell postfix that exactly, in the master.cf file replacing :

smtp      inet  n       -       n       -       -       smtpd

which is usually the first non comment line, but your mileage may vary depending on wether the postfix you have is modified by your vendor, with :

127.0.0.1:smtp      inet  n       -       n       -       -       smtpd
share|improve this answer
1  
+1 Fixing the problem not the symptoms. Much better than using iptables to block the ports. –  Grhm Feb 16 '10 at 8:28

I believe you don't want the -s 0.0.0.0 clause. You're only denying access from the 0.0.0.0 address.

You probably need something like:

sudo iptables -A INPUT -p tcp -s 127.0.0.0/8 --dport 25 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 25 -j DROP

This will accept any incoming connection from the localhost (i.e. from the loopback range - 127.0.0.1-127.255.255.255) and drop all others.

share|improve this answer
    
This works perfectly, thanks. But is there a way to get it to persist through server reboots? A config file to edit somewhere? (sudo find /etc -name iptables gives me nothing.) –  Alex Reisner Feb 15 '10 at 17:26
    
You want to install a /etc/init.d/iptables script, and set up a /var/lib/iptables/active file with your rules. See 5dollarwhitebox.org/wiki/index.php/Howtos_Basic_IPTables –  PP. Feb 15 '10 at 17:41

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.