Personal Email Server with Ubuntu and Losing Network on Virtual Appliances
Yesterday, before leaving for work, I seriously FUBAR'ed my RSS reading email setup to the point where it wouldn't get past the "A's" in the feed list. Before that, a couple of weeks ago, I ended up with a huge regular email mess because:
- Some spammer used my email addresses as the "FROM" on a bunch of spam.
- A major bank in South Africa was the recipient of a LOT of those spam messages.
- Said bank decided to bounce each and every one of them to the "FROM" address: me.
- I only managed to get the sandbags in place after 31,000 of those bounced messages came through.
And, before that, I had my personal mail server needing to be reinstalled and messed with because the junk account to which all spam was directed reached a size that Mercury Mail couldn't handle. Finally, the Windows machine that is serving as my mail server (and a bunch of other uses) is going to be replaced as it moves into a role as a Call of Duty 2 server. I was really not looking forward to carrying the existing mail setup (the only thing on this machine that's problematic to move) into the new setup.
With all of that weighing heavily on the email portion of my geek setup, last night I decided to tackle something that's been on the TODO list for something like 3 years: a personal Linux email server to handle all of this crap in a more industrial approach. Further, I want all of this in a VMWare virtual appliance so I can easily back it up, move it between different hardware, take it with me on a portable drive, etc.
I've taken half-hearted stabs at this setup before, and stopped before any of it really worked, so I was deeply amazed when I was actually able to get to a basic functioning setup in a couple of hours last night. Here's the basic set of requirements I've got in order to call this thing "done".
- Server does not have a domain of its own.
- Fetches mail from an arbitrary number of POP3 mailboxes to appropriate user accounts.
- IMAP access to MailDir setup of those mailboxes.
- Outbound email sent via smarthost through outbound.mailhop.org.
- My entire chain of tools for RSS reading installed and routing feeds to one of the IMAP mail accounts.
- Spam and virus filtering (though I'm willing to let this slide until after migration if I can't do it the ideal way).
- Automatic cleanup and archiving of email.
- Access will be via SSH tunneled ports to localhost. All access will be "local".
Things I'd like to see, but don't need to happen before migrating off of the old setup.
- LDAP server for contacts.
- Whitelisting any email from someone in LDAP server.
- Procmail rules to enhance pre-processing of my email.
I've used literally a dozen or more different guides to set up email servers on Linux. And, without fail, until last night, they all broke down at some point. Most of them focused on how to set it up if you are setting up a "real" mail server, i.e. one that has a domain and sends and receives email for that domain. I'm not going to register a new domain just for this because it's for collecting the email I already get. In other cases, by the time I'd reached step 2 or 3 and the instructions said: "you should see XYZ at this point and that means it's working", I'd see nothing of the sort and there were no followup instructions on what to do if you didn't see what the tutorial mentioned.
This time around, I went with the instructions from Spencer Stirling. They worked, but not because they matched up exactly. It's just that where they didn't match my reality, they were either close enough or it didn't matter and it still worked anyway. I didn't do any of the security bits yet, but plan to put them in place where it makes sense for my setup.
So, what's working as of tonight (after the 2 hours last night and a bit of futzing this morning before work) is:
- Ubuntu Edgy Server in VMWare running and patched
- Exim4 running
- Fetchmail running
- Courier IMAP running
- Mutt is running and reading email
- Squirrelmail installed and working with IMAP
- LAMP stack installed for PHP tools for RSS
- PHP-CLI installed for commandline scripting of RSS tools
- Basic documentation page started in the server's web server for things I need to remember how to do down the road, like set up new users and links to the tutorials I used to set it up.
- Email from one of my legacy email addresses is getting fetched and delivered appropriately by fetchmail.
All in all, looking good. Well before the migration needs to happen, I'll be there for regular email and the RSS setup should be close behind.
That is, until I tried to run this virtual appliance on another computer. Suddenly, the only network interface available was the loopback to 127.0.0.1. While there truly is no place like home, I'm not thrilled when it's the only place you can go.
Turns out that, unlike Ubuntu Workstation, Ubuntu Server does this thing where, if it gets a new MAC address on a network card, it won't use it on the same network config. Since VMWare hands out new MAC addresses on the virtual network cards like candy, this is likely to be a huge problem for anyone who intends to use VMWare appliances on more than one machine.
After a lot of brow furrowing, I finally found a solution. This forum posting explains what exactly is going on (though from the perspective of a rare move between hosts).
Here's the script mentioned in the forum posting that "resets" the MAC address/networking when this happens. Put it in /usr/sbin/ under something like "fixmac" and make it executable (chmod +x fixmac). Then, when this happens, log in and run it as root and reboot. It will be back to normal.
mac=`ifconfig -a | grep "HWaddr" | cut -d " " -f 11`
echo "eth0 mac $mac arp 1" > /etc/iftab
This is still a pain though and I'm looking for a better option long term as I don't want to have to go through that every time I move it (which is likely to be more than once per day). At any rate, given the difficulty I had in finding the source of the problem, I thought I'd share what a fix is.



