Basic Postfix Configuration and Operation


Because Postfix is the Ubuntu-recommended client (and the mostly widely used client), the following sections provide a brief explanation and examples for configuring and operating your email system. As mentioned earlier, however, Postfix is an extremely complex program with many configuration options. As such, this chapter only covers some of the basics. For more information on Postfix, as well as other MTAs, see the "Reference" section at the end of this chapter.

Postfix configuration is handled by files in the /etc/postfix directory with much of the configuration being handled by the file main.cf. The actual syntax of the configuration file, main.cf, is fairly easy to read (see the following example):

# See /usr/share/postfix/main.cf.dist for a commented, more complete version # Debian specific:  Specifying a file name will cause the first # line of that file to be used as the name. The Debian default # is /etc/mailname. #myorigin = /etc/mailname smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) biff = no # appending .domain is the MUA's job. append_dot_mydomain = no # Uncomment the next line to generate "delayed mail" warnings #delay_warning_time = 4h # TLS parameters smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key smtpd_use_tls=yes smtpd_tls_session_cache_database = btree:${queue_directory}/smtpd_scache smtp_tls_session_cache_database = btree:${queue_directory}/smtp_scache # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for # information on enabling SSL in the smtp client. myhostname = optimus alias_maps = hash:/etc/aliases alias_database = hash:/etc/aliases mydestination = optimus, localhost.localdomain, , localhost relayhost = mynetworks = 127.0.0.0/8 mailbox_size_limit = 0 recipient_delimiter = + inet_interfaces = all 


Complicated email server setup is beyond the scope of this book, and we would point you in the direction of Postfix: The Definitive Guide by Dent. This is a great reference, and rather unusual because it only runs to just under 300 pages. However, if you want to know something about Postfix, this is the book to read.

However, the following five sections address some commonly used advanced options.

Configuring Masquerading

Sometimes you might want to have Postfix masquerade as a host other than the actual hostname of your system. Such a situation could occur if you have a dial-up connection to the Internet and your ISP handles all your mail for you. In this case, you will want Postfix to masquerade as the domain name of your ISP. For example

masquerade_domains = hudson.com


will strip any messages that come from andrew.hudson.com to just hudson.com.

Using Smart Hosts

If you do not have a full-time connection to the Internet, you will probably want to have Postfix send your messages to your ISP's mail server and let it handle delivery for you. Without a full-time Internet connection, you could find it difficult to deliver messages to some locations (such as some underdeveloped areas of the world where email services are unreliable and sporadic). In those situations, you can configure Postfix to function as a smart host by passing email on to another sender instead of attempting to deliver the email directly. You can use a line such as the following in the main.cf file to enable a smart host:

relayhost = mail.isp.net


This line causes Postfix to pass any mail it receives to the server mail.isp.net rather than attempt to deliver it directly. Smart hosting will not work for you if your ISP, like many others, blocks any mail relaying. Some ISPs block relaying because it is frequently used to disseminate spam.

Setting Message Delivery Intervals

As mentioned earlier, Postfix typically attempts to deliver messages as soon as it receives them, and again at regular intervals after that. If you have only periodic connections to the Internet, as with a dial-up connection, you likely would prefer that Sendmail hold all messages in the queue and attempt to deliver them whenever you connect to your ISP. You can configure Postfix to do so by adding the following line to /etc/ppp/peers/ppp0:

/usr/sbin/sendmail =q


This line causes Postifix to automatically send all mail when connecting to your ISP.

However, Postfix will still attempt to send mail regardless of whether the computer is on or off line, meaning that your computer may dial out just to send email. To disable this, you need to enter the following line into mail.cf:

defer_transports = smtp


This stops any unwanted telephone calls from being placed!

Tip

If you use networking over a modem, there is a configuration file for pppd called ppp0, which is located in /etc/ppp/peers. Any commands in this file automatically run each time the PPP daemon is started. You can add the line sendmail -q to this file to have your mail queue automatically processed each time you dial up your Internet connection.


Mail Relaying

By default, Postfix will not relay mail that did not originate from the local domain. This means that if a Postfix installation running at hudson.org receives mail intended for hudzilla.org, and that mail did not originate from hudson.org, the mail will be rejected and will not be relayed. If you want to allow selected domains to relay through you, add an entry for the domain to the main.cf file like so:

mynetworks = 192.168.2.0/24, 10.0.0.2/24, 127.0.0.0/8


The IP address needs to be specified in CIDR format. For a handy calculator, head on over to http://www.subnet-calculator/cidr.php. You must restart Postfix for this change to take effect.

Caution

You need a good reason to relay mail; otherwise, do not do it. Allowing all domains to relay through you will make you a magnet for spammers who will use your mail server to send spam. This can lead to your site being blacklisted by many other sites, which then will not accept any mail from you or your site's userseven if the mail is legitimate!


Forwarding Email with Aliases

Aliases allow you to have an infinite number of valid recipient addresses on your system, without having to worry about creating accounts or other support files for each address. For example, most systems have "postmaster" defined as a valid recipient, but do not have an actual login account named "postmaster." Aliases are configured in the file /etc/aliases. Here is an example of an alias entry:

postmaster: root


This entry forwards any mail received for "postmaster" to the root user. By default, almost all the aliases listed in the /etc/aliases file forward to root.

Caution

Reading email as root is a security hazard; a malicious email message can exploit an email client and cause it to execute arbitrary code as the user running the client. To avoid this danger, you can forward all of root's mail to another account and read it from there. You can choose one of two ways for doing this.

You can add an entry to the /etc/aliases file that sends root's mail to a different account. For example, root: foobar would forward all mail intended for root to the account foobar.

The other way is to create a file named .forward in root's home directory that contains the address that the mail should forward to.


Anytime you make a change to the /etc/aliases file, you will need to rebuild the aliases database before that change will take effect. This is done with the following:

$ sudo newaliases




Ubuntu Unleashed
Ubuntu Unleashed 2011 Edition: Covering 10.10 and 11.04 (6th Edition)
ISBN: 0672333449
EAN: 2147483647
Year: 2006
Pages: 318

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net