SHARE
Facebook X Pinterest WhatsApp

Forwarding a Postfix Virtual Alias to /dev/null

Written By
thumbnail Juliet Kemp
Juliet Kemp
Sep 1, 2020
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

It’s poor practice to send out email from email addresses that don’t resolve, and may mean your mail ends up in a spamtrap. But sometimes you want to use a “do-not-reply” type of email address, and you don’t want to have to mass-delete the mailbox at intervals.

Tip of the Trade: Sometimes you want to use a “do-not-reply” type of email address and you don’t want to have to mass-delete the mailbox at intervals. Here’s an easy way to add a Postfix virtual alias to /dev/null.

The usual solution is to forward to /dev/null, and in a local-only setup you could do that in /etc/aliases:

do-not-reply: /dev/null

However, if you’re using Postfix virtual domains, it gets a little more complicated. With virtual domains/users, you can’t forward mail to a file. It must go to a user or an email address, like this:

juliet@example.com        juliet@example2.com

However, what you can do is set up an alias user in /etc/aliases:

devnull:	/dev/null

and then point to that in your virtual domain database file (which should be somewhere in /etc/postfix/virtual/, or it may be the /etc/postfix/virtualfile itself):

do-not-reply@example.com	devnull

After you’ve made the change, run postmap /etc/postfix/virtual/dbfileand reload Postfix. You can check if the alias is properly set up with the command:

postmap -q do-not-reply@example.com /etc/postfix/virtual/dbfile

You should see the correct alias returned.

One last gotcha: On some systems, the /etc/aliases change may not work unless that user (devnull) already exists on the system. You may well already have a nobody user in /etc/passwd (one with a nonexistent home directory and no login shell), which you can use in place of devnull in /etc/aliases; otherwise you can set up a devnull user to operate similarly.

Juliet Kemp has been messing around with Linux systems, for financial reward and otherwise, for about a decade. She is also the author of “Linux System Administration Recipes: A Problem-Solution Approach” (Apress, 2009).

Follow ServerWatch on Twitter

thumbnail Juliet Kemp

Juliet Kemp is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.