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