Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

I want to block some hosts in Ubuntu, so how could I edit hosts.deny file to block some hosts like

And one more thing I have installed dnsmasq in Ubuntu, so can I check the entries of the dns's cached by dnsmasq? If yes then how?

Thanks in advance.

share|improve this question

3 Answers 3

up vote 8 down vote accepted

hosts.deny example:


This denies all service to and For further information, take a look here:

dnsmasq -d should give you the cached entries but I'm not so sure about that.


To block an IP Address with iptables:

iptables -A INPUT -s -j DROP

to unblock:

iptables -D INPUT -s -j DROP
share|improve this answer
dnsmasq -d :-> dnsmasq: failed to create listening socket: Address already in use –  codeomnitrix Jan 25 '11 at 6:46
nd i have done ALL: in hosts.deny file. But still this page is getting loaded in my browser. –  codeomnitrix Jan 25 '11 at 6:48
Hosts.deny blocks those IPs accessing services on your computer but you are accessing their server. You could use iptables or edit your /etc/hosts like this: –  Dayjay Jan 25 '11 at 7:00
then how to block the my computer user to access that server? –  codeomnitrix Jan 25 '11 at 7:04
hey can you please explain a bit more how to do that –  codeomnitrix Jan 25 '11 at 7:08

hosts.allow and hosts.deny are deprecated. They are used by TCP Wrappers, host-based access control,

If you want to block access to a service, you need to find whether that service has been compiled with TCP Wrappers. I highly doubt that Ubuntu services still use TCP Wrappers.

The TCP Wrappers library is found in /lib/ If you want to check whether lighttpd (Web server) supports TCP Wrappers, run

> ldd /usr/sbin/lighttpd =>  (0x00007fff2a5ff000) => /lib/ (0x00007f69af837000) => /lib/ (0x00007f69af633000) => /lib/ (0x00007f69af42d000) => /lib/ (0x00007f69af1db000) => /lib/ (0x00007f69aee4b000) => /usr/lib/ (0x00007f69aec42000) => /lib/ (0x00007f69ae8bf000)
    /lib64/ (0x00007f69afa90000) => /lib/ (0x00007f69ae6a8000)
> _

It does not mention libwrap, so at least this service does not support TCP Wrappers, and will ignore /etc/hosts.{allow, deny}.

share|improve this answer
If tcp wrappers are depreciated, what's the replacement? –  zaius Dec 13 '11 at 22:13

You want to use a firewall to block access to other sites. I believe ufw is intalled by default. The command man ufw should provide information on how to use it. Replace with the address you want to block.

The commands

sudo ufw enable
sudo ufw deny to
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.