Bo Wu's IT Lab

博闻精思 物我一体

Browsing Posts tagged UNIX & Linux

sendmail Build your Sendmail Relay Server in your LAN

I installed a sendmail relay server in my LAN so that other servers can use it to send emails. The following is how I did the configuration in a Ubuntu 9 machine.

1. First you need to install sendmail package.

2. After installation, you need to do the following configuration:

(1) Sendmail Master Configuration File: /etc/mail/sendmail.mc

# vi sendmail.mc

To enable relay on a specific IP, you need to change SMTP Daemon’s IP address. By default, it is 127.0.0.1 which is your localhost loopback address. This setting only allows you to send email from localhost. If you want other servers to use this server as relay to send emails, you much change to a valid IP address in your LAN, for example, it can be 192.168.0.88. In order to do so, you need to change the line 57 and 59 to as below:

DAEMON_OPTIONS('Family=inet,  Name=MTA-v4, Port=smtp, Addr=192.168.0.88')dnl
DAEMON_OPTIONS('Family=inet,  Name=MSP-v4, Port=submission, M=Ea, Addr=192.168.0.88')dnl

Please replace 192.168.0.88 with your real IP address. You also need to change following two lines at 100 and 104:

LOCAL_DOMAIN('yourhost.yourdomain')dnl
MAILER('smtp')dnl

Next step, you need to compile the sendmail.mc file to sendmail.cf file which will be actually used by sendmail. You need to type:

# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

You need to restart the sendmail server to make the change effective:

# /etc/init.d/sendmail restart

To check if the Sendmail is listening on an IP and a specific port, you can type:

# netstat -aunt

To check if the SMTP Port is open and listening from another server, you can type:

# nmap -v -sT 192.168.10.10 (IP address of this SMTP server)

(2) Configure the Access Control file: /etc/mail/access

# vi access

If you want to allow 192.168.0.99 to relay, add the following line:

Connect:192.168.0.99    RELAY

You also need to compile the access file to access.db file.

# makemap hash /etc/mail/access.db < /etc/mail/access

You need to restart the sendmail service to make it effective.

3. Sendmail Troubleshooting

If the local domain emails can not be delivered, and if your email service is hosted by an outside ISP, like Gmail (Google App.), please make sure your DNS setting will let you to resolve the correct MX record. Usually, you can set the external DNS server as your DNS server.

For example,

# vi /etc/resolv.conf

nameserver 206.0.6.60

You need to replace 206.0.6.60 with your real DNS Server’s IP address provided by your ISP.

How to Unzip Multiple=

When you try:
unzip *.zip

You will get the following error:
caution: filename not matched

When you want to unzip file using wild card, you have two options as follows.

Option # 1 : unzip multiple files using single quote (short version)

Type the command as follows:
$ unzip ‘*.zip’

Note that *.zip word is put in between two single quote, so that shell will not recognize it as a wild card character.

Option # 2 : unzip multiple files using shell for loop (long version)

You can also use for loop as follows:
$ for z in *.zip; do unzip $z; done