From http://www.cnblogs.com/cnnbboy/archive/2009/02/08/1386280.html
UFW is the next Simple Firewall Configuration tool in Ubuntu. At the underlying layer, it still calls iptables for processing. Although its functions are simple, it is more practical for desktop applications and has basic common functions, it is easy to use.
1. Install
Sudo apt-Get install UFW
2. Enable
Sudo UFW enable
Sudo UFW default deny
After running the preceding two commands, the firewall is enabled and automatically enabled when the system starts.
Disable all external access to the local machine, but the local access to the external is normal.
3. enable/disable
Sudo UFW allow | deny [Service]
Open or close a port, for example:
Sudo UFW allow SMTP allows all external IP addresses to access the local port 25/tcp (SMTP ).
Sudo UFW allow 22/tcp allows all external IP addresses to access the local port 22/tcp (SSH)
Sudo UFW allow 53 allows external access to port 53 (TCP/UDP)
Sudo UFW allow from 192.168.1.100 allows this IP address to access all local ports
Sudo UFW allow proto UDP 192.168.0.1 port 53 to 192.168.0.2 port 53
Sudo UFW deny SMTP prohibit external access to the SMTP service
Sudo UFW Delete allow SMTP delete a rule created above
4. view the Firewall Status
Sudo UFW status
For general users, only the following settings are required:
Sudo apt-Get install UFW
Sudo UFW enable
Sudo default deny
The preceding three commands are safe enough. If you need to open some services, use sudo UFW allow.