Thursday, July 24, 2008

Sendmail Support and Installation

My favorite SMTP mail program of all time is Sendmail. This was obviously the first Linux SMTP MTA that I have used, and I still do. There are many more MTA's out there, but this one is mine ;-)


Ok, once you have installed a brand new Linux server, the standard sendmail installation is secure enough not to allow anyone or any other network besides the localhost to send any email. You will see when you do a " netstat -anop grep LIST " that sendmail is running on port 25 on 127.0.0.1. This is perfect since in the old day people will forget that they have not secured their sendmail installations, and become a SPAM host for the Internet.


SO the first step is to change the listen IP from 127.0.0.1 to either 0.0.0.0 or your IP of your server. To do this, you need to edit the sendmail.cf and make the following changes:


" vi /etc/mail/sendmail.cf "

Inside this file, look for the line that looks like this:


"O DaemonPortOptions=Port=smtp,Addr=127.0.0.1, Name=MTA"


Now, what you need to do it to change the MTA agent to listen on 0.0.0.0 and not just the localhost ip 127.0.0.1, so change the line to:


"O DaemonPortOptions=Port=smtp,Addr=0.0.0.0, Name=MTA"


Once you have done this, create a file called " relay-domains " in the /etc/mail directory, and in this file you need to put your domain name and the first 3 octets of your IP range like example 192.168.0 , just that


Then you can issue the following command to activate your changes:


" service sendmail reload "


You will see that the MAT now listen on 0.0.0.0:25 and by adding your domain name and IP range to that relay-domains file, you will be able to start using your mail server.


Below is a script I have written which you can use to activate new changes " on-the'fly" without having to restart sendmail. If you have a sendmail server you use in an ISP environment, you don't want to restart sendmail all the time, you will run into issues. See script below:

#!/bin/bash
cd /etc/mail
makemap hash virtusertable.db < virtusertable
makemap hash mailertable.db < mailertable
makemap hash access.db < access
newaliases > /dev/null 2> /dev/null
wait
ps auxw grep sendmail grep accepting awk '{print "kill -HUP "$2}' sh
echo "Rebuild aliases run now - "`date` >> /var/log/maillog

Call this file “sendmailreload” or something, make the file executable by typing " chmod 755 sendmailreload" and place the file under /usr/sbin.

I will add more pages for sendmail from here, each page dedicated to each file sendmail uses like local-host-names , mailertable etc.

No comments: