Usurping the BTHomeHub with a Raspberry Pi: Part 1
I used to run a nice pfSense box as my router, unfortunately power bills being what they are, I reverted back to using a BTHomeHub. Unfortunately, the BTHomeHub isn't particularly good - the Wifi signal sucks, it's DNS server seems to daydream and it occasionally forgets that it should be assigning some devices the same IP every time (or more precisely, will give their IP away if they are not currently present).
We could, of course, replace the HomeHub with something a bit more up market, but where's the fun in that? In this post, we'll be starting down the route of using a Raspberry Pi to usurp some of the power the BTHomeHub currently holds over the LAN. Eventually, the HH will be acting as nothing but a dumb internet gateway, doing a little bit of NAT and not much else.
Getting the Kit
It should go without saying that we'll be needed a Model B Raspberry Pi, a case (homemade or otherwise), and an SD Card. As we're planning on taking away the HomeHub's WLAN responsibilities we'll also want a USB wireless dongle - I've found the Edimax EW-7711USn USB 802.11 b/g/n Adaptor plays rather well with the Pi, especially as you can unscrew the antenna and add something really high gain if needed.
Getting Started
So the first thing we need to do, is to install our Base OS. We're going to be using Raspbian, so download an image from RaspberryPi.org, and write the image to your SD card
sudo dd if=2013-12-20-wheezy-raspbian.img of=/dev/sdj
Note: It should go without saying, but make sure that /dev/sdj is actually your SD card!
Connect your Pi up to a monitor/TV and plug a keyboard and mouse in so that we can complete the initial set-up. When the first launch screen appears (yum, ncurses) opt to to the following
- Resize root to fill SD card
- Set Hostname (I went with RaspPiRouter)
- Enable OpenSSH
- Change the GPU memory allocation to 16MB (the system's going to be headless, why waste RAM on the GPU?)
Once ready, connect up an ethernet cable and reboot the Pi. For the time being it should get an IP via DHCP, you can either check the allocated IP on the HomeHub, or run
ip a
On the pi itself.
Connect Remotely
Now we want to SSH in and do a bit of configuration, so assuming the Pi got the IP 192.168.1.25
ssh pi@192.168.1.25
Enter 'raspberry' as the password. Now that we're in, the first thing to do is change the default password (everyone knows that it's raspberry)
passwd
Install Some Packages
We're largely going to install packages as we need them, but let's begin with the first two that we know we'll need
sudo -s # Saves me typing sudo before every command in this tutorial
apt-get install hostapd isc-dhcp-server
Configure Networking
Now we want to do a bit of IP allocation, the HomeHub grabs itself 192.168.1.254 and .253 so we're going to use .252, .251 and .250. What we're looking to do is to get the WLAN access point working with DHCP, once that's done we'll bridge the interfaces and let our DHCP server rule the entire LAN
ifdown wlan0
nano /etc/network/interfaces
#Remove all entries relating to wlan0 except for allow hotplug
# Then add:
iface wlan0 inet static
address 192.168.1.251
netmask 255.255.255.0
Save and exit
For now, we'll manually apply the IP to the interface
ifconfig wlan0 192.168.1.251
Configure HostAPD
The next step in configuring our wireless access point is to actually tell it what we want it to do, bear in mind this config file is nothing short of tetchy, so pay close attention to the values you use (don't try and use hw_mode n for example). Change the values of ssid and wpa_passphrase to suit your needs
nano /etc/hostapd/hostapd.conf
interface=wlan0
ssid=MyHomeNetwork
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=Raspberry
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Next we want to configure the system defaults to point to our config file
nano /etc/default/hostapd
# Add the following
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Finally, we can fire up the WLAN AP to check everything works
/usr/sbin/hostapd /etc/hostapd/hostapd.conf
#At this point you should be able to see the wireless network from your phone/laptop. If you try and connect you'll see something like the following in the terminal (expect your connection to fail though)
Configuration file: /etc/hostapd/hostapd.conf
Failed to update rate sets in kernel module
Using interface wlan0 with hwaddr 80:1f:02:8d:5f:51 and ssid 'MyHomeNetwork'
wlan0: STA 00:37:6d:be:c7:c3 IEEE 802.11: authenticated
wlan0: STA 00:37:6d:be:c7:c3 IEEE 802.11: associated (aid 1)
wlan0: AP-STA-CONNECTED 00:37:6d:be:c7:c3
wlan0: STA 00:37:6d:be:c7:c3 RADIUS: starting accounting session 52C2E54A-00000000
wlan0: STA 00:37:6d:be:c7:c3 WPA: pairwise key handshake completed (RSN)
Your connection will likely have failed, unless the client you were connecting with happened to have a static IP. Press Ctrl+C to bring the AP back down and we'll move onto the all important next step
Configuring DHCP
So, now we want to configure the DHCP server
nano /etc/dhcp/dhcp.conf
# Comment out the following
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;
# Leave authoritative commented, we're not ready to replace the HomeHub just yet!
At the bottom of the file, add the following
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.150 192.168.1.200;
option broadcast-address 192.1.0.255;
option routers 192.168.1.254;
default-lease-time 600;
max-lease-time 7200;
option domain-name "home";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
Save and close.
Static IPs
You may wish to reserve a specific IP for a specific machine, if so, re-open the dhcp configuration and add something similar to the following (one per machine)
host xbmc-eedb {
hardware ethernet b8:27:eb:0b:ee:da;
fixed-address 192.168.1.74;
}
Save and close, and the system with that MAC address will always be issued .74 (once the dchp server has been restarted
Now we need to configure the DHCP server to listen on WLAN0
nano /etc/default/isc-dhcp-server
#Set Interfaces to wlan0
Save and close, then bring up the DHCP server daemon
service isc-dhcp-server start
Note: if it fails, make sure WLAN0 still has the ip we assigned it -
ifconfig wlan0 192.168.1.251
If we start the WLAN AP again, you should now be able to connect - though you still won't be able to do much once on the network
/usr/sbin/hostapd /etc/hostapd/hostapd.conf
Your client should now receive an IP from within the range we specified, though it won't currently be able to route traffic to the internet. For that, we want a bridge, so Ctrl+C to kill hostapd one last time;
Creating a Bridge
Our final step before making everything start at boot, is to bridge our interfaces (I prefer this to NATting, it's one LAN after all!
apt-get install bridge-utils
Now we need to edit our network interfaces again
nano /etc/network/interfaces
# My values are below
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
address 192.168.1.252
netmask 255.255.255.0
gateway 192.168.1.254
iface default inet dhcp
allow hotplug wlan0
auto wlan0 br0
iface br0 inet static
address 192.168.1.250
broadcast 192.168.1.255
netmask 255.255.255.0
network 192.168.1.0
gateway 192.168.1.254
bridge_ports eth0 wlan0
Save and close.
When you run the next command, you will lose your SSH session, keep a note of the IP you defined for br0 as it's this one we'll need to SSH back in on
ifup br0
SSH back in, and to play it safe, run
service hostapd start
service networking restart
Now your client should be able to connect to the wifi and access the internet. If so, let's configure it all to start at boot
update-rc.d hostapd enable && update-rc.d isc-dhcp-server enable
wpa_supplicant might just undo all our hard work though, so lets disable it
mv /usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service ~
It's at this point, we want to reboot the Pi just to be sure that everything will be as we left it if there is a power outage.
reboot
I initially found that DHCP requests would go unanswered following a reboot, it seems to be an issue with hostAPD and restarting the networking service after it's loaded resolves it. So (and this really isn't the correct way to fix an issue), I edited the init script for the DHCP server to include
service networking restart
Just before the DHCP service is started (i.e. look for "Starting $DESC" "$NAME" and add the restart on the line before.
In Part Two we configure the Pi to act as a DHCP server for the entire LAN as well as providing DNS and NTP services
Usurping the BTHomeHub With a Raspberry Pi - Follow Up Documentation
- Usurping the BTHomeHub with a Raspberry Pi: Part 2 - DNS, DHCP and NTP
- Usurping the BTHomeHub with a Raspberry Pi: Part 3 - Routing, Remote Administration and Utilities
- Usurping the BTHomeHub with a Raspberry Pi: Part 4 - Using a VPN to Tunnel Connections to Specific IPs
- Usurping the BTHomeHub with a Raspberry Pi: Part 5 - Inbound OpenVPN
- Usurping the BTHomeHub with a Raspberry Pi: Part 6 - Conclusion