At work a while ago we came across an automated test where a temporary IP address was needed. However, we needed to ensure that whatever IP the test chose to use would not affect any other systems on the network.

I believe the workaround that was used was to have each person specify a temporary IP address in the configuration file of the testing framework. This put the responsibility on the person running the test to ensure that they aren’t using an IP address that is already spoken for on the network.

After some thinking though I found a bit of a dirty way that might allow this type of test to acquire a new address reservation from the DHCP service, do some testing with it, then release the DHCP reservation. Each of our labs run DHCP so if we are good about releasing the reservation this should be a fairly safe approach.

Some background first, the systems that we are testing are linux based, use the IPRoute2 network management system and have the "dhcpcd" client available.

Without further adieu, the idea I came up with was:

# add a VNIC with a fake MAC address to the public NIC
ip link add link eth3 address "some-spoofed-mac-address" tmpaddress type macvlan

# make a DHCP reservation to get a temporary address
dhcpcd -AGLMNRYD -I "some-spoofed-mac-address" --leasetime 300 --debug tmpaddress

# execute the various tests
# the temporary DHCP can be found with the command "ip addr show tmpaddress"

# clean up
# release the DHCP Reservation
dhcpcd --debug --release tmpaddress

# delete the VNIC
ip link delete tmpaddress
The NIC that the VNIC will be associated with. I don’t think it matters which one you choose (if you have multiple NICs anyways) as long as the chosen NIC is on the same network as the DHCP server.
The MAC address should be of the format "02:XX:XX:XX:XX:XX". The leading "02" indicates to most compliant systems that it is a fake MAC address. The X’s should be replaced with random hex values.
"tmpaddress" was used as the name of the VNIC that the DHCP address is associated with. Rename it whatever you want as long as you use the same name in all the commands.

DISCLAIMER: I haven’t fully tested this process yet so there may still be some issues with doing things this way.

Maybe this will help somebody out; maybe this will help me out some time down the road. Then again, maybe I’ll post this and promptly forget about it entirely. We’ll see.

" "