diff --git a/DHCP/relay/README.md b/DHCP/relay/README.md index da5e100..1de7c51 100644 --- a/DHCP/relay/README.md +++ b/DHCP/relay/README.md @@ -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. diff --git a/DHCP/relay/dhcp-client/linux-clab.j2 b/DHCP/relay/dhcp-client/linux-clab.j2 index d52407f..f2758ae 100644 --- a/DHCP/relay/dhcp-client/linux-clab.j2 +++ b/DHCP/relay/dhcp-client/linux-clab.j2 @@ -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 diff --git a/DHCP/relay/dhcp-relay/linux.j2 b/DHCP/relay/dhcp-relay/linux.j2 new file mode 100644 index 0000000..02dd09d --- /dev/null +++ b/DHCP/relay/dhcp-relay/linux.j2 @@ -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 %} diff --git a/DHCP/relay/linux-vm.yml b/DHCP/relay/linux-vm.yml index f33fb30..f876558 100644 --- a/DHCP/relay/linux-vm.yml +++ b/DHCP/relay/linux-vm.yml @@ -22,7 +22,8 @@ groups: switch: members: [ relay ] config: [ dhcp-relay ] - device: iosv + device: linux + role: router nodes: [ srv, relay, user ]