Awasu » Banana Pi gateway: Setting up DHCP
Tuesday 1st March 2016 9:20 PM []

Every computer on a network has a unique ID, known as an IP address, which might look something like 72.249.26.4. Back in the day, a network administrator would have to go around and configure these manually for every single computer on a network, but with the advent of DHCP[1]Dynamic Host Configuration Protocol., this can now be done automatically.

When a computer is turned on, and has been configured to use DHCP, it checks the network to see if a DHCP server is available and if so, asks it for an IP address. The DHCP server has a pool of IP addresses it can use, and if one is available, assigns it to the new computer, which can then use it to identify itself and communicate with other computers on the network. When the computer is turned off, its IP address is released and becomes available for use by another computer.

Installing and configuring the DHCP server

So, we need to install a DHCP server on our gateway, so that computers on our internal network can get IP addresses[2]This is actually not strictly necessary, but you would then have to manually assign an IP address to every single computer on your LAN. No fun.. This is very simple:

sudo apt-get install isc-dhcp-server

It will probably fail when it tries to start up, because it hasn't been configured yet, but we can ignore this, since we will configure it now.

First, edit /etc/default/isc-dhcp-server and set the INTERFACES parameter. For example, in my home network, I connect to the internet via wifi (i.e. the wlan0 network interface), and use the wired network for my LAN, so I would set this to eth0[3]In other words, I want the DHCP server to only handle computers on my home network, that connect via eth0 (the wired network). Any computers on the external network, that connect via wlan0 (wifi), will be ignored..

Then edit /etc/dhcp/dhcpd.conf:

  • Set the domain-name option to what you would like to call your network e.g. gateway.
  • Set the domain-name-servers option to the IP address of the bPi[4]This will be sent to DHCP clients..
  • Add a line to set the routers option, that configures the IP address of the gateway[5]This will be sent to DHCP clients..
  • Un-comment the authoritative statement.
  • Configure the lease addresses[6]This is the pool of IP addresses that can be assigned to new computers joining the network. e.g.
        subnet 10.0.0.0 netmask 255.255.255.0 {
            range 10.0.0.100 10.0.0.199 ;
        }
    
  • It is also possible to assign specific computers a fixed IP address, according to their MAC address e.g.
        host mycomputer {
            hardware ethernet XX:XX:XX:XX:XX:XX ;
            fixed-address 10.0.0.2 ;
        }
    

Restart the service:

sudo service isc-dhcp-server restart

We also want it to start up when the system is booted:

sudo update-rc.d isc-dhcp-server start

Finally, to check what IP addresses have been assigned, take a look inside /var/lib/dhcp/dhcpd.leases.

« Setting up the gateway

Tutorial index

Setting up DNS »

   [ + ]

1. Dynamic Host Configuration Protocol.
2. This is actually not strictly necessary, but you would then have to manually assign an IP address to every single computer on your LAN. No fun.
3. In other words, I want the DHCP server to only handle computers on my home network, that connect via eth0 (the wired network). Any computers on the external network, that connect via wlan0 (wifi), will be ignored.
4, 5. This will be sent to DHCP clients.
6. This is the pool of IP addresses that can be assigned to new computers joining the network.
Have your say