Chotaire Wiki

Stuff you didn't know

User Tools

Site Tools


linux-dhcptest

Testing a DHCP server without an extra physical network adapter

One requirement for testing a DHCP server is that the DHCP client is using a different MAC address than the DHCP server (or in other scenarios, a different mac address than the existing client network interface if that interface is already receiving a lease from the same DHCP server). One could grab a notebook to test DHCP or set up a virtual machine, but the easiest way to accomplish this is to use a virtual interface which provides a unique mac address. This is the tricky part because Linux interface aliases and virtual interfaces use the mac address of their hardware interface. The solution is to create a macvlan0 interface using “ip link”.

Setting up a virtual mac interface:

ip link add dev macvlan0 link eth0 type macvlan

Configuring DHCP client to not update default gateway and DNS

Comment out the request section in /etc/dhclient.conf and use the following request section if you do not want to update your default gateway and DNS settings (e.g. when just testing DHCP communications on a productive machine without changing existing network settings):

request subnet-mask, broadcast-address, interface-mtu;

Requesting a DHCP lease from a local DHCP server:

dhclient -v macvlan0

Dumping DHCP traffic:

tcpdump -lenx -i eth0 -s 1500 port bootps or port bootpc -t -vvv

Delete a virtual mac interface:

ip link delete dev macvlan0



linux-dhcptest.txt · Last modified: 2019/04/20 16:55 by chotaire