Date created: Monday, August 8, 2016 2:06:22 PM. Last modified: Sunday, September 8, 2024 12:11:00 PM

TUN/TAP, Name Spaces and Veth Notes

TUN interfaces are IP point-to-point style interfaces, TAP are Ethernet broadcast domains:

sudo apt-get install uml-utilities

# Add tap0
sudo tunctl

# Add with specific name
# sudo tunctl -t mytapname

sudo ip link set up dev tap0

# Delete tap0
sudo tunctl -d tap0


# Or by using the "ip" suite...
# sudo ip tuntap add name tun0 mode tun sudo ip tuntap add name tap0 mode tap sudo ip link set up dev tap0
sudo ip tuntap del dev tap0 mode tap

 

Veth pairs and LINUX network name spaces:

# Show network name spaces
sudo ip netns list

sudo ip netns add myprivatespace

sudo ip link add veth0 type veth peer name veth1
# This ^ should add veth0 and veth1, check with...
sudo ip link list

# Move veth1 into the private name space
sudo ip link set veth1 netns myprivatespace

sudo ip link set up dev veth0

# Veth1 is now missing from the output of "sudo ip link list".
# To view/edit it, the "ip" commands must be run inside of the
# "myprivatespace" name space...
sudo ip netns exec myprivatespace ip link list
sudo ip netns exec myprivatespace ip link set up dev veth1

# Run a program in a namespace
sudo ip netns exec myprivatespace /path/to/bin -some -args

 

iPerf between two directly connected interfaces with one side a network namespace to force traffic externally via the NICs:

ip l
ip netns list

sudo ip netns add test
sudo ip link set enp0s8 netns test
sudo ip netns exec test ip link set up dev enp0s8
sudo ip netns exec test ip a a 192.0.2.2/30 dev enp0s8
sudo ip netns exec test ip r

sudo ip link set up dev enp0s9
sudo ip a a 192.0.2.1/30 dev enp0s9
ip r

# Move interface back to global netns and delete netns
sudo ip netns exec test ip link set enp0s9 netns 1
sudo ip netns delete test

# Server
sudo ip netns exec test iperf3 -s -i 1 -B 192.0.2.2

# Client
iperf3 -i 1 -B 192.0.2.1 -c 192.0.2.2 -t 3600
iperf3 -i 1 -B 192.0.2.1 -c 192.0.2.2 -t 3600 -u -b 100M

Previous page: TCP States On Linux
Next page: VLAN Interfaces