Skip to content

M04 DHCP and Static Routing

Back to the Course Schedule

Lecture Videos

DHCP - Dynamic Host Configuration Protocol

Previous chapter discussed about addressing devices manually. This is laborous and ineffective way to work, but necessary in the end of 1990 when standard methods of distributing addresses weren't widely available (or supported).

Jumping to this day and age, DHCP has become such an standard component of every network, that you will come across it several times during your studies. Repetition is one step to mastery.

RFC 2131 - Dynamic Host Configuration Protocol

The Dynamic Host Configuration Protocol (DHCP) provides configuration parameters to Internet hosts. DHCP consists of two components:

  1. a protocol for delivering host-specific configuration parameters from a DHCP server to a host
  2. and a mechanism for allocation of network addresses to hosts.

In DHCP, there needs to be a server component in the network which distributes addresses to clients.

  • DHCP Server(s) can be
    • Linux Operating System (e.g. Centos 8)
    • Windows Operating System (e.g. Windows Server)
    • Router
      • e.g. Vyos we will use this on this course
      • Your home Router
  • DHCP Client(s) can be
    • Mobile Phones
    • Laptops
    • Personal Computers
    • IoT -devices
    • Fridges
    • Toasters
    • Cars
    • Robotic Vacuum Cleaners
    • ... anything that is connected to the Internet

So DHCP is everywhere.

DHCP is sometimes called DHCPv4 for IPv4 usage


IPv6 planned to get rid of DHCP through EUI64 & SLAAC addressing formats.

DHCP still ensists of getting implemented through DHCPv6 (RFC 8415).

Messaging between the devices

DHCP uses UDP port 68 and UDP port 67 for transmission (formelly known as Bootstrap protocol). Figure below shows the basic communication between devices for automatic IP addressing.



Sent by the client to "discover" what DHCP servers are available in the network and what network parameters they have to offer.

Packet capture of DHCPDISCOVER



Sent by the server as a response to DHCPDISCOVER to the client. The server uses this message to suggest configuration parameters to the client.

Packet capture of DHCPOFFER



Once the client receives an offer, it has to request a dhcp binding for those parameters. This recognizes that both parties have heard of each other and are willing to communicate for further for configuration.

Packet capture of DHCPREQUEST



The server confirms the settings and bindings by sending a DHCPACK. This confirms that both parties agree on the configuration parameters.

Packet capture of DHCPACK


Making Vyos a DHCP Server

Our topology uses Vyos as an DHCP server. In configuration we can type the following commands:

set service dhcp-server shared-network-name VLAN5 subnet default-router

Sets the default gateway parameters for subnet to point towards

set service dhcp-server shared-network-name VLAN5 subnet range PCs start

Starts to allocate/bind addresses from the address space. Beginning from the address

set service dhcp-server shared-network-name VLAN5 subnet range PCs stop

Stops to allocate/bind addresses from the address space. Ending in the address

Would look like in show configuration

service {
    dhcp-server {
        shared-network-name VLAN5 {
            subnet {
                range PCs {
Danger: If you have multiple subnets, use differed shared-network-name for them!



service { dhcp-server { shared-network-name VLAN5 { subnet { default-router range PCs { start stop }

    shared-network-name VLAN10 {
        subnet {
            range PCs {

} ```

Once committed and end devices turned to automatic configuration, the server will show active leases distributed to end devices.

show dhcp server leases

vyos@vyos:~$ show dhcp server leases
IP address    Hardware address    Lease expiration     Pool    Client Name
------------  ------------------  -------------------  ------  ------------------   08:00:27:03:c2:9a   2020/08/06 08:01:49  VLAN5   lubuntu-VirtualBox
It is sometimes necessary to force the DHCP client to immediately ask for an IP address

ipconfig /release

ipconfig /renew

dhclient -r


ifdown eth0

ifup eth0

DHCP can sometimes remember a lot (read: be a pain) so often full reboots are necessary to get all the parameters wiped from the OS's memory.

Static Routing

Now we are moving out of the LAN's into Router to Router networks. Routers often work at intersections of subnets, thus they can be seen as traffic lights and traffic signs of those crossroads. They permit traffic through and choices of directions are made based on some metric (typically distance e.g. kilometers in traffic).

Static routes are decisions by network administrators on how to place the signs in those crossroads.

Example: Static route

set protocols static route <subnet> next-hop <how to get there / next-hop>


set protocols static route next-hop

This is similar to a crossroads signs

set a static sign <Helsinki> next-hop <turn left>

The example above works in the topology below. Ampere router is getting the set protocols static route next-hop -command, because it doesn't have any "lines" (actually ethernet adapters) to the IP subnet of Ampere router doesn't know where that subnet is unless it is told so by a static route.


Symmetric & Asymmetric routing

Almost always the telecommunications / network traffic between computers is bidirectional / two-way communications. Both parties want to send traffic to one another: client <-> server. This requires that routing should be complete in all the intersections/routers.

In the example earlier we only added a route from right to left, but there is no route back. This can be thought of going from Jyväskylä to Helsinki, but ... how do we get from Helsinki to Jyväskylä? Well... there are two options, through Lahti or Tampere!


Of course you might take a different route back. And ... why?


Well of course because Jyväskylä - Lahti - Helsinki is shorter, thus it will take less gas and cost less.

This same principle is at the heart of routing. There are reasons for a IPv4 packet to deviate from the shortest path, but typically and quite often... the shortest path is preferred.

Example - Symmetric

Given the example below


To achieve Symmetric routing, the following commands are needed:

On the Ampere -router: set protocols static route next-hop

and on the Candela -router: set protocols static route next-hop

If both subnets are symmetrically routed, the Candela -router needs also: set protocols static route next-hop

Example - Asymmetric

The same thing in asymmetric would mean changes to the routes (given in symmetric routing).


On the Ampere -router: set protocols static route next-hop

and on the Candela -router: `set protocols static route next-hop

Route selection process

We use the topology below to illustrate the route selection process.


Once the Ampere router receives the IP packet, it looks through the Destination Address -field of the packet. Given that the address would be it can then start to look for the longest prefix match in the routing table.

Protocol IP Network Mask Interface
Connected / 30 Ethernet 3
Connected / 24 Ethernet 1
Connected / 24 Ethernet 2
Static / 24 Ethernet 3

For this every routes subnet mask is used to do the AND process (remember from subnetting?) to find out which route fits the best.

In this case if we take our previously installed static route into use we can dissect the subnet mask /24 out of the route. We can then use it to calculate if the Destination Address fits the subnet mask by using the following calculation:

1010 1100 . 0001 0000. 0000 0000 . 0010 0000 the destination address in BIN format.

1111 1111 . 1111 1111. 1111 1111 . 0000 0000 the subnet mask in BIN format.

We use the AND truth gate to cycle through the bit pairs of both addresses to find out that belongs in subnet. And is the best match in the routing table.

Thus the packet is forwarded out of Ethernet 3 interface.

Warning: The example was a direct match with a small table... larger routing tables lead to more complicated situations

There are multiple different things to consider with conflicting routes.

Typically the basic is Administrative Distance and Metric(s). Althought Metric changes from dynamic routing protocol to another.

But these are for later courses.

Continue to the Exercises

E05 Configuring DHCP and Static Routing

Self-reflect the material with a small quiz?

Data Networks Quiz - M04 DHCP and Static Routing

Back to the Schedule?

Back to the Course Schedule


This course and its materials are written by Karo Saharinen and licenced by Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0) license.

Creative Commons -licence