0

I would like to test the DHCP client that I wrote on Ubuntu 16.04.6 LTS. I would like to do it locally on my laptop i.e. send and receive DHCP packets inside.

Here is what I tried:

  • created two dummy interfaces: dummy0, dummy1
  • created bridge for these 2 interfaces: br0

The goal is to send DHCP discover from dummy0 and receive it on dummy1, I'm sending DHCP discover on dummy0, unfortunately I don't see any packets on dummy1 interface. If it could be received the next step would be to run DHCP server on dummy1 to test how my client is doing.

I see DHCP discover in wireshark on dummy0 interface. I see nothing on dummy1. Additionally: I see packet on br0.

I assume there may be better way to do this, could you please tell me how this can be done?

twrm5555
  • 3
  • 3

2 Answers2

0

"Boomerang packets" (sent out from one local interface, received on another local interface) are considered a routing error (loop somewhere out there) and are dropped by the kernel by default.

Also, dummy devices are a pain to work with.

Better approach: Create a network namespace (or two), put a veth pair between the network namespace and the main namespace (or the two network namespaces). No bridge needed. Then test all you want.

Run an xterm in each namespace to make your life easier.

Here's a script I use to do that. Modify as you like.

#!/bin/bash

# Setup network namespace with veth pair, start xterm in it

# nsterm ns0 veth0 10.0.0 yellow 24
#
# tested: yellow, lime, orange, cyan

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

NS=${1:-ns0}
DEV=${2:-veth0}
DEV_A=${DEV}a
DEV_B=${DEV}b
ADDR=${3:-10.0.0}
ADDR_A=${ADDR}.254
ADDR_B=${ADDR}.1
MASK=${5:-24}
COL=${4:-yellow}

# echo ns=$NS dev=$DEV col=$COL mask=$MASK

ip netns add $NS
ip link add $DEV_A type veth peer name $DEV_B netns $NS
ip addr add $ADDR_A/$MASK dev $DEV_A
ip link set ${DEV}a up
ip netns exec $NS ip addr add $ADDR_B/$MASK dev $DEV_B
ip netns exec $NS ip link set ${DEV}b up
ip netns exec $NS ip link set lo up
ip netns exec $NS ip route add default via $ADDR_A dev $DEV_B
ip netns exec $NS su -c "xterm -bg $COL &" your_username
dirkt
  • 31,679
  • 3
  • 40
  • 73
0

I think the answer (commands) here is easy to understand and follow. For veth pair, ping does not recognize interface name and tc qdisc netem does not work