LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 08-16-2006, 08:11 PM   #1
sbabcock23
Member
 
Registered: Aug 2006
Location: Mississauga, Ontario, Canada
Distribution: RHEL 5, CentOS 5
Posts: 64

Rep: Reputation: 15
Multiple domains for Postfix


Hi everyone,

Another question. Say I have x.domain.com and y.domain.com and want to setup postfix to accept and send mail for both those domains. Both domains have the same ip address by the way. Do I have to create a virtual domain? I currently have x.domain.com setup correctly and everything is working fine. Now I want to create a new user who has user@y.domain.com, is this possible? Are there any good tutorials on how to do this?

Thanks,
Steve
 
Old 08-17-2006, 03:03 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
normally you'd just use the virtual_alias_domains variable to the additional domains you want. that would then deliver bob@y.domain.com to the same destination as bob@x.domain.com. if you need to be more specific than that you'd be looking ath a virtual_alias_map file.
 
Old 08-17-2006, 10:55 AM   #3
Child of Wonder
Member
 
Registered: Jul 2004
Location: Sioux Falls, SD
Distribution: Debian, Ubuntu, Fedora, Red Hat
Posts: 69

Rep: Reputation: 16
Virtual alias domains works OK if you want all your email going to local user mailboxes. That means user1@x.domain.com and user1@y.domain.com are each going to have different Linux user accounts since they both can't have user1. This can be confusing to users and is harder to manage.

If you want each user1@x.domain.com and user1@y.domain.com account to have it's own mailbox but not a Linux user account, you need virtual mailboxes. This is how I do it on my Ubuntu Postfix box at home.

**Make sure to back up your config files before making any changes!**

First make sure Postfix has the virtual module available to use. Look for the virtual line in /etc/postfix/master.cf. If it's there (which it should) continue.

Create an account that will have access to the virtual mailboxes directory and one for each domain to write to them.

Code:
useradd vuser -u 2000  (or any uid you want above 1000)
groupadd vuser -g 2000  (same as uid)
useradd xdomain -u 2001  
groupadd xdomain -g 2001  
useradd ydomain -u 2002
groupadd ydomain -g 2002
Then create the base directory for your virtual mailboxes.

Code:
mkdir /var/spool/virtual_mailboxes
chown vuser:vuser /var/spool/virtual_mailboxes
chmod 755 /var/spool/virtual_mailboxes
Next, create the subdirectories.

Code:
mkdir /var/spool/virtual_mailboxes/x.domain.com
mkdir /var/spool/virtual_mailboxes/y.domain.com
chown xdomain /var/spool/virtual_mailboxes/x.domain.com/
chown ydomain /var/spool/virtual_mailboxes/y.domain.com/
chgrp xdomain /var/spool/virtual_mailboxes/x.domain.com/
chgrp ydomain /var/spool/virtual_mailboxes/y.domain.com/
chmod 700 /var/spool/virtual_mailboxes/x.domain.com/
chmod 700 /var/spool/virtual_mailboxes/y.domain.com/
Next you need to build a file that you can enter all your email addresses into. Call it /etc/postfix/virtual_build_map_source.

Code:
user1@x.domain.com            x.domain.com/user1/           2001    2001
user2@x.domain.com            x.domain.com/user2/           2001    2001
user1@y.domain.com            y.domain.com/user1/           2002    2002
user2@y.domain.com            y.domain.com/user2/           2002    2002
Then create a script to take that virtual_build_map_source file and create all the other needed files that Postfix will need. Call it /etc/postfix/build_virtual_maps.sh.

Code:
# !/bin/bash
#
# Build all virtual mailbox maps from one source

# section: paths
SOURCE=/etc/postfix/virtual_build_map_source
VMAP=/etc/postfix/virtual_mailbox_recipients
VUID=/etc/postfix/virtual_uid_map
VGID=/etc/postfix/virtual_gid_map
AWK=/usr/bin/awk
POSTMAP=/usr/sbin/postmap

# section: build
# build $virtual_mailbox_maps
$AWK '{printf("%s %s\n",$1,$2)}' $SOURCE > $VMAP
$POSTMAP hash:$VMAP

# build $virtual_uid_maps
$AWK '{printf("%s %s\n",$1,$3)}' $SOURCE > $VUID
$POSTMAP hash:$VUID

# build $virtual_gid_maps
$AWK '{printf("%s %s\n",$1,$4)}' $SOURCE > $VGID
$POSTMAP hash:$VGID
Make the file executable.

Code:
chmod 755 /etc/postfix/build_virtual_maps.sh
Then run the script and it will create the virtual_uid_map, virtual_gid_map, virtual_mailbox_recipients files and postmap them. You should also create a virtual_aliases file for any aliases you want set up. The aliases format is simple. Just write the incoming address, a space, and what address you want it to go to. Then postmap it.

Code:
user1@x.domain.com user2@y.domain.com
Go into main.cf and add the following lines:

Code:
## Virtual Mailboxes
virtual_mailbox_domains = x.domain.com, y.domain.com
virtual_uid_maps = hash:/etc/postfix/virtual_uid_map
virtual_gid_maps = hash:/etc/postfix/virtual_gid_map
virtual_mailbox_base = /var/spool/virtual_mailboxes
virtual_mailbox_maps = hash:/etc/postfix/virtual_mailbox_recipients
virtual_alias_maps = hash:/etc/postfix/virtual_aliases
DO NOT PUT YOUR VIRTUAL DOMAINS IN "mydestination=" OR POSTFIX WILL TRY TO DELIVER THOSE DOMAINS LOCALLY!

