1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun==================================== 4*4882a593SmuzhiyunVirtual Routing and Forwarding (VRF) 5*4882a593Smuzhiyun==================================== 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunThe VRF Device 8*4882a593Smuzhiyun============== 9*4882a593Smuzhiyun 10*4882a593SmuzhiyunThe VRF device combined with ip rules provides the ability to create virtual 11*4882a593Smuzhiyunrouting and forwarding domains (aka VRFs, VRF-lite to be specific) in the 12*4882a593SmuzhiyunLinux network stack. One use case is the multi-tenancy problem where each 13*4882a593Smuzhiyuntenant has their own unique routing tables and in the very least need 14*4882a593Smuzhiyundifferent default gateways. 15*4882a593Smuzhiyun 16*4882a593SmuzhiyunProcesses can be "VRF aware" by binding a socket to the VRF device. Packets 17*4882a593Smuzhiyunthrough the socket then use the routing table associated with the VRF 18*4882a593Smuzhiyundevice. An important feature of the VRF device implementation is that it 19*4882a593Smuzhiyunimpacts only Layer 3 and above so L2 tools (e.g., LLDP) are not affected 20*4882a593Smuzhiyun(ie., they do not need to be run in each VRF). The design also allows 21*4882a593Smuzhiyunthe use of higher priority ip rules (Policy Based Routing, PBR) to take 22*4882a593Smuzhiyunprecedence over the VRF device rules directing specific traffic as desired. 23*4882a593Smuzhiyun 24*4882a593SmuzhiyunIn addition, VRF devices allow VRFs to be nested within namespaces. For 25*4882a593Smuzhiyunexample network namespaces provide separation of network interfaces at the 26*4882a593Smuzhiyundevice layer, VLANs on the interfaces within a namespace provide L2 separation 27*4882a593Smuzhiyunand then VRF devices provide L3 separation. 28*4882a593Smuzhiyun 29*4882a593SmuzhiyunDesign 30*4882a593Smuzhiyun------ 31*4882a593SmuzhiyunA VRF device is created with an associated route table. Network interfaces 32*4882a593Smuzhiyunare then enslaved to a VRF device:: 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun +-----------------------------+ 35*4882a593Smuzhiyun | vrf-blue | ===> route table 10 36*4882a593Smuzhiyun +-----------------------------+ 37*4882a593Smuzhiyun | | | 38*4882a593Smuzhiyun +------+ +------+ +-------------+ 39*4882a593Smuzhiyun | eth1 | | eth2 | ... | bond1 | 40*4882a593Smuzhiyun +------+ +------+ +-------------+ 41*4882a593Smuzhiyun | | 42*4882a593Smuzhiyun +------+ +------+ 43*4882a593Smuzhiyun | eth8 | | eth9 | 44*4882a593Smuzhiyun +------+ +------+ 45*4882a593Smuzhiyun 46*4882a593SmuzhiyunPackets received on an enslaved device and are switched to the VRF device 47*4882a593Smuzhiyunin the IPv4 and IPv6 processing stacks giving the impression that packets 48*4882a593Smuzhiyunflow through the VRF device. Similarly on egress routing rules are used to 49*4882a593Smuzhiyunsend packets to the VRF device driver before getting sent out the actual 50*4882a593Smuzhiyuninterface. This allows tcpdump on a VRF device to capture all packets into 51*4882a593Smuzhiyunand out of the VRF as a whole\ [1]_. Similarly, netfilter\ [2]_ and tc rules 52*4882a593Smuzhiyuncan be applied using the VRF device to specify rules that apply to the VRF 53*4882a593Smuzhiyundomain as a whole. 54*4882a593Smuzhiyun 55*4882a593Smuzhiyun.. [1] Packets in the forwarded state do not flow through the device, so those 56*4882a593Smuzhiyun packets are not seen by tcpdump. Will revisit this limitation in a 57*4882a593Smuzhiyun future release. 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun.. [2] Iptables on ingress supports PREROUTING with skb->dev set to the real 60*4882a593Smuzhiyun ingress device and both INPUT and PREROUTING rules with skb->dev set to 61*4882a593Smuzhiyun the VRF device. For egress POSTROUTING and OUTPUT rules can be written 62*4882a593Smuzhiyun using either the VRF device or real egress device. 63*4882a593Smuzhiyun 64*4882a593SmuzhiyunSetup 65*4882a593Smuzhiyun----- 66*4882a593Smuzhiyun1. VRF device is created with an association to a FIB table. 67*4882a593Smuzhiyun e.g,:: 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun ip link add vrf-blue type vrf table 10 70*4882a593Smuzhiyun ip link set dev vrf-blue up 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun2. An l3mdev FIB rule directs lookups to the table associated with the device. 73*4882a593Smuzhiyun A single l3mdev rule is sufficient for all VRFs. The VRF device adds the 74*4882a593Smuzhiyun l3mdev rule for IPv4 and IPv6 when the first device is created with a 75*4882a593Smuzhiyun default preference of 1000. Users may delete the rule if desired and add 76*4882a593Smuzhiyun with a different priority or install per-VRF rules. 77*4882a593Smuzhiyun 78*4882a593Smuzhiyun Prior to the v4.8 kernel iif and oif rules are needed for each VRF device:: 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun ip ru add oif vrf-blue table 10 81*4882a593Smuzhiyun ip ru add iif vrf-blue table 10 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun3. Set the default route for the table (and hence default route for the VRF):: 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun ip route add table 10 unreachable default metric 4278198272 86*4882a593Smuzhiyun 87*4882a593Smuzhiyun This high metric value ensures that the default unreachable route can 88*4882a593Smuzhiyun be overridden by a routing protocol suite. FRRouting interprets 89*4882a593Smuzhiyun kernel metrics as a combined admin distance (upper byte) and priority 90*4882a593Smuzhiyun (lower 3 bytes). Thus the above metric translates to [255/8192]. 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun4. Enslave L3 interfaces to a VRF device:: 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun ip link set dev eth1 master vrf-blue 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun Local and connected routes for enslaved devices are automatically moved to 97*4882a593Smuzhiyun the table associated with VRF device. Any additional routes depending on 98*4882a593Smuzhiyun the enslaved device are dropped and will need to be reinserted to the VRF 99*4882a593Smuzhiyun FIB table following the enslavement. 100*4882a593Smuzhiyun 101*4882a593Smuzhiyun The IPv6 sysctl option keep_addr_on_down can be enabled to keep IPv6 global 102*4882a593Smuzhiyun addresses as VRF enslavement changes:: 103*4882a593Smuzhiyun 104*4882a593Smuzhiyun sysctl -w net.ipv6.conf.all.keep_addr_on_down=1 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun5. Additional VRF routes are added to associated table:: 107*4882a593Smuzhiyun 108*4882a593Smuzhiyun ip route add table 10 ... 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun 111*4882a593SmuzhiyunApplications 112*4882a593Smuzhiyun------------ 113*4882a593SmuzhiyunApplications that are to work within a VRF need to bind their socket to the 114*4882a593SmuzhiyunVRF device:: 115*4882a593Smuzhiyun 116*4882a593Smuzhiyun setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, dev, strlen(dev)+1); 117*4882a593Smuzhiyun 118*4882a593Smuzhiyunor to specify the output device using cmsg and IP_PKTINFO. 119*4882a593Smuzhiyun 120*4882a593SmuzhiyunBy default the scope of the port bindings for unbound sockets is 121*4882a593Smuzhiyunlimited to the default VRF. That is, it will not be matched by packets 122*4882a593Smuzhiyunarriving on interfaces enslaved to an l3mdev and processes may bind to 123*4882a593Smuzhiyunthe same port if they bind to an l3mdev. 124*4882a593Smuzhiyun 125*4882a593SmuzhiyunTCP & UDP services running in the default VRF context (ie., not bound 126*4882a593Smuzhiyunto any VRF device) can work across all VRF domains by enabling the 127*4882a593Smuzhiyuntcp_l3mdev_accept and udp_l3mdev_accept sysctl options:: 128*4882a593Smuzhiyun 129*4882a593Smuzhiyun sysctl -w net.ipv4.tcp_l3mdev_accept=1 130*4882a593Smuzhiyun sysctl -w net.ipv4.udp_l3mdev_accept=1 131*4882a593Smuzhiyun 132*4882a593SmuzhiyunThese options are disabled by default so that a socket in a VRF is only 133*4882a593Smuzhiyunselected for packets in that VRF. There is a similar option for RAW 134*4882a593Smuzhiyunsockets, which is enabled by default for reasons of backwards compatibility. 135*4882a593SmuzhiyunThis is so as to specify the output device with cmsg and IP_PKTINFO, but 136*4882a593Smuzhiyunusing a socket not bound to the corresponding VRF. This allows e.g. older ping 137*4882a593Smuzhiyunimplementations to be run with specifying the device but without executing it 138*4882a593Smuzhiyunin the VRF. This option can be disabled so that packets received in a VRF 139*4882a593Smuzhiyuncontext are only handled by a raw socket bound to the VRF, and packets in the 140*4882a593Smuzhiyundefault VRF are only handled by a socket not bound to any VRF:: 141*4882a593Smuzhiyun 142*4882a593Smuzhiyun sysctl -w net.ipv4.raw_l3mdev_accept=0 143*4882a593Smuzhiyun 144*4882a593Smuzhiyunnetfilter rules on the VRF device can be used to limit access to services 145*4882a593Smuzhiyunrunning in the default VRF context as well. 146*4882a593Smuzhiyun 147*4882a593Smuzhiyun-------------------------------------------------------------------------------- 148*4882a593Smuzhiyun 149*4882a593SmuzhiyunUsing iproute2 for VRFs 150*4882a593Smuzhiyun======================= 151*4882a593Smuzhiyuniproute2 supports the vrf keyword as of v4.7. For backwards compatibility this 152*4882a593Smuzhiyunsection lists both commands where appropriate -- with the vrf keyword and the 153*4882a593Smuzhiyunolder form without it. 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun1. Create a VRF 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun To instantiate a VRF device and associate it with a table:: 158*4882a593Smuzhiyun 159*4882a593Smuzhiyun $ ip link add dev NAME type vrf table ID 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun As of v4.8 the kernel supports the l3mdev FIB rule where a single rule 162*4882a593Smuzhiyun covers all VRFs. The l3mdev rule is created for IPv4 and IPv6 on first 163*4882a593Smuzhiyun device create. 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun2. List VRFs 166*4882a593Smuzhiyun 167*4882a593Smuzhiyun To list VRFs that have been created:: 168*4882a593Smuzhiyun 169*4882a593Smuzhiyun $ ip [-d] link show type vrf 170*4882a593Smuzhiyun NOTE: The -d option is needed to show the table id 171*4882a593Smuzhiyun 172*4882a593Smuzhiyun For example:: 173*4882a593Smuzhiyun 174*4882a593Smuzhiyun $ ip -d link show type vrf 175*4882a593Smuzhiyun 11: mgmt: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 176*4882a593Smuzhiyun link/ether 72:b3:ba:91:e2:24 brd ff:ff:ff:ff:ff:ff promiscuity 0 177*4882a593Smuzhiyun vrf table 1 addrgenmode eui64 178*4882a593Smuzhiyun 12: red: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 179*4882a593Smuzhiyun link/ether b6:6f:6e:f6:da:73 brd ff:ff:ff:ff:ff:ff promiscuity 0 180*4882a593Smuzhiyun vrf table 10 addrgenmode eui64 181*4882a593Smuzhiyun 13: blue: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 182*4882a593Smuzhiyun link/ether 36:62:e8:7d:bb:8c brd ff:ff:ff:ff:ff:ff promiscuity 0 183*4882a593Smuzhiyun vrf table 66 addrgenmode eui64 184*4882a593Smuzhiyun 14: green: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 185*4882a593Smuzhiyun link/ether e6:28:b8:63:70:bb brd ff:ff:ff:ff:ff:ff promiscuity 0 186*4882a593Smuzhiyun vrf table 81 addrgenmode eui64 187*4882a593Smuzhiyun 188*4882a593Smuzhiyun 189*4882a593Smuzhiyun Or in brief output:: 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun $ ip -br link show type vrf 192*4882a593Smuzhiyun mgmt UP 72:b3:ba:91:e2:24 <NOARP,MASTER,UP,LOWER_UP> 193*4882a593Smuzhiyun red UP b6:6f:6e:f6:da:73 <NOARP,MASTER,UP,LOWER_UP> 194*4882a593Smuzhiyun blue UP 36:62:e8:7d:bb:8c <NOARP,MASTER,UP,LOWER_UP> 195*4882a593Smuzhiyun green UP e6:28:b8:63:70:bb <NOARP,MASTER,UP,LOWER_UP> 196*4882a593Smuzhiyun 197*4882a593Smuzhiyun 198*4882a593Smuzhiyun3. Assign a Network Interface to a VRF 199*4882a593Smuzhiyun 200*4882a593Smuzhiyun Network interfaces are assigned to a VRF by enslaving the netdevice to a 201*4882a593Smuzhiyun VRF device:: 202*4882a593Smuzhiyun 203*4882a593Smuzhiyun $ ip link set dev NAME master NAME 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun On enslavement connected and local routes are automatically moved to the 206*4882a593Smuzhiyun table associated with the VRF device. 207*4882a593Smuzhiyun 208*4882a593Smuzhiyun For example:: 209*4882a593Smuzhiyun 210*4882a593Smuzhiyun $ ip link set dev eth0 master mgmt 211*4882a593Smuzhiyun 212*4882a593Smuzhiyun 213*4882a593Smuzhiyun4. Show Devices Assigned to a VRF 214*4882a593Smuzhiyun 215*4882a593Smuzhiyun To show devices that have been assigned to a specific VRF add the master 216*4882a593Smuzhiyun option to the ip command:: 217*4882a593Smuzhiyun 218*4882a593Smuzhiyun $ ip link show vrf NAME 219*4882a593Smuzhiyun $ ip link show master NAME 220*4882a593Smuzhiyun 221*4882a593Smuzhiyun For example:: 222*4882a593Smuzhiyun 223*4882a593Smuzhiyun $ ip link show vrf red 224*4882a593Smuzhiyun 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master red state UP mode DEFAULT group default qlen 1000 225*4882a593Smuzhiyun link/ether 02:00:00:00:02:02 brd ff:ff:ff:ff:ff:ff 226*4882a593Smuzhiyun 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master red state UP mode DEFAULT group default qlen 1000 227*4882a593Smuzhiyun link/ether 02:00:00:00:02:03 brd ff:ff:ff:ff:ff:ff 228*4882a593Smuzhiyun 7: eth5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master red state DOWN mode DEFAULT group default qlen 1000 229*4882a593Smuzhiyun link/ether 02:00:00:00:02:06 brd ff:ff:ff:ff:ff:ff 230*4882a593Smuzhiyun 231*4882a593Smuzhiyun 232*4882a593Smuzhiyun Or using the brief output:: 233*4882a593Smuzhiyun 234*4882a593Smuzhiyun $ ip -br link show vrf red 235*4882a593Smuzhiyun eth1 UP 02:00:00:00:02:02 <BROADCAST,MULTICAST,UP,LOWER_UP> 236*4882a593Smuzhiyun eth2 UP 02:00:00:00:02:03 <BROADCAST,MULTICAST,UP,LOWER_UP> 237*4882a593Smuzhiyun eth5 DOWN 02:00:00:00:02:06 <BROADCAST,MULTICAST> 238*4882a593Smuzhiyun 239*4882a593Smuzhiyun 240*4882a593Smuzhiyun5. Show Neighbor Entries for a VRF 241*4882a593Smuzhiyun 242*4882a593Smuzhiyun To list neighbor entries associated with devices enslaved to a VRF device 243*4882a593Smuzhiyun add the master option to the ip command:: 244*4882a593Smuzhiyun 245*4882a593Smuzhiyun $ ip [-6] neigh show vrf NAME 246*4882a593Smuzhiyun $ ip [-6] neigh show master NAME 247*4882a593Smuzhiyun 248*4882a593Smuzhiyun For example:: 249*4882a593Smuzhiyun 250*4882a593Smuzhiyun $ ip neigh show vrf red 251*4882a593Smuzhiyun 10.2.1.254 dev eth1 lladdr a6:d9:c7:4f:06:23 REACHABLE 252*4882a593Smuzhiyun 10.2.2.254 dev eth2 lladdr 5e:54:01:6a:ee:80 REACHABLE 253*4882a593Smuzhiyun 254*4882a593Smuzhiyun $ ip -6 neigh show vrf red 255*4882a593Smuzhiyun 2002:1::64 dev eth1 lladdr a6:d9:c7:4f:06:23 REACHABLE 256*4882a593Smuzhiyun 257*4882a593Smuzhiyun 258*4882a593Smuzhiyun6. Show Addresses for a VRF 259*4882a593Smuzhiyun 260*4882a593Smuzhiyun To show addresses for interfaces associated with a VRF add the master 261*4882a593Smuzhiyun option to the ip command:: 262*4882a593Smuzhiyun 263*4882a593Smuzhiyun $ ip addr show vrf NAME 264*4882a593Smuzhiyun $ ip addr show master NAME 265*4882a593Smuzhiyun 266*4882a593Smuzhiyun For example:: 267*4882a593Smuzhiyun 268*4882a593Smuzhiyun $ ip addr show vrf red 269*4882a593Smuzhiyun 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master red state UP group default qlen 1000 270*4882a593Smuzhiyun link/ether 02:00:00:00:02:02 brd ff:ff:ff:ff:ff:ff 271*4882a593Smuzhiyun inet 10.2.1.2/24 brd 10.2.1.255 scope global eth1 272*4882a593Smuzhiyun valid_lft forever preferred_lft forever 273*4882a593Smuzhiyun inet6 2002:1::2/120 scope global 274*4882a593Smuzhiyun valid_lft forever preferred_lft forever 275*4882a593Smuzhiyun inet6 fe80::ff:fe00:202/64 scope link 276*4882a593Smuzhiyun valid_lft forever preferred_lft forever 277*4882a593Smuzhiyun 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master red state UP group default qlen 1000 278*4882a593Smuzhiyun link/ether 02:00:00:00:02:03 brd ff:ff:ff:ff:ff:ff 279*4882a593Smuzhiyun inet 10.2.2.2/24 brd 10.2.2.255 scope global eth2 280*4882a593Smuzhiyun valid_lft forever preferred_lft forever 281*4882a593Smuzhiyun inet6 2002:2::2/120 scope global 282*4882a593Smuzhiyun valid_lft forever preferred_lft forever 283*4882a593Smuzhiyun inet6 fe80::ff:fe00:203/64 scope link 284*4882a593Smuzhiyun valid_lft forever preferred_lft forever 285*4882a593Smuzhiyun 7: eth5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master red state DOWN group default qlen 1000 286*4882a593Smuzhiyun link/ether 02:00:00:00:02:06 brd ff:ff:ff:ff:ff:ff 287*4882a593Smuzhiyun 288*4882a593Smuzhiyun Or in brief format:: 289*4882a593Smuzhiyun 290*4882a593Smuzhiyun $ ip -br addr show vrf red 291*4882a593Smuzhiyun eth1 UP 10.2.1.2/24 2002:1::2/120 fe80::ff:fe00:202/64 292*4882a593Smuzhiyun eth2 UP 10.2.2.2/24 2002:2::2/120 fe80::ff:fe00:203/64 293*4882a593Smuzhiyun eth5 DOWN 294*4882a593Smuzhiyun 295*4882a593Smuzhiyun 296*4882a593Smuzhiyun7. Show Routes for a VRF 297*4882a593Smuzhiyun 298*4882a593Smuzhiyun To show routes for a VRF use the ip command to display the table associated 299*4882a593Smuzhiyun with the VRF device:: 300*4882a593Smuzhiyun 301*4882a593Smuzhiyun $ ip [-6] route show vrf NAME 302*4882a593Smuzhiyun $ ip [-6] route show table ID 303*4882a593Smuzhiyun 304*4882a593Smuzhiyun For example:: 305*4882a593Smuzhiyun 306*4882a593Smuzhiyun $ ip route show vrf red 307*4882a593Smuzhiyun unreachable default metric 4278198272 308*4882a593Smuzhiyun broadcast 10.2.1.0 dev eth1 proto kernel scope link src 10.2.1.2 309*4882a593Smuzhiyun 10.2.1.0/24 dev eth1 proto kernel scope link src 10.2.1.2 310*4882a593Smuzhiyun local 10.2.1.2 dev eth1 proto kernel scope host src 10.2.1.2 311*4882a593Smuzhiyun broadcast 10.2.1.255 dev eth1 proto kernel scope link src 10.2.1.2 312*4882a593Smuzhiyun broadcast 10.2.2.0 dev eth2 proto kernel scope link src 10.2.2.2 313*4882a593Smuzhiyun 10.2.2.0/24 dev eth2 proto kernel scope link src 10.2.2.2 314*4882a593Smuzhiyun local 10.2.2.2 dev eth2 proto kernel scope host src 10.2.2.2 315*4882a593Smuzhiyun broadcast 10.2.2.255 dev eth2 proto kernel scope link src 10.2.2.2 316*4882a593Smuzhiyun 317*4882a593Smuzhiyun $ ip -6 route show vrf red 318*4882a593Smuzhiyun local 2002:1:: dev lo proto none metric 0 pref medium 319*4882a593Smuzhiyun local 2002:1::2 dev lo proto none metric 0 pref medium 320*4882a593Smuzhiyun 2002:1::/120 dev eth1 proto kernel metric 256 pref medium 321*4882a593Smuzhiyun local 2002:2:: dev lo proto none metric 0 pref medium 322*4882a593Smuzhiyun local 2002:2::2 dev lo proto none metric 0 pref medium 323*4882a593Smuzhiyun 2002:2::/120 dev eth2 proto kernel metric 256 pref medium 324*4882a593Smuzhiyun local fe80:: dev lo proto none metric 0 pref medium 325*4882a593Smuzhiyun local fe80:: dev lo proto none metric 0 pref medium 326*4882a593Smuzhiyun local fe80::ff:fe00:202 dev lo proto none metric 0 pref medium 327*4882a593Smuzhiyun local fe80::ff:fe00:203 dev lo proto none metric 0 pref medium 328*4882a593Smuzhiyun fe80::/64 dev eth1 proto kernel metric 256 pref medium 329*4882a593Smuzhiyun fe80::/64 dev eth2 proto kernel metric 256 pref medium 330*4882a593Smuzhiyun ff00::/8 dev red metric 256 pref medium 331*4882a593Smuzhiyun ff00::/8 dev eth1 metric 256 pref medium 332*4882a593Smuzhiyun ff00::/8 dev eth2 metric 256 pref medium 333*4882a593Smuzhiyun unreachable default dev lo metric 4278198272 error -101 pref medium 334*4882a593Smuzhiyun 335*4882a593Smuzhiyun8. Route Lookup for a VRF 336*4882a593Smuzhiyun 337*4882a593Smuzhiyun A test route lookup can be done for a VRF:: 338*4882a593Smuzhiyun 339*4882a593Smuzhiyun $ ip [-6] route get vrf NAME ADDRESS 340*4882a593Smuzhiyun $ ip [-6] route get oif NAME ADDRESS 341*4882a593Smuzhiyun 342*4882a593Smuzhiyun For example:: 343*4882a593Smuzhiyun 344*4882a593Smuzhiyun $ ip route get 10.2.1.40 vrf red 345*4882a593Smuzhiyun 10.2.1.40 dev eth1 table red src 10.2.1.2 346*4882a593Smuzhiyun cache 347*4882a593Smuzhiyun 348*4882a593Smuzhiyun $ ip -6 route get 2002:1::32 vrf red 349*4882a593Smuzhiyun 2002:1::32 from :: dev eth1 table red proto kernel src 2002:1::2 metric 256 pref medium 350*4882a593Smuzhiyun 351*4882a593Smuzhiyun 352*4882a593Smuzhiyun9. Removing Network Interface from a VRF 353*4882a593Smuzhiyun 354*4882a593Smuzhiyun Network interfaces are removed from a VRF by breaking the enslavement to 355*4882a593Smuzhiyun the VRF device:: 356*4882a593Smuzhiyun 357*4882a593Smuzhiyun $ ip link set dev NAME nomaster 358*4882a593Smuzhiyun 359*4882a593Smuzhiyun Connected routes are moved back to the default table and local entries are 360*4882a593Smuzhiyun moved to the local table. 361*4882a593Smuzhiyun 362*4882a593Smuzhiyun For example:: 363*4882a593Smuzhiyun 364*4882a593Smuzhiyun $ ip link set dev eth0 nomaster 365*4882a593Smuzhiyun 366*4882a593Smuzhiyun-------------------------------------------------------------------------------- 367*4882a593Smuzhiyun 368*4882a593SmuzhiyunCommands used in this example:: 369*4882a593Smuzhiyun 370*4882a593Smuzhiyun cat >> /etc/iproute2/rt_tables.d/vrf.conf <<EOF 371*4882a593Smuzhiyun 1 mgmt 372*4882a593Smuzhiyun 10 red 373*4882a593Smuzhiyun 66 blue 374*4882a593Smuzhiyun 81 green 375*4882a593Smuzhiyun EOF 376*4882a593Smuzhiyun 377*4882a593Smuzhiyun function vrf_create 378*4882a593Smuzhiyun { 379*4882a593Smuzhiyun VRF=$1 380*4882a593Smuzhiyun TBID=$2 381*4882a593Smuzhiyun 382*4882a593Smuzhiyun # create VRF device 383*4882a593Smuzhiyun ip link add ${VRF} type vrf table ${TBID} 384*4882a593Smuzhiyun 385*4882a593Smuzhiyun if [ "${VRF}" != "mgmt" ]; then 386*4882a593Smuzhiyun ip route add table ${TBID} unreachable default metric 4278198272 387*4882a593Smuzhiyun fi 388*4882a593Smuzhiyun ip link set dev ${VRF} up 389*4882a593Smuzhiyun } 390*4882a593Smuzhiyun 391*4882a593Smuzhiyun vrf_create mgmt 1 392*4882a593Smuzhiyun ip link set dev eth0 master mgmt 393*4882a593Smuzhiyun 394*4882a593Smuzhiyun vrf_create red 10 395*4882a593Smuzhiyun ip link set dev eth1 master red 396*4882a593Smuzhiyun ip link set dev eth2 master red 397*4882a593Smuzhiyun ip link set dev eth5 master red 398*4882a593Smuzhiyun 399*4882a593Smuzhiyun vrf_create blue 66 400*4882a593Smuzhiyun ip link set dev eth3 master blue 401*4882a593Smuzhiyun 402*4882a593Smuzhiyun vrf_create green 81 403*4882a593Smuzhiyun ip link set dev eth4 master green 404*4882a593Smuzhiyun 405*4882a593Smuzhiyun 406*4882a593Smuzhiyun Interface addresses from /etc/network/interfaces: 407*4882a593Smuzhiyun auto eth0 408*4882a593Smuzhiyun iface eth0 inet static 409*4882a593Smuzhiyun address 10.0.0.2 410*4882a593Smuzhiyun netmask 255.255.255.0 411*4882a593Smuzhiyun gateway 10.0.0.254 412*4882a593Smuzhiyun 413*4882a593Smuzhiyun iface eth0 inet6 static 414*4882a593Smuzhiyun address 2000:1::2 415*4882a593Smuzhiyun netmask 120 416*4882a593Smuzhiyun 417*4882a593Smuzhiyun auto eth1 418*4882a593Smuzhiyun iface eth1 inet static 419*4882a593Smuzhiyun address 10.2.1.2 420*4882a593Smuzhiyun netmask 255.255.255.0 421*4882a593Smuzhiyun 422*4882a593Smuzhiyun iface eth1 inet6 static 423*4882a593Smuzhiyun address 2002:1::2 424*4882a593Smuzhiyun netmask 120 425*4882a593Smuzhiyun 426*4882a593Smuzhiyun auto eth2 427*4882a593Smuzhiyun iface eth2 inet static 428*4882a593Smuzhiyun address 10.2.2.2 429*4882a593Smuzhiyun netmask 255.255.255.0 430*4882a593Smuzhiyun 431*4882a593Smuzhiyun iface eth2 inet6 static 432*4882a593Smuzhiyun address 2002:2::2 433*4882a593Smuzhiyun netmask 120 434*4882a593Smuzhiyun 435*4882a593Smuzhiyun auto eth3 436*4882a593Smuzhiyun iface eth3 inet static 437*4882a593Smuzhiyun address 10.2.3.2 438*4882a593Smuzhiyun netmask 255.255.255.0 439*4882a593Smuzhiyun 440*4882a593Smuzhiyun iface eth3 inet6 static 441*4882a593Smuzhiyun address 2002:3::2 442*4882a593Smuzhiyun netmask 120 443*4882a593Smuzhiyun 444*4882a593Smuzhiyun auto eth4 445*4882a593Smuzhiyun iface eth4 inet static 446*4882a593Smuzhiyun address 10.2.4.2 447*4882a593Smuzhiyun netmask 255.255.255.0 448*4882a593Smuzhiyun 449*4882a593Smuzhiyun iface eth4 inet6 static 450*4882a593Smuzhiyun address 2002:4::2 451*4882a593Smuzhiyun netmask 120 452