1<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN" 2 "http://www.w3.org/TR/html4/loose.dtd"> 3 4<html> 5 6<head> 7 8<title> Postfix Basic Configuration </title> 9 10<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"> 11 12</head> 13 14<body> 15 16<h1><img src="postfix-logo.jpg" width="203" height="98" ALT="">Postfix Basic Configuration </h1> 17 18<hr> 19 20<h2> Introduction </h2> 21 22<p> Postfix has several hundred configuration parameters that are 23controlled via the main.cf file. Fortunately, all parameters have 24sensible default values. In many cases, you need to configure only 25two or three parameters before you can start to play with the mail 26system. Here's a quick introduction to the syntax: </p> 27 28<ul> 29 30<li> <p> <a href="#syntax">Postfix configuration files</a></p> 31 32</ul> 33 34<p> The text below assumes that you already have Postfix installed 35on the system, either by compiling the source code yourself (as 36described in the INSTALL file) or by installing an already compiled 37version. </p> 38 39<p> This document covers basic Postfix configuration. Information 40about how to configure Postfix for specific applications such as 41mailhub, firewall or dial-up client can be found in the 42STANDARD_CONFIGURATION_README file. But don't go there until you 43already have covered the material presented below. </p> 44 45<p> The first parameters of interest specify the machine's identity 46and role in the network. </p> 47 48<ul> 49 50<li> <p> <a href="#myorigin"> What domain name to use in outbound mail </a> </p> 51 52<li> <p> <a href="#mydestination"> What domains to receive mail for </a> </p> 53 54<li> <p> <a href="#relay_from"> What clients to relay mail from </a> </p> 55 56<li> <p> <a href="#relay_to"> What destinations to relay mail to </a> </p> 57 58<li> <p> <a href="#relayhost"> What delivery method: direct or 59indirect </a> </p> 60 61</ul> 62 63<p> The default values for many other configuration parameters are 64derived from just these. </p> 65 66<p> The next parameter of interest controls the amount of mail sent 67to the local postmaster: </p> 68 69<ul> 70 71<li> <p> <a href="#notify"> What trouble to report to the postmaster 72</a> </p> 73 74</ul> 75 76<p> Be sure to set the following correctly if you're behind a proxy or 77network address translator, and you are running a backup MX host 78for some other domain: </p> 79 80<ul> 81 82<li> <p> <a href="#proxy_interfaces"> Proxy/NAT external network 83addresses </a> </p> 84 85</ul> 86 87<p> Postfix daemon processes run in the background, and log problems 88and normal activity to the syslog daemon. Here are a few things 89that you need to be aware of: </p> 90 91<ul> 92 93<li> <p> <a href="#syslog_howto"> What you need to know about 94Postfix logging </a> </p> 95 96</ul> 97 98<p> If your machine has unusual security requirements you may 99want to run Postfix daemon processes inside a chroot environment. </p> 100 101<ul> 102 103<li> <p> <a href="#chroot_setup"> Running Postfix daemon processes 104chrooted </a> </p> 105 106</ul> 107<p> If you run Postfix on a virtual network interface, or if your 108machine runs other mailers on virtual interfaces, you'll have to 109look at the other parameters listed here as well: </p> 110 111<ul> 112 113<li> <p> <a href="#myhostname"> My own hostname </a> </p> 114 115<li> <p> <a href="#mydomain"> My own domain name </a> </p> 116 117<li> <p> <a href="#inet_interfaces"> My own network addresses </a> </p> 118 119</ul> 120 121<h2> <a name="syntax">Postfix configuration files</a></h2> 122 123<p> By default, Postfix configuration files are in /etc/postfix. 124The two most important files are main.cf and master.cf; these files 125must be owned by root. Giving someone else write permission to 126main.cf or master.cf (or to their parent directories) means giving 127root privileges to that person. </p> 128 129<p> In /etc/postfix/main.cf you will have to set up a minimal number 130of configuration parameters. Postfix configuration parameters 131resemble shell variables, with two important differences: the first 132one is that Postfix does not know about quotes like the UNIX shell 133does.</p> 134 135<p> You specify a configuration parameter as: </p> 136 137<blockquote> 138<pre> 139/etc/postfix/main.cf: 140 parameter = value 141</pre> 142</blockquote> 143 144<p> and you use it by putting a "$" character in front of its name: </p> 145 146<blockquote> 147<pre> 148/etc/postfix/main.cf: 149 other_parameter = $parameter 150</pre> 151</blockquote> 152 153<p> You can use $parameter before it is given a value (that is the 154second main difference with UNIX shell variables). The Postfix 155configuration language uses lazy evaluation, and does not look at 156a parameter value until it is needed at runtime. </p> 157 158<p> Postfix uses database files for access control, address rewriting 159and other purposes. The DATABASE_README file gives an introduction 160to how Postfix works with Berkeley DB, LDAP or SQL and other types. 161Here is a common example of how Postfix invokes a database: </p> 162 163<blockquote> 164<pre> 165/etc/postfix/main.cf: 166 virtual_alias_maps = hash:/etc/postfix/virtual 167</pre> 168</blockquote> 169 170<p> Whenever you make a change to the main.cf or master.cf file, 171execute the following command as root in order to refresh a running 172mail system: </p> 173 174<blockquote> 175<pre> 176# postfix reload 177</pre> 178</blockquote> 179 180<h2> <a name="myorigin"> What domain name to use in outbound mail </a> </h2> 181 182<p> The myorigin parameter specifies the domain that appears in 183mail that is posted on this machine. The default is to use the 184local machine name, $myhostname, which defaults to the name of the 185machine. Unless you are running a really small site, you probably 186want to change that into $mydomain, which defaults to the parent 187domain of the machine name. </p> 188 189<p> For the sake of consistency between sender and recipient addresses, 190myorigin also specifies the domain name that is appended 191to an unqualified recipient address. </p> 192 193<p> Examples (specify only one of the following): </p> 194 195<blockquote> 196<pre> 197/etc/postfix/main.cf: 198 myorigin = $myhostname (default: send mail as "user@$myhostname") 199 myorigin = $mydomain (probably desirable: "user@$mydomain") 200</pre> 201</blockquote> 202 203<h2><a name="mydestination"> What domains to receive mail for </a> 204</h2> 205 206<p> The mydestination parameter specifies what domains this 207machine will deliver locally, instead of forwarding to another 208machine. The default is to receive mail for the machine itself. 209See the VIRTUAL_README file for how to configure Postfix for 210hosted domains. </p> 211 212<p> You can specify zero or more domain names, "/file/name" patterns 213and/or "type:table" lookup tables (such as hash:, btree:, nis:, ldap:, 214or mysql:), separated by whitespace and/or commas. A "/file/name" 215pattern is replaced by its contents; "type:table" requests that a 216table lookup is done and merely tests for existence: the lookup 217result is ignored. </p> 218 219<p> IMPORTANT: If your machine is a mail server for its entire 220domain, you must list $mydomain as well. </p> 221 222<p> Example 1: default setting. </p> 223 224<blockquote> 225<pre> 226/etc/postfix/main.cf: 227 mydestination = $myhostname localhost.$mydomain localhost 228</pre> 229</blockquote> 230 231<p> Example 2: domain-wide mail server. </p> 232 233<blockquote> 234<pre> 235/etc/postfix/main.cf: 236 mydestination = $myhostname localhost.$mydomain localhost $mydomain 237</pre> 238</blockquote> 239 240<p> Example 3: host with multiple DNS A records. </p> 241 242<blockquote> 243<pre> 244/etc/postfix/main.cf: 245 mydestination = $myhostname localhost.$mydomain localhost 246 www.$mydomain ftp.$mydomain 247</pre> 248</blockquote> 249 250<p> Caution: in order to avoid mail delivery loops, you must list all 251hostnames of the machine, including $myhostname, and localhost.$mydomain. </p> 252 253<h2> <a name="relay_from"> What clients to relay mail from </a> </h2> 254 255<p> By default, Postfix will forward mail from clients in authorized 256network blocks to any destination. Authorized networks are defined 257with the mynetworks configuration parameter. The current default is to 258authorize the local machine only. Prior to Postfix 3.0, the default 259was to authorize all clients in the IP subnetworks that the local 260machine is attached to. </p> 261 262<p> Postfix can also be configured to relay mail from "mobile" 263clients that send mail from outside an authorized network block. 264This is explained in the SASL_README and TLS_README documents. </p> 265 266<p> IMPORTANT: If your machine is connected to a wide area network 267then your default mynetworks setting may be too friendly. </p> 268 269<p> Examples (specify only one of the following): </p> 270 271<blockquote> 272<pre> 273/etc/postfix/main.cf: 274 mynetworks_style = subnet (default: authorize subnetworks) 275 mynetworks_style = host (safe: authorize local machine only) 276 mynetworks = 127.0.0.0/8 (safe: authorize local machine only) 277 mynetworks = 127.0.0.0/8 168.100.189.2/32 (authorize local machine) 278</pre> 279</blockquote> 280 281<p> You can specify the trusted networks in the main.cf file, or 282you can let Postfix do the work for you. The default is to let 283Postfix do the work. The result depends on the mynetworks_style 284parameter value. 285 286<ul> 287 288<li> <p> Specify "mynetworks_style = host" when Postfix should 289forward mail from only the local machine. </p> 290 291<li> <p> Specify "mynetworks_style = subnet" (the default) when 292Postfix should forward mail from SMTP clients in the same IP 293subnetworks as the local machine. On Linux, this works correctly 294only with interfaces specified with the "ifconfig" command. </p> 295 296<li> <p> Specify "mynetworks_style = class" when Postfix should 297forward mail from SMTP clients in the same IP class A/B/C networks 298as the local machine. Don't do this with a dialup site - it would 299cause Postfix to "trust" your entire provider's network. Instead, 300specify an explicit mynetworks list by hand, as described below. 301</p> 302 303</ul> 304 305<p> Alternatively, you can specify the mynetworks list by hand, 306in which case Postfix ignores the mynetworks_style setting. 307To specify the list of trusted networks by hand, specify network 308blocks in CIDR (network/mask) notation, for example: </p> 309 310<blockquote> 311<pre> 312/etc/postfix/main.cf: 313 mynetworks = 168.100.189.0/28, 127.0.0.0/8 314</pre> 315</blockquote> 316 317<p> You can also specify the absolute pathname of a pattern file instead 318of listing the patterns in the main.cf file. </p> 319 320<h2> <a name="relay_to"> What destinations to relay mail to </a> </h2> 321 322<p> By default, Postfix will forward mail from strangers (clients outside 323authorized networks) to authorized remote destinations only. 324Authorized remote 325destinations are defined with the relay_domains configuration 326parameter. The default is to authorize all domains (and subdomains) 327of the domains listed with the mydestination parameter. </p> 328 329<p> Examples (specify only one of the following): </p> 330 331<blockquote> 332<pre> 333/etc/postfix/main.cf: 334 relay_domains = $mydestination (default) 335 relay_domains = (safe: never forward mail from strangers) 336 relay_domains = $mydomain (forward mail to my domain and subdomains) 337</pre> 338</blockquote> 339 340<h2> <a name="relayhost"> What delivery method: direct or 341indirect </a> </h2> 342 343<p> By default, Postfix tries to deliver mail directly to the 344Internet. Depending on your local conditions this may not be possible 345or desirable. For example, your system may be turned off outside 346office hours, it may be behind a firewall, or it may be connected 347via a provider who does not allow direct mail to the Internet. In 348those cases you need to configure Postfix to deliver mail indirectly 349via a relay host. </p> 350 351<p> Examples (specify only one of the following): </p> 352 353<blockquote> 354<pre> 355/etc/postfix/main.cf: 356 relayhost = (default: direct delivery to Internet) 357 relayhost = $mydomain (deliver via local mailhub) 358 relayhost = [mail.$mydomain] (deliver via local mailhub) 359 relayhost = [mail.isp.tld] (deliver via provider mailhub) 360</pre> 361</blockquote> 362 363<p> The form enclosed with <tt>[]</tt> eliminates DNS MX lookups. 364Don't worry if you don't know what that means. Just be sure to 365specify the <tt>[]</tt> around the mailhub hostname that your ISP 366gave to you, otherwise mail may be mis-delivered. </p> 367 368<p> The STANDARD_CONFIGURATION_README file has more hints and tips 369for firewalled and/or dial-up networks. </p> 370 371<h2> <a name="notify"> What trouble to report to the postmaster</a> </h2> 372 373<p> You should set up a postmaster alias in the aliases(5) table 374that directs mail to a human person. The postmaster address is 375required to exist, so that people can report mail delivery problems. 376While you're updating the aliases(5) table, be sure to direct mail 377for the super-user to a human person too. </p> 378 379<blockquote> 380<pre> 381/etc/aliases: 382 postmaster: you 383 root: you 384</pre> 385</blockquote> 386 387<p> Execute the command "newaliases" after changing the aliases 388file. Instead of /etc/aliases, your alias file may be located 389elsewhere. Use the command "postconf alias_maps" to find out.</p> 390 391<p> The Postfix system reports problems to the postmaster alias. 392You may not be interested in all types of trouble reports, so this 393reporting mechanism is configurable. The default is to report only 394serious problems (resource, software) to postmaster: </p> 395 396<p> Default setting: </p> 397 398<blockquote> 399<pre> 400/etc/postfix/main.cf: 401 notify_classes = resource, software 402</pre> 403</blockquote> 404 405<p> The meaning of the classes is as follows: </p> 406 407<blockquote> 408 409<dl> 410 411<dt> bounce </dt> <dd> Inform the postmaster of undeliverable 412mail. Either send the postmaster a copy of undeliverable mail that 413is returned to the sender, or send a transcript of the SMTP session 414when Postfix rejected mail. For privacy reasons, the postmaster 415copy of undeliverable mail is truncated after the original message 416headers. This implies "2bounce" (see below). See also the 417luser_relay feature. The notification is sent to the address 418specified with the bounce_notice_recipient configuration parameter 419(default: postmaster). </dd> 420 421<dt> 2bounce </dt> <dd> When Postfix is unable to return undeliverable 422mail to the sender, send it to the postmaster instead (without 423truncating the message after the primary headers). The notification 424is sent to the address specified with the 2bounce_notice_recipient 425configuration parameter (default: postmaster). </dd> 426 427<dt> delay </dt> <dd> Inform the postmaster of delayed mail. In 428this case, the postmaster receives message headers only. The 429notification is sent to the address specified with the 430delay_notice_recipient configuration parameter (default: postmaster). 431</dd> 432 433<dt> policy </dt> <dd> Inform the postmaster of client requests 434that were rejected because of (UCE) policy restrictions. The 435postmaster receives a transcript of the SMTP session. The notification 436is sent to the address specified with the error_notice_recipient 437configuration parameter (default: postmaster). </dd> 438 439<dt> protocol </dt> <dd> Inform the postmaster of protocol errors 440(client or server side) or attempts by a client to execute 441unimplemented commands. The postmaster receives a transcript of 442the SMTP session. The notification is sent to the address specified 443with the error_notice_recipient configuration parameter (default: 444postmaster). </dd> 445 446<dt> resource </dt> <dd> Inform the postmaster of mail not delivered 447due to resource problems (for example, queue file write errors). 448The notification is sent to the address specified with the 449error_notice_recipient configuration parameter (default: postmaster). 450</dd> 451 452<dt> software </dt> <dd> Inform the postmaster of mail not delivered 453due to software problems. The notification is sent to the address 454specified with the error_notice_recipient configuration parameter 455(default: postmaster). </dd> 456 457</dl> 458 459</blockquote> 460 461<h2><a name="proxy_interfaces"> Proxy/NAT external network 462addresses</a> </h2> 463 464<p> Some mail servers are connected to the Internet via a network 465address translator (NAT) or proxy. This means that systems on the 466Internet connect to the address of the NAT or proxy, instead of 467connecting to the network address of the mail server. The NAT or 468proxy forwards the connection to the network address of the mail 469server, but Postfix does not know this. </p> 470 471<p> If you run a Postfix server behind a proxy or NAT, you need to 472configure the proxy_interfaces parameter and specify all the external 473proxy or NAT addresses that Postfix receives mail on. You may 474specify symbolic hostnames instead of network addresses. </p> 475 476<p> IMPORTANT: You must specify your proxy/NAT external addresses 477when your system is a backup MX host for other domains, otherwise 478mail delivery loops will happen when the primary MX host is down. 479</p> 480 481<p> Example: host behind NAT box running a backup MX host. </p> 482 483<blockquote> 484<pre> 485/etc/postfix/main.cf: 486 proxy_interfaces = 1.2.3.4 (the proxy/NAT external network address) 487</pre> 488</blockquote> 489 490<h2> <a name="syslog_howto"> What you need to know about 491Postfix logging </a> </h2> 492 493<p> Postfix daemon processes run in the background, and log problems 494and normal activity to the syslog daemon. The syslogd process sorts 495events by class and severity, and appends them to logfiles. The 496logging classes, levels and logfile names are usually specified in 497/etc/syslog.conf. At the very least you need something like: </p> 498 499<blockquote> 500<pre> 501/etc/syslog.conf: 502 mail.err /dev/console 503 mail.debug /var/log/maillog 504</pre> 505</blockquote> 506 507<p> After changing the syslog.conf file, send a "HUP" signal to 508the syslogd process. </p> 509 510<p> IMPORTANT: many syslogd implementations will not create files. 511You must create files before (re)starting syslogd. </p> 512 513<p> IMPORTANT: on Linux you need to put a "-" character before the 514pathname, e.g., -/var/log/maillog, otherwise the syslogd process 515will use more system resources than Postfix. </p> 516 517<p> Hopefully, the number of problems will be small, but it is a good 518idea to run every night before the syslog files are rotated: </p> 519 520<blockquote> 521<pre> 522# postfix check 523# egrep '(reject|warning|error|fatal|panic):' /some/log/file 524</pre> 525</blockquote> 526 527<ul> 528 529<li> <p> The first line (postfix check) causes Postfix to report 530file permission/ownership discrepancies. </p> 531 532<li> <p> The second line looks for problem reports from the mail 533software, and reports how effective the relay and junk mail access 534blocks are. This may produce a lot of output. You will want to 535apply some postprocessing to eliminate uninteresting information. 536</p> 537 538</ul> 539 540<p> The <a href="DEBUG_README.html#logging"> DEBUG_README </a> 541document describes the meaning of the "warning" etc. labels in 542Postfix logging. </p> 543 544<h2> <a name="chroot_setup"> Running Postfix daemon processes 545chrooted </a> </h2> 546 547<p> Postfix daemon processes can be configured (via the master.cf 548file) to run in a chroot jail. The processes run at a fixed low 549privilege and with file system access limited to the Postfix queue 550directories (/var/spool/postfix). This provides a significant 551barrier against intrusion. The barrier is not impenetrable (chroot 552limits file system access only), but every little bit helps.</p> 553 554<p>With the exception of Postfix daemons that deliver mail locally 555and/or that execute non-Postfix commands, every Postfix daemon can 556run chrooted.</p> 557 558<p>Sites with high security requirements should consider to chroot 559all daemons that talk to the network: the smtp(8) and smtpd(8) 560processes, and perhaps also the lmtp(8) client. The author's own 561porcupine.org mail server runs all daemons chrooted that can be 562chrooted. </p> 563 564<p>The default /etc/postfix/master.cf file specifies that no Postfix 565daemon runs chrooted. In order to enable chroot operation, edit 566the file /etc/postfix/master.cf, and follow instructions in the 567file. When you're finished, execute "postfix reload" to make the 568change effective. </p> 569 570<p>Note that a chrooted daemon resolves all filenames relative to 571the Postfix queue directory (/var/spool/postfix). For successful 572use of a chroot jail, most UNIX systems require you to bring in 573some files or device nodes. The examples/chroot-setup directory in 574the source code distribution has a collection of scripts that help 575you set up Postfix chroot environments on different operating 576systems.</p> 577 578<p> Additionally, you almost certainly need to configure syslogd 579so that it listens on a socket inside the Postfix queue directory. 580Examples of syslogd command line options that achieve this for 581specific systems: </p> 582 583<p> FreeBSD: <tt>syslogd -l /var/spool/postfix/var/run/log</tt> </p> 584 585<p> Linux, OpenBSD: <tt>syslogd -a /var/spool/postfix/dev/log</tt> </p> 586 587<h2><a name="myhostname"> My own hostname </a> </h2> 588 589<p> The myhostname parameter specifies the fully-qualified domain 590name of the machine running the Postfix system. $myhostname 591appears as the default value in many other Postfix configuration 592parameters. </p> 593 594<p> By default, myhostname is set to the local machine name. If 595your local machine name is not in fully-qualified domain name form, 596or if you run Postfix on a virtual interface, you will have to 597specify the fully-qualified domain name that the mail system should 598use. </p> 599 600<p> Alternatively, if you specify mydomain in main.cf, then Postfix 601will use its value to generate a fully-qualified default value 602for the myhostname parameter. </p> 603 604<p> Examples (specify only one of the following): </p> 605 606<blockquote> 607<pre> 608/etc/postfix/main.cf: 609 myhostname = host.local.domain (machine name is not FQDN) 610 myhostname = host.virtual.domain (virtual interface) 611 myhostname = virtual.domain (virtual interface) 612</pre> 613</blockquote> 614 615<h2><a name="mydomain"> My own domain name</a> </h2> 616 617<p> The mydomain parameter specifies the parent domain of 618$myhostname. By default, it is derived from $myhostname 619by stripping off the first part (unless the result would be a 620top-level domain). </p> 621 622<p> Conversely, if you specify mydomain in main.cf, then Postfix 623will use its value to generate a fully-qualified default value 624for the myhostname parameter. </p> 625 626<p> Examples (specify only one of the following): </p> 627 628<blockquote> 629<pre> 630/etc/postfix/main.cf: 631 mydomain = local.domain 632 mydomain = virtual.domain (virtual interface) 633</pre> 634</blockquote> 635 636<h2><a name="inet_interfaces">My own network addresses</a> </h2> 637 638<p>The inet_interfaces parameter specifies all network interface 639addresses that the Postfix system should listen on; mail addressed 640to "user@[network address]" will be delivered locally, 641as if it is addressed to a domain listed in $mydestination.</p> 642 643<p> You can override the inet_interfaces setting in the Postfix 644master.cf file by prepending an IP address to a server name. </p> 645 646<p> The default is to listen on all active interfaces. If you run 647mailers on virtual interfaces, you will have to specify what 648interfaces to listen on. </p> 649 650<p> IMPORTANT: If you run MTAs on virtual interfaces you must 651specify explicit inet_interfaces values for the MTA that receives 652mail for the machine itself: this MTA should never listen on the 653virtual interfaces or you would have a mailer loop when a virtual 654MTA is down. </p> 655 656<p> Example: default setting. </p> 657 658<blockquote> 659<pre> 660/etc/postfix/main.cf: 661 inet_interfaces = all 662</pre> 663</blockquote> 664 665<p> Example: host running one or more virtual mailers. For 666each Postfix instance, specify only one of the following. </p> 667 668<blockquote> 669<pre> 670/etc/postfix/main.cf: 671 inet_interfaces = virtual.host.tld (virtual Postfix) 672 inet_interfaces = $myhostname localhost... (non-virtual Postfix) 673</pre> 674</blockquote> 675 676<p> Note: you need to stop and start Postfix after changing this 677parameter. </p> 678 679</body> 680 681</html> 682