Eric's Simple qmail Setup

November 15, 2001

This is a simple, step-by-step set of instructions for setting up qmail to run as a relay box. It assumes you want to use ucspi and daemontools.

This will assume you will want to use the "standard" directories. God help you if you want to go against djb.

daemontools

The first step is to install daemontools.
  1. cd /var/tmp
  2. fetch http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
  3. tar -xzf daemontools-0.76.tar.gz
  4. cd admin/daemontools-0.76
  5. package/install
  6. reboot

ucspi

The second step is to install ucspi.
  1. cd /var/tmp
  2. fetch http://cr.yp.to/ucspi-tcp/ucspi-tcp-0.88.tar.gz
  3. tar -xzf ucspi-tcp-0.88.tar.gz
  4. cd ucspi-tcp-0.88
  5. make
  6. make setup check

qmail

The third step is to install qmail.
  1. cd /var/tmp
  2. fetch http://cr.yp.to/software/qmail-1.03.tar.gz
  3. tar -xzf qmail-1.03.tar.gz
  4. cd qmail-1.03
  5. mkdir /var/qmail
  6. Add the qmail users.
    Linux
    groupadd nofiles
    useradd -g nofiles -d /var/qmail/alias alias
    useradd -g nofiles -d /var/qmail qmaild
    useradd -g nofiles -d /var/qmail qmaill
    useradd -g nofiles -d /var/qmail qmailp
    groupadd qmail
    useradd -g qmail -d /var/qmail qmailq
    useradd -g qmail -d /var/qmail qmailr
    useradd -g qmail -d /var/qmail qmails
    
    FreeBSD
    pw groupadd nofiles
    pw useradd alias -g nofiles -d /var/qmail/alias -s /nonexistent
    pw useradd qmaild -g nofiles -d /var/qmail -s /nonexistent
    pw useradd qmaill -g nofiles -d /var/qmail -s /nonexistent
    pw useradd qmailp -g nofiles -d /var/qmail -s /nonexistent
    pw groupadd qmail
    pw useradd qmailq -g qmail -d /var/qmail -s /nonexistent
    pw useradd qmailr -g qmail -d /var/qmail -s /nonexistent
    pw useradd qmails -g qmail -d /var/qmail -s /nonexistent
    
    BSDI 2.0
    addgroup nofiles
    adduser -g nofiles -H/var/qmail/alias -G,,, -s/dev/null -P'*' alias
    adduser -g nofiles -H/var/qmail -G,,, -s/dev/null -P'*' qmaild
    adduser -g nofiles -H/var/qmail -G,,, -s/dev/null -P'*' qmaill
    adduser -g nofiles -H/var/qmail -G,,, -s/dev/null -P'*' qmailp
    addgroup qmail
    adduser -g qmail -H/var/qmail -G,,, -s/dev/null -P'*' qmailq
    adduser -g qmail -H/var/qmail -G,,, -s/dev/null -P'*' qmailr
    adduser -g qmail -H/var/qmail -G,,, -s/dev/null -P'*' qmails
    
    AIX
    mkgroup -A nofiles
    mkuser pgrp=nofiles home=/var/qmail/alias shell=/bin/true alias
    mkuser pgrp=nofiles home=/var/qmail shell=/bin/true qmaild
    mkuser pgrp=nofiles home=/var/qmail shell=/bin/true qmaill
    mkuser pgrp=nofiles home=/var/qmail shell=/bin/true qmailp
    mkgroup -A qmail
    mkuser pgrp=qmail home=/var/qmail shell=/bin/true qmailq
    mkuser pgrp=qmail home=/var/qmail shell=/bin/true qmailr
    mkuser pgrp=qmail home=/var/qmail shell=/bin/true qmails
    
  7. make setup check
  8. mkdir /var/log/qmail
  9. chown qmaill /var/log/qmail
  10. CSH users should type "rehash"
  11. ./config
  12. (cd ~alias; touch .qmail-postmaster .qmail-mailer-daemon .qmail-root)
  13. chmod 644 ~alias/.qmail*
  14. cd /var/qmail
  15. cat > rc <<EOF
    #!/bin/sh
    
    exec env - PATH="/var/qmail/bin:$PATH" \
    qmail-start ./Mailbox multilog t s2000000 /var/log/qmail
    EOF
    
  16. chmod a+x rc
  17. mkdir /service/qmail ; ln -s /var/qmail/rc /service/qmail/run
  18. cd /var/qmail/control
  19. Note: This will open relaying for everyone in the 10.x.x.x network. You can create a rules database however you desire. See http://cr.yp.to/ucspi-tcp/tcprules.html for more info.
    cat > tcp.smtp <<EOF
    10.:allow,RELAYCLIENT=""
    EOF
    
  20. tcprules tcp.smtp.cdb tcp.smtp.tmp < tcp.smtp
  21. mkdir /service/qmail-smtpd
  22. cd /service/qmail-smtpd
  23. Note: You must replace the "1234" in the script below with the actual user id form "qmaild" and the actual group id for "nofiles".
    cat > run <<EOF
    #!/bin/sh
    #
    # Qmail startup/shutdown script by Eric Huss
    #
    PATH=/var/qmail/bin:/usr/local/bin:$PATH export PATH
    QMAILDUID=1234
    NOFILESGID=1234
    
    ulimit -n 400
    exec tcpserver -R -x /var/qmail/control/tcp.smtp.cdb -u \$QMAILDUID -g \$NOFILESGID 0 smtp /var/qmail/bin/qmail-smtpd
    EOF
    
  24. chmod a+x run