# create vrf deviceiplinkaddvrf-bluetypevrftable10iplinksetdevvrf-blueup# An l3mdev FIB rule directs lookups to the table associated with the device.# A single l3mdev rule is sufficient for all VRFs.# Prior to the v4.8 kernel iif and oif rules are needed for each VRF device:ipruaddoifvrf-bluetable10ipruaddiifvrf-bluetable10#Set the default route for the table (and hence default route for the VRF).iprouteaddtable10unreachabledefault# Enslave L3 interfaces to a VRF device.# Local and connected routes for enslaved devices are automatically moved to# the table associated with VRF device. Any additional routes depending on# the enslaved device are dropped and will need to be reinserted to the VRF# FIB table following the enslavement.iplinksetdeveth1mastervrf-blue# The IPv6 sysctl option keep_addr_on_down can be enabled to keep IPv6 global# addresses as VRF enslavement changes.sysctl-wnet.ipv6.conf.all.keep_addr_on_down=1# Additional VRF routes are added to associated table.iprouteaddtable10...
TCP & UDP services running in the default VRF context (ie., not bound to any VRF device) can work across all VRF domains by enabling the tcp_l3mdev_accept and udp_l3mdev_accept sysctl options:
# ip -d link show type vrf
16: vrf-blue: <NOARP,MASTER,UP,LOWER_UP> mtu 65536 qdisc noqueue state UP mode DEFAULT group default qlen 1000
link/ether 9e:9c:8e:7b:32:a4 brd ff:ff:ff:ff:ff:ff promiscuity 0
vrf table 10 addrgenmode eui64
添加网卡到VRF
ip link set dev eth0 master vrf-blue
查询VRF邻接表和路由
ip neigh show vrf vrf-blue
ip addr show vrf vrf-blue
ip -br addr show vrf vrf-blue
ip route show vrf vrf-blue