Complete geekery.

The IT department at Russian Interference uses two pieces of software that greatly enhances the organisation’s cyber anonymity. HideMe, a virtual private network tool and PiHole a very effective advertisement blocker. Sadly the two do not play together very happily.

PiHole runs on a network connected Raspberry Pi and acts as a primary DNS for other devices on the local network. It maintains an enormous cloud-sourced blacklist of ‘very bad people’ websites, ranging from the merely irritating to the downright dangerous. If you load a web page containing links to these sites, PiHole will vaporise the links and replace any intended content with a reassuringly blank area on the page. Any adverts that do make it through can be identified, zapped and added to the cloud list for the benefit of other users.

HideMe is a VPN that allows you to browse the web anonymously by hiding your true IP address behind a range of proxy servers situated in a large number of countries. Combined with a like minded search engine such as Duck Duck Go it is possible to surf the web without the targeted advertising and search response profiling that attempts to maximise our spending on age related products such as incontinence wear and uplifting drugs.

The problem

To use PiHole all that it needs is for the user to add its IP address to their list of domain name servers (DNS). On MacOS this is easily done via SystemPreferences/Network/Advanced/DNS. The PiHole address needs to be the first one on the list.

HideMe tries to be helpful and when it starts up it clears out your existing DNS list and supplies two addresses of its own. These quite sensibly are the DNS servers running on whatever HideMe server it connects you to. It has no objection to you adding the PiHole address once it has done this, and everything works smoothly … for a while.

The solution

We developed the following shell script to detect the absence of PiHole from the DNS list and replace it. So that the system does not lose the HideMe DNS server addresses it saves them before it deletes the list and adds them again following the PiHole entry.

# Script to restore DNS servers to the SystemPreferences/Network/Advanced/DNS settings
# when they have been zapped by HideMe during a VPN refresh
# filename:
# to be added to crontab commands
current_DNS=$(/usr/sbin/networksetup -getdnsservers Ethernet)
preferred_DNS="<your PiHole IP address>"
error_message="There aren\'t any DNS Servers set on Ethernet."
echo "Current DNS servers: " ${current_DNS}
if [[ $current_DNS == *${preferred_DNS}* ]];
        echo "Hunkydory!"
        if [[ ${current_DNS} == ${error_message} ]];
            /usr/sbin/networksetup -setdnsservers Ethernet ${preferred_DNS}
            /usr/sbin/networksetup -setdnsservers Ethernet "Empty"
            /usr/sbin/networksetup -setdnsservers Ethernet ${preferred_DNS} ${current_DNS}

As the interruption of the HideMe service can take place at any time the script above is run every minute using a cron job. To edit your cron task list use the command crontab -e and insert the following line at the end.

*/1 * * * * <path to your script>/ > /dev/null 2>&1

That’s it – it works!