Uncomplicate Firewall (ufw) Rules for LAMP in Ubuntu Server

-- 0. Check status
$ sudo ufw status 
Status: inactive

-- 1. Enable typical ports for SSH, HTTP(S)
$ sudo ufw allow ssh
$ sudo ufw allow http
$ sudo ufw allow https
$ sudo ufw allow mysql

-- 2. Enable the firewall
$ sudo ufw enable

-- 3. Don't like it, reset to default
$ sudo ufw reset ~
Resetting all rules to installed defaults. Proceed with operation (y|n)? y
Backing up 'user.rules' to '/lib/ufw/user.rules.20111029_214156'
Backing up 'after6.rules' to '/etc/ufw/after6.rules.20111029_214156'
Backing up 'user6.rules' to '/lib/ufw/user6.rules.20111029_214156'
Backing up 'before6.rules' to '/etc/ufw/before6.rules.20111029_214156'
Backing up 'after.rules' to '/etc/ufw/after.rules.20111029_214156'
Backing up 'before.rules' to '/etc/ufw/before.rules.20111029_214156'

Sending Email Through Console

$ echo "foobar" | mail -s "testing" [email protected]
The program 'mail' can be found in the following packages:
* heirloom-mailx
* mailutils
Try: apt-get install 

So, I was given two choices. Which one? I ended up picking mailutils because of dependency of Exim.
$ sudo -s
# sudo apt-get update; sudo apt-get upgrade;
# sudo apt-get install mailutils exim4-daemon-light
# dpkg-reconfigure exim4-config
- General type of mail configuration: internet site
- System mail name: foobar
- IP-addresses to listen on for incoming SMTP connections: 127.0.0.1 ; ::1
- Other destinations for which mail is accepted: foobar; localhost.localdomain; localhost
- Domains to relay mail for:
- Machines to relay mail for:
- Keep number of DNS-queries minimal (Dial-on-Demand) : 
- Delivery method for local mail: mbox format in /var/mail
- Split configuration into smaller files: 

To test.
$ exim -bt [email protected]

R: dnslookup for [email protected]
[email protected]
router = dnslookup, transport = remote_smtp
host mailinator.net [66.135.37.96] MX=10
$ echo "foobar" | mail -s "testing" [email protected]
$ sudo tail -f /var/log/exim4/mainlog

To use BCC or CC, you must install bsd-mailx package, the default GNU mailutils package does not support this.
$ sudo apt-get install bsd-mailx

Carbon Copy (CC).
$ echo "testing cc email" | mail -s "testing email cc" -c [email protected] [email protected]

Blind Carbon Copy (BCC).
$ echo "testing bcc email" | mail -s "testing email bcc" -b [email protected] [email protected]

Thanks to mailinator.com, you can check the email inbox at http://barfoo.mailinator.com and http://foobar.mailinator.com.

Send Email From Command Line

Occasionally during development, you'll need to send email to test out certain feature or cron job. Moreover, is nice to have this feature from the command line or console so you can debug and trace any issues.

$ echo "foobar" | mail -s "testing" [email protected]
The program 'mail' can be found in the following packages:
* heirloom-mailx
* mailutils
Try: apt-get install 

So, I was given two choices. Which one? I ended up picking GNU Mailutils because of dependency of Exim, which is known to be lightweight and easy to configure.
$ sudo -s
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install mailutils exim4-daemon-light
$ dpkg-reconfigure exim4-config

Exim mailer was configured using following settings.
  • General type of mail configuration: internet site
  • System mail name: foobar
  • IP-addresses to listen on for incoming SMTP connections: 127.0.0.1 ; ::1
  • Other destinations for which mail is accepted: foobar; localhost.localdomain; localhost
  • Domains to relay mail for:
  • Machines to relay mail for:
  • Keep number of DNS-queries minimal (Dial-on-Demand) : 
  • Delivery method for local mail: mbox format in /var/mail
  • Split configuration into smaller files: no

To check whether we've configure Exim correctly.
$ exim -bt [email protected]

R: dnslookup for [email protected]
[email protected]
router = dnslookup, transport = remote_smtp
host mailinator.net [66.135.37.96] MX=10

To send out a sample test email.
$ echo "foobar" | mail -s "testing" [email protected]
$ sudo tail -f /var/log/exim4/mainlog

However, GNU Mailutils does not support neither Bind Carbon Copy (BCC) nor Carbon Copy (CC). Hence, we've to install the bsd-mailx package.
$ sudo install apt-get install bsd-mailx

To send a Carbon Copy (CC) email.
$ echo "testing cc email" | mail -s "testing email cc" -c [email protected] [email protected]

To send a test Blind Carbon Copy (BCC) email.
$ echo "testing bcc email" | mail -s "testing email bcc" -b [email protected] [email protected]