I felt it was time to take Sysadmins of the North to the next level, it was time to expand with my own global DNS load balancing with Bind9 and Varnish Cache CDN. Here is how I set up my geo-location load balancing Varnish Cache HTTP reverse proxy CDN. It’s all for the fun, various configs are not advanced and may not be optimized. Never copy/paste anything to put into production without testing.
Geolocation DNS load balancing with chrooted Bind9 + geoip-database, and Varnish Cache CDN back-end on DigitalOcean Debian Wheezy droplets. All for fun! 🙂
Read on to learn how to set up a global presense…
Most static content, like javascript and images, are offloaded through a CDN subdomain, which I conveniently called “cdn.saotn.org”. Content is offloaded with IIS Outbound Rules. Using a geo load balancing DNS, based on Bind9, visitors are directed to the nearest Varnish Cache node. One is based in the US (New York) and one in the EU (Amsterdam, NL). It is easy to expand this set up to other locations on the globe.
A set up like this makes the content physically closer and faster available to them (is the idea).
Geo DNS load balancing and Varnish requirements
First you need some DigitalOcean droplets. I chose Debian 7 (Wheezy), one located in NYC2 and one in AMS2. The smalles instance will do fine for low traffic sites. After your droplets are created, log in as root and change your root password. Add a ordinary user and then disable sshd’s PermitRootLogin.
Open up your sshd_config file
vi /etc/ssh/sshd_config
and change PermitRootLogin from yes to no:
PermitRootLogin no
and restart ssh.
Update your packages
apt-get update
apt-get upgrade
Install Bind9 on Debian Wheezy
Now it is time for you to install Bind 9 on your Debian Wheezy droplets. For this, follow the excellent chrooted bind9 with geodns under debian wheezy guide by Pawel Kudzia. This will set up GeoDNS too.
Varnish 4.0 installation on Debian Wheezy
Next, install Varnish 4.0 on your droplets, follow Varnish Caches installation on Debian guide to get you started. For CentOS, you may follow my post installing Varnish Cache on CentOS 6.7.
Create DNS zones
In /etc/bind you have to create a directory zones, and set correct owner and permissions ACLs. Then create two zone files, for example:
cdn.saotn.org.dbcdn-us.saont.org.db
Their contents:
; Zone file for cdn.example.com
$TTL 14400
cdn.example.com. 86400 IN SOA ns1.example.org. admin.example.org. (
2014102909 ;Serial Number
86400 ;refresh
7200 ;retry
3600000 ;expire
86400 )
cdn.example.com. NS ns1.example.org.
cdn.example.com. 300 IN A 1.1.1.1
; Zone file for cdn-us.example.com
$TTL 14400
cdn.example.com. 86400 IN SOA ns1.example.org. admin.example.org. (
2014102909 ;Serial Number
86400 ;refresh
7200 ;retry
3600000 ;expire
86400 )
cdn.example.com NS ns1.example.org.
cdn.example.com 300 IN A 2.2.2.2
And don’t forget your glue- and NS records, see the Bind 9 Administrator Reference Manual for more information on how to set up your zones.
Once you’re satisfied with the zone files and Varnish Cache configuration, start bind 9 and varnish:
service bind9 start
service varnish start
Verify the Geo DNS results using whatsmydns.net and www.just-ping.com.

References used for this post
This post and set up was inspired by the following articles (in no particular order):
- Rolling Your Own CDN – Build A 3 Continent CDN For $25 In 1 Hour
- chrooted bind9 with geodns under debian wheezy
- Loading different website content based on country with GeoDNS
- Varnish Cache installation on Debian
- Cluster Fudge: Recipes for WordPress in the Cloud
Conclusion creating your global Content Delivery Network
Using the online available guides, some own ready to use knowledge and cheap DigitalOcean droplets, you can easily create your own global Content Delivery Network, or CDN. I created this set up in about one hour.
A global DNS load balancing set up like this, with a Varnish Cache back-end, makes content physically closer to your visitors and speeds up your website. They will like that 🙂
Maybe this all is a bit too much for you. You can always use IIS Outbound Rewrite Rules or a PHP and .htaccess configuration to create an Origin Pull CDN to offload content to different hostnames.

Did you like this post?
Please take a second to support Sysadmins of the North and donate! ❤️
Your generosity helps pay for the ongoing costs associated with running this website like coffee, hosting services, library mirrors, domain renewals, time for article research, and coffee, just to name a few. ❤️
Summary
- The article discusses how to set up geo-location DNS load balancing using Bind9 and Varnish Cache CDN.
- It emphasizes using DigitalOcean droplets running Debian Wheezy for this configuration.
- The author created two Varnish Cache nodes in the US and EU to direct visitors to the nearest location.
- Instructions include installing Bind9, configuring DNS zones, and verifying Geo DNS results.
- The setup enhances website speed by bringing content physically closer to the users.
1 thought on “Sysadmins of the North goes global!”