How can I add static DNS entry in Debian and block some sites?

2

OK I'm admin noob.

Is there a way for adding static DNS entry?

I already tried to modify /etc/hosts file but without success.

Here is my hosts file:

127.0.0.1   localhost
127.0.1.1   hitsu
127.0.1.1   www.deviantart.com
127.0.1.1   deviantart.com
127.0.1.1   www.youtube.com
127.0.1.1   youtube.com

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Eveyrything is fine, but when I enter for example adc.deviantart.com I still get the page.

Is there a way to block that sites?

I am trying to increase productivity in work via disabling off-topic sites.

EDIT

Well I would like to block all sites from deviantart something like

127.0.0.1 *.deviantart.com

Browser add-ons/extensions are a good solutions, but I use multiple browsers (chrome, opera etc) so it will be probably easier to block this in linux.

EDIT #2

There are some solutions for this problem eg https://github.com/leftnode/get-shit-done

However it won't work for multidomains..

nothing-special-here

Posted 2013-05-14T07:56:30.517

Reputation: 605

You could setup dnsmasq with some overrides, or configure a proxy like squid (in which you could even make non-productivity sites blocking time-dependent) – Wrikken – 2013-05-14T19:37:30.847

Answers

1

You cannot use wildcards in /etc/hosts. You will need to add every subhost separately.

Tell us more about the problem. Do you want to block traffic originating from your machine only, from the whole network? Only WWW traffic?

If you want to block all traffic to deviantart:

 host deviantart.com gives 199.15.160.100

 iptables -A OUTPUT -d 199.15.160.100 -j DROP

This will DROP all packages going to deviantart.com. This IP can change of course but you can check it periodically. If you want this to be persistent you would probably need to add this line to some /etc/rc.local script or appropriate for your distro.

Darek

Posted 2013-05-14T07:56:30.517

Reputation: 886

I want to block specific traffic only for my machine. – nothing-special-here – 2013-05-14T08:29:55.090

So you can add all subdomains to /etc/hosts or use iptables like in my eidt – Darek – 2013-05-14T08:38:59.157

I don't know bash. Can I use Ruby or other dynamic languages at /etc/rc.local scripts? Do you other tools which can do the same job? – nothing-special-here – 2013-05-14T11:55:43.703

Nope. Just write there: /usr/sbin/iptables -A OUTPUT -d 199.15.160.100 -j DROP – Darek – 2013-05-14T12:36:43.457

1

Easiest way is probably to use dnsmasq

Install dnsmasq

$ sudo apt-get install dnsmasq

and add this line to /etc/dnsmasq.conf

address=/deviantart.com/127.0.0.1

This will block deviantart.com and all its subdomains.

Note: For ubuntu see this post.

lemonsqueeze

Posted 2013-05-14T07:56:30.517

Reputation: 1 151

0

You need to add 127.0.1.1 adc.deviantart.com to /etc/hosts to block adc.deviantart.com.

But perhaps better way to boost productivity is to not visit deviantart.com voluntarily? You can also install Adblock Plus plugin for Firefox and use it to block these sites. Adblock lets you add pattern like deviantart.com and automatically block all subdomains - unlike /etc/hosts.

mvp

Posted 2013-05-14T07:56:30.517

Reputation: 3 705

I have edited my answer and added more info. – nothing-special-here – 2013-05-14T08:47:07.613