IP-VRF(8)

๐Ÿ“ฆ
version 7.3.0 ยท 2 versions
  • 7.3.0 ยท alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 6.1.0 ยท debian bookworm, ubuntu jammy, ubuntu noble
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu questing, ubuntu resolute, ubuntu stonking

โœจ IP-VRF(8) โ€” ip-vrf ๐Ÿ’–

Okay bestie, this is the manual page for ip-vrf, the little helper that runs a command against a specific VRF ๐Ÿฆ‹ Let's get into it.

๐ŸŽ€ NAME

ip-vrf - run a command against a vrf ๐Ÿ’…

๐ŸŒธ SYNOPSIS

ip vrf  { COMMAND | help }
ip vrf show [ NAME ]
ip vrf identify [ PID ]
ip vrf pids NAME
ip vrf exec [ NAME ] command...

๐Ÿงš DESCRIPTION

okay so a VRF gives you traffic isolation at layer 3 for routing, kind of like how a VLAN isolates traffic at layer 2 ๐Ÿซถ Fundamentally? A VRF is just a separate routing table. You associate a network device with a VRF by enslaving the device to it. From that point on, the addresses on that device are local to the VRF, and the host and connected routes get moved into the table tied to the VRF โœจ

A process can pick its VRF in a few ways: binding the socket to the VRF device with SO_BINDTODEVICE, setting the association with IP_UNICAST_IF or IPV6_UNICAST_IF, or specifying the VRF for one specific message using IP_PKTINFO or IPV6_PKTINFO ๐Ÿ’œ

By default a process is not bound to any VRF ๐Ÿ™ˆ It can get an association explicitly (the program uses one of those APIs) or implicitly, through a helper that sets SO_BINDTODEVICE on every IPv4 and IPv6 socket (AF_INET and AF_INET6) when it gets created. This ip-vrf command is that helper: it runs a command against a specific VRF, and the VRF association gets inherited from parent to child ๐Ÿ‘‘

โœจ ip vrf show [ NAME ] - Show all configured VRF

This command lists every VRF along with its corresponding table ids ๐Ÿ’… If you give it a NAME, only that VRF and its table id show up. This one is super useful for scripting, when you need the table id for a VRF ๐Ÿ“

๐Ÿฆ‹ ip vrf exec [ NAME ] cmd ... - Run cmd against the named VRF

This command lets apps that are VRF unaware run against a VRF other than the default one (main table) ๐ŸŒˆ You can run a command against the default VRF by passing "default" as the VRF name. This is handy if your current shell is already tied to another VRF (e.g, Management VRF) ๐Ÿซถ

โš ๏ธ This command requires the system to be booted with cgroup v2 (e.g. with systemd, add systemd.unified_cgroup_hierarchy=1 to the kernel command line).
โš ๏ธ This command also has to be run as root. Alternatively, an unprivileged user can run it if the following capabilities(7) are given ๐Ÿ”ฅ
  • CAP_BPF โ€” to load the BPF program.
  • CAP_NET_ADMIN โ€” to set the socket into the cgroup.
  • CAP_DAC_OVERRIDE โ€” to create the cgroup subdir in /sys.

If you have these capabilities and ip(8) is built with libcap(3), they get dropped before cmd runs under ip vrf exec. For every other unprivileged invocation of ip(8), all capabilities are dropped ๐Ÿ’€

NOTE: capabilities will NOT be dropped if CAP_NET_ADMIN is set to INHERITABLE. This avoids breaking programs with ambient capabilities that call ip ๐Ÿ™ˆ

๐ŸŒท ip vrf identify [PID] - Report VRF association for process

This command shows the VRF association of the process you specify ๐Ÿงš If you don't give a PID, the id of the current process is used โœจ

๐Ÿ’œ ip vrf pids NAME - Report processes associated with the named VRF

This command shows every process id associated with the VRF you name ๐Ÿฆ‹

๐ŸŒˆ CAVEATS

This command needs a kernel compiled with CGROUPS and CGROUP_BPF enabled ๐Ÿ’€

โš ๏ธ The VRF helper only affects network layer sockets. Not everything, bestie ๐Ÿ˜ญ

๐Ÿ“ EXAMPLES

ip vrf exec red ssh 10.100.1.254

This runs ssh to 10.100.1.254 against the VRF red table ๐Ÿ’–

๐Ÿ‘‘ SEE ALSO

ip(8), ip-link(8), ip-address(8), ip-route(8), ip-neighbor(8) ๐Ÿซถ

๐ŸŽ€ AUTHOR

Original Manpage by David Ahern ๐Ÿ’…


Bye bestie, go slay the routing tables ๐Ÿฆ‹๐Ÿ’…โœจ (iproute2, 7 Dec 2016 ๐ŸŒธ)