Skip to content

Instantly share code, notes, and snippets.

@cyyself
Created January 28, 2025 15:36
Show Gist options
  • Save cyyself/19512b296d6d9a99cde529f02ba2c05c to your computer and use it in GitHub Desktop.
Save cyyself/19512b296d6d9a99cde529f02ba2c05c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
PREFIX = "2001:470:19:a65:"
SUFFIX = "/64"
LEN = 14
print("brctl addbr pathgen")
print("ip link set pathgen up")
print("ip addr add %sffff:ffff:ffff:ffff%s dev pathgen" % (PREFIX, SUFFIX))
for i in range(1, LEN + 1):
print("ip netns add ns%d" % i)
print("ip link add ns%d type veth peer name ns%d-host" % (i, i))
print("ip link set ns%d netns ns%d" % (i, i))
print("ip link set ns%d-host up" % i)
print("brctl addif pathgen ns%d-host" % i)
print("ip netns exec ns%d ip link set lo up" % i)
print("ip netns exec ns%d ip link set dev ns%d up" % (i, i))
print("ip netns exec ns%d ip addr add %s:%d/64 dev ns%d" % (i, PREFIX, i, i))
print("ip netns exec ns%d ip route add default via %sffff:ffff:ffff:ffff dev ns%d" % (i, PREFIX, i))
print("ip netns exec ns%d sysctl -w net.ipv6.conf.all.forwarding=1" % i)
if i != LEN:
print("ip netns exec ns%d ip route add %s:%d via %s:%d dev ns%d" % (i, PREFIX, LEN, PREFIX, i + 1, i))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment