Skip to main content

Setting up mail server on Rackspace cloud server

Posted in

For a couple of projects lately, I've had to set up a Rackspace cloud server with enough email capacity to send emails and to receive them to be processed by a script. Here are the steps I've followed:

  • Edited /etc/aliases to include the new email address, piped to the script that will process the emails, then run newaliases to load these aliases.
  • Ran hostname "[new-hostname]", which should change the setting without requiring a restart.
  • Installed postfix with yum install postfix, and ran chkconfig postfix on so that the process starts (and restarts on reboot).
  • Also installed telnet and mailx for testing tools.
  • Edit settings in /etc/postfix/main.cf and then restart postfix with /etc/init.d/postfix restart
    • myhostname
    • mydomain
    • inet_interfaces = all

Testing tools

Send a test message from the command line

  1. mail address@example.com
  2. Subject: test email from democloud.com
  3. test body of the email.
  4. .
  5. Cc:

Connect to the mail server using telnet

  1. telnet 127.0.0.1 25

Iptables

In order to have the right ports open, here are the iptables commands that I used:

  1. iptables -A INPUT -i lo -j ACCEPT
  2. iptables -A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT
  3. iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  4. iptables -A OUTPUT -j ACCEPT
  5. iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  6. iptables -A INPUT -p tcp --dport 443 -j ACCEPT
  7. iptables -A INPUT -p tcp --dport 25 -j ACCEPT
  8. iptables -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
  9. iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
  10. iptables -A INPUT -j REJECT
  11. iptables -A FORWARD -j REJECT

After verifying that this worked, I saved the iptables settings so they'd run on restart: /etc/init.d/iptables save.