Your browser failed to load CSS style sheets. Your browser or web proxy might not support elliptic-curve TLS

Building network automation solutions

6 week online course

Start now!
back to overview

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 127.0.0.1. 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 hostsToCisco.pl and start the script with perl hostsToCisco.pl hostsFileName.

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

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

No comments:

You don't have to log in to post a comment, but please do provide your real name/URL. Anonymous comments might get deleted.

Sidebar