This Gist demoes Linux' netkit interface pairs. These interfaces are successors for veth tailor made for eBPF and high performance.
Create a 'lab' setup:
# Create the 'lab' namespace
sudo ip netns add lab
# Create and setup the interface pair with both sides in blackhole mode
sudo ip link add nk-host type netkit blackhole peer blackhole name nk-container
sudo ip link set nk-container netns lab
sudo ip netns exec lab ip addr add 10.42.0.2/8 dev nk-container
sudo ip netns exec lab ip link set lo up
sudo ip netns exec lab ip link set nk-container up
sudo ip addr add 10.42.0.1/8 dev nk-host
sudo ip link set nk-host upBuild and run:
go mod init hello-netkit
go mod tidy
go get github.com/cilium/ebpf/cmd/bpf2go
go generate && go build && sudo ./hello-netkitThe setup can be tested with a simple ping 10.42.0.2 in the host, with the program running, and without.
See https://blog.yadutaf.fr/2025/07/01/introduction-to-linux-netkit-interfaces-with-a-grain-of-ebpf/ for the full blog post.
Great blog post, thank you for sharing what you've learned!
The
NETKIT_*return-code macros reside in the UAPI link-layer header.If you want to use
NETKIT_PASSinstead ofTCX_PASS, replace#include <linux/bpf.h>with#include <linux/if_link.h>.