Postfix will now start delivering all incoming mail to those virtual mailboxes. The next step would be to set up your POP3 or IMAP server to allow users to get those emails. I use dovecot-pop3 and dovecot-imap.

/etc/dovecot/dovecot.conf

Code:
base_dir = /var/run/dovecot/
protocols = imap pop3
log_path = /var/log/dovecot
info_log_path = /var/log/dovecot.info
login_dir = /var/run/dovecot/login
login_chroot = yes
login_user = dovecot
protocol imap {
  login_executable = /usr/lib/dovecot/imap-login
  mail_executable = /usr/lib/dovecot/imap
}
protocol pop3 {
   login_executable = /usr/lib/dovecot/pop3-login
   mail_executable = /usr/lib/dovecot/pop3
   pop3_uidl_format =  %08Xu%08Xv
}
valid_chroot_dirs = /var/spool/virtual_mailboxes
default_mail_env = maildir:/var/spool/virtual_mailboxes/%d/%n
disable_plaintext_auth = no
auth default {
   mechanisms = plain digest-md5
   userdb passwd-file {
      args = /etc/dovecot/users
   }
   passdb passwd-file {
     args = /etc/dovecot/passwd
   }
}
auth_executable = /usr/lib/dovecot/dovecot-auth
auth_user = root
auth_verbose = yes
Create /etc/dovecot/users and include all your users in there in the following format:

Code:
user1@x.domain.com::2001:2001::/var/spool/virtual_mailboxes/x.domain.com/:/bin/false::
user2@x.domain.com::2001:2001::/var/spool/virtual_mailboxes/x.domain.com/:/bin/false::
user1@y.domain.com::2002:2002::/var/spool/virtual_mailboxes/y.domain.com/:/bin/false::
user2@y.domain.com::2002:2002::/var/spool/virtual_mailboxes/y.domain.com/:/bin/false::
Make the file only usable by root and readable by root group.

Code:
chmod 740 /etc/dovecot/users
Create the following script and put it into /usr/sbin/mkdovecotpasswd.

Code:
#!/bin/bash
mkpasswd --hash=md5 $2  > /tmp/hash
echo "$1:`cat /tmp/hash`" >> /etc/dovecot/passwd
Make it executable.

Code:
chmod 755 /usr/sbin/mkdovecotpasswd
Make your Dovecot password file and give it only root rights.

Code:
touch /etc/dovecot/passwd
chmod 740 /etc/dovecot/passwd
Now you need to assign passwords for your users. Run your new script in this format:

Code:
mkdovecotpasswd user1@x.domain.com password
Do this for every user you have. If you ever need to change a password, just delete the corresponding line in /etc/dovecot/passwd and run the command again with the new password.

To add a new user, add them to the /etc/virtual_build_map_source file, run /etc/postfix/build_virtual_maps.sh, add them to /etc/dovecot/users, and run the mkdovecotpasswd command to assign them a password. All your users can now retrieve mail via POP3 and IMAP (assuming your box is set to accept ports 110, 143, and 25 and/or have them forwarded from your router to your server) and users will be using their full email address as their username.

Restart Postfix and dovecot and you should be good.

Last edited by Child of Wonder; 08-17-2006 at 11:11 AM.
 
Old 12-12-2006, 12:06 AM   #4
gcrumb
LQ Newbie
 
Registered: Dec 2006
Posts: 1

Rep: Reputation: 0
One small detail....

Thanks for the detailed reply. It was invaluable.

Just one little detail:

I followed these steps to the letter and found that my postfix server was bouncing email to valid virtual user accounts. A bit of research determined that the problem was that I hadn't included the 'virtual_transport = virtual' parameter in /etc/postfix/main.cf.

After adding that, everything worked fine.

P.S. I was inspired by your script, and re-wrote the whole thing in perl and in a somewhat more comprehensive format. I'll post it here as soon as I have the pod documentation completed.....
 
Old 12-12-2006, 12:26 AM   #5
gani
Member
 
Registered: Jun 2004
Location: Metro Manila, Philippines
Distribution: OpenBSD, Slackware, XP
Posts: 347

Rep: Reputation: 31
This one, if you are interested on trying, it uses MySQL in setting virtual domains/hosting. This is the tutorial I followed and my Slack-based postfix server based on.

http://www.postfixvirtual.net/postfixconf.html

---------
GANI
 
Old 12-12-2006, 09:37 AM   #6
Child of Wonder
Member
 
Registered: Jul 2004
Location: Sioux Falls, SD
Distribution: Debian, Ubuntu, Fedora, Red Hat
Posts: 69

Rep: Reputation: 16
I'm glad I could help. I got most of my info from "The Book of Postfix" by Ralf Hildebrandt and Patrick Koetter. AWESOME BOOK!

My next task is to set up Postfix and LDAP. We have it running where I work but I'd like to try it on my own.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make postfix accept mail from multiple domains Farthom Linux - Newbie 4 09-14-2006 11:13 AM
Postfix - how do hosted domains download their mail from my postfix franschoek Linux - Software 1 04-01-2006 09:41 PM
Postfix multiple domains & mailboxes fatum112 Linux - Software 0 11-21-2005 01:13 PM
managing different domains with postfix jules_fraser Linux - Networking 1 12-22-2003 11:07 PM
Postfix and multiple domains MasterC Linux - Networking 4 07-16-2003 01:19 PM


All times are GMT -5. The time now is 02:48 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration