Skip to content

Commit

Permalink
Linux ISC DHCP relay
Browse files Browse the repository at this point in the history
  • Loading branch information
ipspace committed Jun 17, 2023
1 parent 770b076 commit ad152dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion DHCP/relay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ After starting the lab, the *user* device should get DHCP-assigned IP address on

## Changing Device Types

This topology can be used with Cisco IOSv or Arista EOSv. To test it with other devices, add custom configuration template to `dhcp-relay` directory.
This topology can be used with Cisco IOSv, Arista EOSv, or Linux ISC DHCP relay. To test it with other devices, add custom configuration template to `dhcp-relay` directory.

The easiest way to change the device types is to edit the topology file. You could also use the **netlab up** [CLI arguments](https://netsim-tools.readthedocs.io/en/latest/netlab/up.html#usage) -- to change the DHCP relay device type, use `-s nodes.relay.device=xxx` CLI argument.

To use the ISC DHCP relay, you have to add `role: router` to the **dhcp_server** group. See the [Linux VM](linux-vm.yml) topology for more details.

## Using Linux as the DHCP Client

The default lab topology uses Cisco IOSv as the DHCP client and server. You can use a Linux VM or a Linux container as a DHCP client if you don't have access to Cisco IOSv.
Expand Down
2 changes: 1 addition & 1 deletion DHCP/relay/dhcp-client/linux-clab.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SCRIPT
#
{% for intf in interfaces if intf.dhcp.client|default(False) %}
ip addr flush dev {{ intf.ifname }}
/sbin/udhcpc -S -i {{ intf.ifname }} &
/sbin/udhcpc -S -i {{ intf.ifname }} -b &
{% endfor %}

exit 0
12 changes: 12 additions & 0 deletions DHCP/relay/dhcp-relay/linux.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
#
export DEBIAN_FRONTEND=noninteractive
apt-get install -qq -y isc-dhcp-relay
dhcrelay -4 {%
for intf in interfaces if intf.dhcp.server is defined %}
{% if loop.first %}
{% set srv = hostvars[intf.dhcp.server] %}
{% set ipv4 = srv.loopback.ipv4 if 'loopback' in srv else srv.interfaces[0].ipv4 %}
{{ ipv4|ipaddr('address') }}
{% endif %}
{% endfor %}
3 changes: 2 additions & 1 deletion DHCP/relay/linux-vm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ groups:
switch:
members: [ relay ]
config: [ dhcp-relay ]
device: iosv
device: linux
role: router

nodes: [ srv, relay, user ]

Expand Down

0 comments on commit ad152dd

Please sign in to comment.