Skip to content

Instantly share code, notes, and snippets.

@paigeadelethompson
Created December 13, 2023 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paigeadelethompson/0559d8b624751eb5931124f52836aff1 to your computer and use it in GitHub Desktop.
Save paigeadelethompson/0559d8b624751eb5931124f52836aff1 to your computer and use it in GitHub Desktop.
NetNS / VRF with routes and ipv6
#!/bin/bash
/usr/bin/env ip netns delete _netcrave
/usr/bin/env ip link del vrf2
/usr/bin/env ip route flush table 2
/usr/bin/env ip rule add to 198.51.100.0/30 table 2
/usr/bin/env ip netns add _netcrave
/usr/bin/env ip netns exec _netcrave ip link set lo up
/usr/bin/env ip netns exec _netcrave ip link add ns0vrf2 type vrf table 2
/usr/bin/env ip link add vethma0 type veth peer name ns0vethsl0
/usr/bin/env ip netns exec _netcrave ip link set dev ns0vrf2 up
/usr/bin/env ip netns exec _netcrave ip route add table 2 unreachable default metric 4278198272
/usr/bin/env ip link set ns0vethsl0 netns _netcrave
/usr/bin/env ip netns exec _netcrave ip link set dev ns0vethsl0 master ns0vrf2
/usr/bin/env ip netns exec _netcrave ip addr add 198.51.100.1/30 dev ns0vethsl0
/usr/bin/env ip netns exec _netcrave ip link set ns0vethsl0 up
/usr/bin/env ip netns exec _netcrave ip route add default via 198.51.100.2 table 2
/usr/bin/env ip link add vrf2 type vrf table 2
/usr/bin/env ip link set dev vrf2 up
/usr/bin/env ip route add table 2 unreachable default metric 4278198272
/usr/bin/env ip link set vethma0 master vrf2
/usr/bin/env ip addr add 198.51.100.2/30 dev vethma0
/usr/bin/env ip link set vethma0 up
/usr/bin/env ip route add default via 198.51.100.1 table 2
/usr/bin/env ip route add default via 206.125.168.65 table 2
/usr/bin/env ip rule add to 198.51.100.0/30 table 2
iptables -T POSTROUTING -o ens18 -j MASQUERADE
#/usr/bin/env ip netns exec _netcrave /usr/bin/env ip vrf exec ns0vrf2 /usr/bin/env bash -c 'cgroupfs-mount && /opt/docker/dockerd -D --bip 10.0.0.1/16'
# ens18 /64 is 2607:f2f8:a2c4:2000::85
# ip -6 rule add to 2607:f2f8:a2c4:2000:8000::/65 table 2
# ip -6 addr add 2607:f2f8:a2c4:2000:8000::1/66 dev vethma0
# ip -6 route add 2607:f2f8:a2c4:2000:c000::/66 via 2607:f2f8:a2c4:2000:8000::2 table 2
# ip -6 route add default via 2607:f2f8::2/48 table 2 (ens18's default gateway, too)
# ip -6 neigh add proxy 2607:f2f8:a2c4:2000:8000::2 dev ens18
# maybe this ip -6 rule add to ff02::1 table 2
# tf is this, found this looking for info on ndp-proxy
# https://www.irtf.org/anrw/2017/anrw17-final3.pdf