Building network automation solutions

9 module online course

Start now!

Kill browser ads with Cisco router's DNS server

As you might already know, you can use the /etc/hosts file (or its Windows equivalent) to kill unwanted browser ads - just list all the banner-serving sites in you hosts file and set their IP addresses to In my June IP Corner article, Cisco Router: the Swiss Army Knife of Network Services (section Stop the browser ads and banners), I'm describing how you can do the same thing network-wide with a router acting as a DNS server.

For those of you who would like to automate this approach and convert a hosts file into a router configuration, here's a short PERL script to do it. To run it, save the source into and start the script with perl hostsFileName.

# converts hosts file into router configuration
# Stdin: hosts file
# Stdout: IOS configuration
our @line,$i;

while (<>) {
@line = split(/\s+/,$_);
next unless $line[0] eq "";
for ($i = 1; $i < $#line; $i++) {
last if $line[$i] =~ /\#/;
print "ip host $line[$i]\n"
Add comment