Skip to content

Commit ad152dd

Browse files
committed
Linux ISC DHCP relay
1 parent 770b076 commit ad152dd

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

DHCP/relay/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ After starting the lab, the *user* device should get DHCP-assigned IP address on
88

99
## Changing Device Types
1010

11-
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.
11+
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.
1212

1313
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.
1414

15+
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.
16+
1517
## Using Linux as the DHCP Client
1618

1719
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.

DHCP/relay/dhcp-client/linux-clab.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ SCRIPT
1818
#
1919
{% for intf in interfaces if intf.dhcp.client|default(False) %}
2020
ip addr flush dev {{ intf.ifname }}
21-
/sbin/udhcpc -S -i {{ intf.ifname }} &
21+
/sbin/udhcpc -S -i {{ intf.ifname }} -b &
2222
{% endfor %}
2323

2424
exit 0

DHCP/relay/dhcp-relay/linux.j2

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
#
3+
export DEBIAN_FRONTEND=noninteractive
4+
apt-get install -qq -y isc-dhcp-relay
5+
dhcrelay -4 {%
6+
for intf in interfaces if intf.dhcp.server is defined %}
7+
{% if loop.first %}
8+
{% set srv = hostvars[intf.dhcp.server] %}
9+
{% set ipv4 = srv.loopback.ipv4 if 'loopback' in srv else srv.interfaces[0].ipv4 %}
10+
{{ ipv4|ipaddr('address') }}
11+
{% endif %}
12+
{% endfor %}

DHCP/relay/linux-vm.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ groups:
2222
switch:
2323
members: [ relay ]
2424
config: [ dhcp-relay ]
25-
device: iosv
25+
device: linux
26+
role: router
2627

2728
nodes: [ srv, relay, user ]
2829

0 commit comments

Comments
 (0)