Skip to content

Instantly share code, notes, and snippets.

@rajeshrah22
Created January 22, 2026 03:25
Show Gist options
  • Select an option

  • Save rajeshrah22/bda1183f74ab078589fc5c6d78b34715 to your computer and use it in GitHub Desktop.

Select an option

Save rajeshrah22/bda1183f74ab078589fc5c6d78b34715 to your computer and use it in GitHub Desktop.
setup_local_underlay() {
sudo ip netns add hostA;
sudo ip netns add hostB;
sudo ip link add name vethA type veth peer name vethB;
sudo ip link set vethA netns hostA;
sudo ip link set vethB netns hostB;
# create underlay network "physical"
sudo ip netns exec hostA ip addr add 192.178.0.1/24 dev vethA;
sudo ip netns exec hostA ip link set vethA up;
sudo ip netns exec hostB ip addr add 192.178.0.2/24 dev vethB;
sudo ip netns exec hostB ip link set vethB up;
# verify underlay connectivity
echo "===== verifying underlay connectivity ====="
sudo ip netns exec hostA ping -c 1 192.178.0.2;
}
setup_geneve_tunnel() {
sudo ip netns exec hostA ip link add name gnv0 type geneve external;
sudo ip netns exec hostA ip link set gnv0 up;
sudo ip netns exec hostA ip addr add 10.0.0.1/24 dev gnv0;
sudo ip netns exec hostB ip link add name gnv0 type geneve external;
sudo ip netns exec hostB ip link set gnv0 up;
sudo ip netns exec hostB ip addr add 10.0.0.2/24 dev gnv0;
# routing
# This works, but why?
# We are saying packets in logical network destined to some CIDR block goes through tunnel
# to remote endpoint specified.
sudo ip netns exec hostA ip route add 10.0.0.2/32 encap ip id 100 dst 192.178.0.2 dev gnv0;
sudo ip netns exec hostB ip route add 10.0.0.1/32 encap ip id 100 dst 192.178.0.1 dev gnv0;
}
teardown() {
sudo ip netns delete hostA;
sudo ip netns delete hostB;
}
show_state() {
echo "===== HOST A ====="
sudo ip netns exec hostA ip -d link show gnv0;
sudo ip netns exec hostA ip -d route;
echo "===== HOST B ====="
sudo ip netns exec hostB ip -d link show gnv0;
sudo ip netns exec hostB ip -d route;
}
verify_routing() {
echo "===== verifying connectivity ====="
sudo ip netns exec hostA ping -c 3 10.0.0.2;
sudo ip netns exec hostB ping -c 3 10.0.0.1;
}
case "$1" in
--setup)
set -x
setup_local_underlay
setup_geneve_tunnel
set +x
show_state
verify_routing
;;
--clean)
set -x
teardown
set +x
ip a
ip route
;;
*)
echo "Usage: $0 {--setup|--clean}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment