Configure qmail tcpserver to Run smtpd on More Than One Address

The short answer is that you cannot set up tcpserver to run on more than one address, unless it’s going to run on all addresses. To run qmail-smtpd on two addresses, you need to run two copies of qmail-smtpd.

I needed to run one copy on the public IP address, and one copy for localhost.

(The reason for this change was to test-flight another email server that wanted to bind to port 25 on a specific address. The normal qmail configuration binds qmail-smtpd to all addresses.)

Doing this is pretty easy. On Ubuntu 18.04, the service control directories are in /etc/qmail.

sudo -s
cd /etc/qmail
svc -d qmail-smtpd
cp -ar qmail-smtpd-localhost
# edit qmail-smtpd-localhost/run and change the 0 argument to tcpserver 127.0.0.1
rm qmail-stmpd-localhost/supervise
cd /etc/service
ln -s /etc/qmail/qmail-smtpd-localhost .
svc -u qmail-smtpd

The code in run is like:

#!/bin/sh
QMAILDUID=id -u qmaild
NOFILESGID=id -g qmaild
MAXSMTPD=cat /var/lib/qmail/control/concurrencyincoming
LOCAL=head -1 /var/lib/qmail/control/me
MAILSERVERIP=127.0.0.1
 
if [ -z "$QMAILDUID" -o -z "$NOFILESGID" -o -z "$MAXSMTPD" -o -z "$LOCAL" ]; then
     echo QMAILDUID, NOFILESGID, MAXSMTPD, or LOCAL is unset in
     echo /var/qmail/supervise/qmail-smtpd-localhost/run
     exit 1
 fi
 if [ ! -f /var/lib/qmail/control/rcpthosts ]; then
     echo "No /var/lib/qmail/control/rcpthosts!"
     echo "Refusing to start SMTP listener because it'll create an open relay"
     exit 1
 fi
 exec softlimit -m 90000000 \
     tcpserver -v -R -l "$LOCAL" -x /etc/qmail/tcp.smtp.cdb -c "$MAXSMTPD" \
         -u "$QMAILDUID" -g "$NOFILESGID" $MAILSERVERIP smtp qmail-smtpd 2>&1

References

Setup Qmail to Listen to Port 587

How do I run Qmail on port 587?