Saturday, April 15, 2017

Raspberry Pi to the rescue

The problem Stated

We are temporarily using a SIM based Internet router.   It works just fine but when you switch on the DHCP server,  so that wireless clients can get a dynamically allocated IP address,  it gives a DNS server address of the router.

(DNS Haiku)

And when used with any SIM, the ASUS router fails to setup any local DNS server on the router, so any connected client fails ALL Internet address lookups.   What absolutely terrible programming, and by the way, this cock-up was not in the original firmware,  but there is no way to back-level :-(

Example of the problem:
ASUS 4G-N12 Router
It's IP =
IP from the Internet =
DHCP Range Set = -> inclusive

When I connect my Android phone it gets
IP =
Default Gateway =

> server
Default Server:  []

Server:  []

DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
DNS request timed out.
    timeout was 2 seconds.
*** Request to [] timed-out

Why don't I manually set the DNS?
At least 2 devices we can name insist on using DHCP and there is no way to override their selection. Culprits are Google Home and Neo Heatmiser.   What terrible programming!  From these clients and also ASUS.

IP's and security
Since this is a temporary setup; the IP addresses quoted in this tutorial are the actual ones used.  Normally we would obfuscate them for security purposes.  But for any would be hackers, please note that already 2 hardware firewalls are installed,  from different vendors,  so attempted network penetration even in this temporary phase is going to be non trivial for you :-)  And since no data is actually present at this address, my sincere advice is: don't bother.

Overview of the Fix

- I will totally disable DHCP from the ASUS 4G-N12 router
- I will install, build and customise a Rasperry Pi Zero W
- pizero will have installed a DHCP server
- It will server out DHCP leases and provide the Google DNS server to clients

Raspberry Pi Zero W

The Pi Zero W is the latest iteration of the Raspberry Pi family and the W means it includes wireless.  So this amazing 10 GBP computer, plus a power supply and cables will be all we need to provide the fix

Install and Update the OS

- Installation is performed from here

root@pizero:~# uname -a
Linux pizero 4.4.50+ #970 Mon Feb 20 19:12:50 GMT 2017 armv6l GNU/Linux

- Update OS

root@pizero:~# apt-get update
Hit jessie InRelease
Hit jessie InRelease
Hit jessie/main armhf Packages
Hit jessie/main armhf Packages
Hit jessie/ui armhf Packages
Hit jessie/contrib armhf Packages
Hit jessie/non-free armhf Packages
Hit jessie/rpi armhf Packages
Ign jessie/main Translation-en
Ign jessie/ui Translation-en
Ign jessie/contrib Translation-en
Ign jessie/main Translation-en
Ign jessie/non-free Translation-en
Ign jessie/rpi Translation-en
Reading package lists... Done

Static IP Address

The IP address of the Pi Zero W must be static since you have turned off any other DHCP server on your network

iface eth0 inet manual

interface wlan0

static domain_name_servers=
static routers=

/etc/hosts   pizero

Now reboot and check that the IP address is really changed

sync; sync; sync;
# it reboots
ifconfig wlan0
wlan0     Link encap:Ethernet  HWaddr b8:27:eb:d8:59:02
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::7ab6:4d57:ccff:5b94/64 Scope:Link
          RX packets:30258 errors:0 dropped:20 overruns:0 frame:0
          TX packets:2378 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:5165420 (4.9 MiB)  TX bytes:455109 (444.4 KiB)

Install a DHCP Server

apt-get install isc-dhcp-server

The install should succeed but the start will fail because you did not configure it yet

default-lease-time 600;
max-lease-time 7200;
option subnet-mask;
option broadcast-address;
option routers;
option domain-name-servers,;
subnet netmask {


Reboot at this point
sync; sync; sync

Some Checking

service isc-dhcp-server status
 isc-dhcp-server.service - LSB: DHCP server
   Loaded: loaded (/etc/init.d/isc-dhcp-server)
   Active: active (running) since Fri 2017-04-14 17:18:21 UTC; 4h 36min ago
  Process: 433 ExecStart=/etc/init.d/isc-dhcp-server start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/isc-dhcp-server.service
           └─625 /usr/sbin/dhcpd -q -cf /etc/dhcp/dhcpd.conf -pf /var/run/dhc...

Apr 14 21:51:19 pizero dhcpd[625]: DHCPACK on to 0c:8b:fd:cc:e...n0

Apr 14 21:52:12 pizero dhcpd[625]: DHCPINFORM from via wlan0:....0
Apr 14 21:52:53 pizero dhcpd[625]: DHCPREQUEST for from f4:f5:...n0

Apr 14 21:52:53 pizero dhcpd[625]: DHCPACK on to f4:f5:d8:cc:1...n0

cat /var/lib/dhcp/dhcpd.leases
lease {
  starts 5 2017/04/14 21:12:51;
  ends 5 2017/04/14 21:22:51;
  cltt 5 2017/04/14 21:12:51;
  binding state active;
  next binding state free;
  rewind binding state free;
  hardware ethernet f4:f5:d8:cc:13:a4;

  client-hostname "Google-Home";

Raspberry Pi Zero W saves the day.  It costs an astonishing 15 GBP from Pi Hut.  Incredible

dhcpd.conf - Linux man page
Buy the Pi Zero W fro Pi Hut