open.itworld.com
  Search  
Security Home Page Security Webcasts Security White Papers Security Newsletters Security News Open Topics Careers ITworld Voices ITwhirled The Security site of ITworld.com

Unix Tip: Rejecting email from outside

ITworld.com 4/9/2007

Sandra Henry-Stocker, ITworld.com

Send in your Unix questions today! | See additional Unix tips and tricks

Any server that accepts email is at some risk of abuse. Given the relatively large population of dimwits in the world with nothing better to do with their time than send volumes of innocuous email to every email address they can conjure up (including such notables as nobody at various domains), there's good reason to avoid email altogether on servers that aren't intended to be mail servers.

If you would like to generate email on a server, but don't want to put up with email from the outside, you can configure sendmail to do this for you. The "trick" is to set up sendmail such that it listens on port 25 (as it always does), but only for the loopback address. When set up this way, a server will only allow connections on port 25 that are initiated on the local system. No other connections will be established, leaving your server with only its own mail to process.

Here's how to do this:

First, start with the sendmail.mc file that you used to build your current sendmail. Add the lines shown below before the MAILER line.

FEATURE(`no_default_msa')dnl
DAEMON_OPTIONS(`Family=inet, address=127.0.0.1, Name=MTA')dnl
DAEMON_OPTIONS(`Family=inet, address=127.0.0.1, Port=587, Name=MSA, M=E')dnl
CLIENT_OPTIONS(`Family=inet, Address=0.0.0.0')dnl
The bottom of your sendmail.mc file will then look something like this:

divert(0)dnl
VERSIONID(`$Id: generic-solaris.mc,v 8.13 2001/06/27 21:46:30 gshapiro Exp $')
OSTYPE(solaris2)dnl
DOMAIN(generic)dnl
FEATURE(`no_default_msa')dnl
DAEMON_OPTIONS(`Family=inet, address=127.0.0.1, Name=MTA')dnl
DAEMON_OPTIONS(`Family=inet, address=127.0.0.1, Port=587, Name=MSA, M=E')dnl
CLIENT_OPTIONS(`Family=inet, Address=0.0.0.0')dnl
MAILER(local)dnl
MAILER(smtp)dnl
Use the "sh Build sendmail.cf" command to create a new sendmail.cf file. Copy your current /etc/mail/sendmail.cf file to a safe place just in case you need it, such as /etc/mail/sendmail.cf.prev and then put your new sendmail.cf file into place. In addition to creating your new sendmail.cf file, this command will add the lines from your mc file as comments to the bottom of the new file. This ensures that you will not lose track of how your sendmail.cf file was configured and built and can save you a lot of trouble if you wipe out your sendmail source directory after you build a new release of the software and then want to recreate it.

Next, do the same basic thing for the submit.cf file -- use the "sh Build submit.cf" command to generate a new submit.cf file, back up your current file and put the new one in place.

To view how sendmail is accepting connections before you restart it, use the netstat command shown below. The string "*.25" means that it is listening for connections on port 25 for any IP address associated with the system -- generally the public IP address and the loopback.

netstat -an | grep 25
      *.25                 *.*                0      0 49152      0 LISTEN
At this point, you are ready to restart sendmail. You can then use the netstat command again to verify that sendmail is only listening on the loopback address:
# netstat -an | grep 25
127.0.0.1.25               *.*                0      0 49152      0 LISTEN
Here, we can see that port 25 is now only responsive to the loopback address. Any system now attempting to send mail to the server will fail with an error like that shown below.

# telnet nomail.mysite.com 25
Trying 205.244.233.22...
telnet: Unable to connect to remote host: Connection refused

On this topic

 

Sandra Henry-Stocker has been administering Unix systems for more than 18 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She currently works for TeleCommunication Systems, a wireless communications company, in Annapolis, Maryland, where no one else necessarily shares any of her opinions. She lives with her second family on a small farm on Maryland's Eastern Shore. Send comments and suggestions to bugfarm@gmail.com.




Sponsored Links

Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
TRY NEW SUN SERVERS FREE for 60 Days!
Test The Latest Sun Servers In Your Environment BEFORE YOU BUY. Pay Nothing, Not Even Shipping.
Workflow Enabled Help Desk & IT Service Management
Automate service desk activities and integrate processes across IT. Learn more here.
Sign up for a FREE NETWORK RISK ASSESSMENT!
MORE THAN 70% OF NETWORKS ARE INFECTED by hidden Malware. Find out if your network is infected now!
Enterprise IP Goes Mobile
To maximize full productivity, companies must integrate their mobile applications with the IP network.
» Buy a link now

Advertisements
Sponsored links
Top 5 Reasons to Combine App Performance and Security
Locate Hidden Software on business PCs with this free tool
KODAK i1400 Series Scanners stand up to the challenge
Bring harmony to your mix of UNIX-Linux-Windows computing environments
 Home   Open source  Operating systems  Unix
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.