In Ubuntu if you want to flush the DNS cache you need to install nscd daemon and restart it everytime when you want to flush the DNS
Installation instructions for nscd daemon:
type in a terminal window:
sudo aptitude install nscd
After installation you can flush the DNS cache by typing:
sudo /etc/init.d/nscd restart