Using iptables
sudo iptables -L
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
sudo iptables -A INPUT -s ###.###.###.### -p tcp --dport www -j ACCEPT
sudo iptables -P INPUT DROP
sudo iptables -L -v
sudo sh -c "iptables-save > /etc/iptables.rules"
sudo nano /etc/network/interfaces
Append the following to appropriate interface(s):
pre-up iptables-restore < /etc/iptables.rules
post-down iptables-restore < /etc/iptables.rules
Reference:
http://iptables-tutorial.frozentux.net/iptables-tutorial.html
http://www.frozentux.net/iptables-tutorial/iptables-tutorial.html [EDIT: 20110514]
https://help.ubuntu.com/community/IptablesHowTo