After determining how DHCP relaying works, I made a decision to try it out in a lab. netlab has no DHCP configuration module (in the meanwhile); the best method ahead appeared to be customized configuration templates mixed with a couple of additional attributes.
Lab Topology
That is how I arrange the lab:
- I created easy lab topology with DHCP server (IOSv), DHCP shopper (one other IOSv), and a relaying node that could possibly be something that helps DHCP relaying.
Lab IP addressing
Interface IPv4 deal with Description
=========================================================
srv (10.0.0.1/32)
GigabitEthernet0/1 10.1.0.2/30 srv -> relay
relay (10.0.0.2/32)
GigabitEthernet0/1 10.1.0.1/30 relay -> srv
GigabitEthernet0/2 172.16.0.2/24 relay -> person
person (10.0.0.3/32)
GigabitEthernet0/1 172.16.0.3/24 person -> relay
- I used interface attribute dhcp.shopper (boolean) on the shopper and dhcp.server (node title, string) on the relay node. That is how I outlined these attributes:
Additional DHCP attributes
defaults.attributes:
hyperlink.dhcp:
shopper: bool
server: str
DHCP shopper, relay, and server teams
teams:
dhcp_server:
members: [ srv ]
module: [ ospf ]
config: [ dhcp-server ]
system: iosv
dhcp_client:
members: [ user ]
config: [ dhcp-client ]
system: iosv
swap:
members: [ relay ]
module: [ ospf ]
config: [ dhcp-relay ]
- I’m working OSPF between DHCP relay and DHCP server. Whereas that’s not the way you’d arrange a typical DHCP server, it permits me to relay DHCP requests to the DHCP server loopback interface.
- Lastly, I needed to outline the nodes and the hyperlinks:
Nodes and hyperlinks
nodes: [ srv, relay, user ]
hyperlinks:
- relay-srv
- person:
dhcp.shopper: True
relay:
dhcp.server: srv
kind: lan
I set the hyperlink kind on the hyperlink between person and relay swap to LAN to make sure it will get a /24 prefix. Doing DHCP on a /30 prefix is boring.
As all the time, you may discover the ultimate topology file on GitHub.
Configuration Templates
Now for the enjoyable half: customized configuration templates (additionally on GitHub). The shopper template was trivial:
- Discover interfaces with dhcp.shopper attribute
- Take away static IPv4 deal with from them
- Allow DHCP shopper on the interface
DHCP shopper configuration template
{% for intf in interfaces if intf.dhcp.shopper is outlined and intf.dhcp.shopper %}
interface {{ intf.ifname }}
no ip deal with
ip deal with dhcp
{% endfor %}
The relaying template was already a bit extra convoluted. I needed to discover the interfaces with dhcp.server attribute after which discover the loopback IP deal with of the DHCP server to make use of within the helper-address command. Apparently, I may use equivalent template for Cisco IOSv and Arista vEOS.
DHCP relay configuration template
{% for intf in interfaces if intf.dhcp.server is outlined %}
interface {{ intf.ifname }}
ip helper-address {ipaddr('deal with') }
{% endfor %}
Lastly the DHCP server template. This one is a beast:
- It iterates over all different nodes within the Ansible stock and finds interfaces with dhcp.server attribute (relaying interfaces)
- For every relaying interface, the template excludes its IPv4 deal with from the DHCP pool, and creates a corresponding pool with the relaying interface IPv4 deal with because the default router.
- I additionally turned on debugging within the configuration template so I may log into the DHCP server and examine the logs instantly after netlab up completes its job.
DHCP server configuration template
logging buffered
no service timestamp debug
!
do debug ip dhcp server packet
do debug ip dhcp server occasion
!
{% for h,v in hostvars.gadgets() %}
{% for intf in v.interfaces if intf.dhcp.server is outlined and intf.ipv4 is outlined %}
ip dhcp excluded-address {ipaddr('deal with') }
{% endfor %}
{% endfor %}
!
{% for h,v in hostvars.gadgets() %}
{% for intf in v.interfaces if intf.dhcp.server is outlined and intf.ipv4 is outlined %}
!
ip dhcp pool p_{ipaddr('community') }
community {ipaddr('community') } {ipaddr('netmask') }
default-router {ipaddr('deal with') }
{% endfor %}
{% endfor %}
Listed below are the additional configuration instructions generated by these templates:
Cisco IOS DHCP shopper configuration
interface GigabitEthernet0/1
no ip deal with
ip deal with dhcp
Cisco IOS DHCP relay configuration
interface GigabitEthernet0/2
ip helper-address 10.0.0.1
Cisco IOS DHCP server configuration (together with debugging instructions)
logging buffered
no service timestamp debug
!
do debug ip dhcp server packet
do debug ip dhcp server occasion
!
ip dhcp excluded-address 172.16.0.2
!
!
ip dhcp pool p_172.16.0.0
community 172.16.0.0 255.255.255.0
default-router 172.16.0.2
You will discover the last system configurations utilizing Arista EOS on the DHCP relay within the GitHub netlab-example repository.
Does It Work?
You guess. Right here’s the printout from the shopper router:
person#present dhcp lease
...
Temp IP addr: 172.16.0.3 for peer on Interface: GigabitEthernet0/1
Temp sub web masks: 255.255.255.0
DHCP Lease server: 10.1.0.2, state: 5 Certain
DHCP transaction id: EAB
Lease: 86400 secs, Renewal: 43200 secs, Rebind: 75600 secs
Temp default-gateway addr: 172.16.0.2
Subsequent timer fires after: 11:59:35
Retry rely: 0 Shopper-ID: cisco-5254.002c.2b7b-Gi0/1
Shopper-ID hex dump: 636973636F2D353235342E303032632E
326237622D4769302F31
Hostname: person
There appears to be a tiny glitch within the printout: the DHCP relay is forwarding DHCP requests to 10.0.0.1, however the DHCP shopper claims it’s speaking with DHCP server with IP deal with 10.1.0.2 – the LAN interface IPv4 deal with of the DHCP server. The change of IP deal with is an ideal implementation of RFC 2131 which says:
If the server has obtained a message by way of a DHCP relay agent, the server SHOULD select an deal with from the interface on which the message was recieved [sic] because the ‘server identifier’ (until the server has different, higher data on which to make its selection).
It’s good to see issues working precisely the best way they need to 😉
Combating Repeatability Disaster One Lab at a Time
Need to run this lab by yourself, or attempt it out with completely different gadgets? No drawback:
Coming Up Subsequent
Easy DHCP relaying works, however what about inter-VRF DHCP relaying? That’s the subject of the following weblog put up on this collection.