Virtual Routing and Forwarding (VRF)
Virtual Routing and Forwarding (VRF)
Section titled âVirtual Routing and Forwarding (VRF)âTL;DR (Quick Start)
Section titled âTL;DR (Quick Start)âFor the impatient: isolate an interface into its own routing domain.
# Create VRF and assign interface/ip vrf add name=customer1 interfaces=ether2
# Add IP address (automatically uses VRF's routing table)/ip address add address=192.168.100.1/24 interface=ether2
# Verify VRF routes/ip route print where routing-table=customer1Overview
Section titled âOverviewâWhat this does: Virtual Routing and Forwarding (VRF) creates multiple independent routing tables on a single router. Each VRF operates as if it were a separate router, with its own routing table, interfaces, and forwarding decisions. Traffic in one VRF cannot reach another VRF unless explicitly configured (route leaking).
When to use this:
- Service provider networks - Isolate customer traffic on shared infrastructure
- Multi-tenant environments - Separate routing for different clients
- Management networks - Isolate management traffic from production
- Overlapping IP spaces - Support multiple networks using the same address ranges
- BGP/MPLS VPNs - L3VPN implementation with route distinguishers
Prerequisites:
- RouterOS 7.0 or newer (v6 uses different routing-mark approach)
- Understanding of routing tables and IP addressing
- For BGP VPN: BGP package and MPLS configuration
7.14 Firewall Changes
RouterOS 7.14 introduced significant changes to how VRFs interact with firewalls. When interfaces are added to a VRF, firewall rules must reference the VRF virtual interface instead of individual physical interfaces. Review the Firewall Integration section if upgrading.
Key Concepts
Section titled âKey ConceptsâVRF vs Routing Table
Section titled âVRF vs Routing TableâIn RouterOS, creating a VRF automatically creates a corresponding routing table with the same name. The VRF defines which interfaces belong to the isolated network domain, while the routing table holds the routes for that domain.
Route Distinguisher (RD)
Section titled âRoute Distinguisher (RD)âFor BGP/MPLS VPN configurations, the Route Distinguisher makes routes globally unique even when IP prefixes overlap between VRFs. Format: ASN:number or IP:number (e.g., 65000:1 or 10.0.0.1:1).
Route Targets (RT)
Section titled âRoute Targets (RT)âControl which routes are imported/exported between VRFs in BGP VPN configurations. Import RT determines which routes a VRF accepts; export RT tags routes leaving a VRF.
Configuration Steps
Section titled âConfiguration StepsâStep 1: Create a VRF Instance
Section titled âStep 1: Create a VRF Instanceâ/ip vrf add name=customer1 interfaces=ether2,ether3This creates:
- A VRF named âcustomer1â
- Associates ether2 and ether3 with this VRF
- Automatically creates a routing table named âcustomer1â
Step 2: Verify VRF Creation
Section titled âStep 2: Verify VRF Creationâ/ip vrf printExpected Output:
Flags: X - disabled # NAME INTERFACES 0 customer1 ether2,ether3Step 3: Check Routing Table Created
Section titled âStep 3: Check Routing Table Createdâ/routing table printExpected Output:
# NAME FIB 0 main 1 customer1Step 4: Add Routes to the VRF
Section titled âStep 4: Add Routes to the VRFâRoutes for VRF interfaces are automatically added to the VRFâs routing table. To add static routes:
/ip route add dst-address=10.0.0.0/24 gateway=192.168.1.1 routing-table=customer1Step 5: Verify Routes in VRF
Section titled âStep 5: Verify Routes in VRFâ/ip route print where routing-table=customer1Common Configuration Scenarios
Section titled âCommon Configuration ScenariosâScenario 1: Basic VRF Isolation
Section titled âScenario 1: Basic VRF IsolationâIsolate two customer networks on the same router:
# Create VRFs/ip vrf add name=customer1 interfaces=ether2/ip vrf add name=customer2 interfaces=ether3
# Add addresses (each in its own VRF context)/ip address add address=192.168.1.1/24 interface=ether2/ip address add address=192.168.1.1/24 interface=ether3
# Note: Same IP range works because they're in different VRFsScenario 2: VRF with Internet Access (Route Leaking)
Section titled âScenario 2: VRF with Internet Access (Route Leaking)âProvide internet access to a VRF using the main routing tableâs default gateway:
# Create VRF/ip vrf add name=customer1 interfaces=ether2
# Add customer gateway address/ip address add address=192.168.100.1/24 interface=ether2
# Add default route that resolves in main table (note @main)/ip route add dst-address=0.0.0.0/0 gateway=10.0.0.1@main routing-table=customer1
# Configure NAT for customer traffic/ip firewall nat add chain=srcnat out-interface=ether1-wan action=masqueradeKey syntax: gateway=IP@table specifies which routing table resolves the gateway.
Scenario 3: VRF with DHCP Server
Section titled âScenario 3: VRF with DHCP ServerâRun a DHCP server within a VRF:
# Create VRF and assign interface/ip vrf add name=customer1 interfaces=ether2
# Add IP address/ip address add address=192.168.100.1/24 interface=ether2
# Create DHCP pool/ip pool add name=customer1-pool ranges=192.168.100.100-192.168.100.200
# Configure DHCP server (uses VRF automatically via interface)/ip dhcp-server add name=customer1-dhcp interface=ether2 address-pool=customer1-pool
# Add DHCP network/ip dhcp-server network add address=192.168.100.0/24 gateway=192.168.100.1 dns-server=8.8.8.8Scenario 4: BGP VPN with Route Distinguisher
Section titled âScenario 4: BGP VPN with Route DistinguisherâFor MPLS L3VPN configurations:
# Create VRF with route distinguisher/ip vrf add name=customer1 interfaces=ether2
# Configure route distinguisher and targets/ip route vrfadd vrf=customer1 route-distinguisher=65000:1 \ import-route-targets=65000:1 export-route-targets=65000:1Scenario 5: Services Bound to VRF
Section titled âScenario 5: Services Bound to VRFâBind services to listen on specific VRF:
# DNS server in VRF/ip dns set servers=8.8.8.8 vrf=customer1
# SSH listening on VRF/ip service set ssh address=0.0.0.0/0 vrf=customer1
# Or use @vrf syntax for one-off operations/tool fetch url="http://example.com" vrf=customer1Firewall Integration
Section titled âFirewall IntegrationâRouterOS 7.14+ Changes
Section titled âRouterOS 7.14+ ChangesâStarting with RouterOS 7.14, when interfaces are added to a VRF, a virtual VRF interface is automatically created. Firewall rules must reference this VRF interface instead of individual physical interfaces.
Before 7.14:
# Matched individual interfaces in VRF/ip firewall filter add chain=input in-interface=ether2 action=acceptAfter 7.14:
# Must match VRF virtual interface/ip firewall filter add chain=input in-interface=customer1 action=acceptMatching Specific Interfaces Within VRF
Section titled âMatching Specific Interfaces Within VRFâTo match specific physical interfaces within a VRF (7.14+), use connection marking:
# Mark connections from specific interface/ip firewall mangle add chain=prerouting in-interface=ether2 action=mark-connection new-connection-mark=from-ether2
# Then filter based on connection mark/ip firewall filter add chain=forward connection-mark=from-ether2 action=acceptNAT with VRF
Section titled âNAT with VRFâ# Masquerade traffic from VRF going to internet/ip firewall nat add chain=srcnat out-interface=ether1-wan src-address=192.168.100.0/24 action=masqueradeVerification
Section titled âVerificationâCheck 1: Verify VRF Configuration
Section titled âCheck 1: Verify VRF Configurationâ/ip vrf printExpected: VRF listed with correct interfaces.
Check 2: Verify Routing Tables
Section titled âCheck 2: Verify Routing Tablesâ/routing table printExpected: Each VRF has a corresponding routing table.
Check 3: Check Routes in VRF
Section titled âCheck 3: Check Routes in VRFâ/ip route print where routing-table=customer1Expected: Routes specific to the VRF, including connected routes for assigned interfaces.
Check 4: Test Connectivity from VRF
Section titled âCheck 4: Test Connectivity from VRFâ/ping 8.8.8.8 vrf=customer1Expected: Successful if VRF has internet access configured.
Check 5: Verify Interface Assignment
Section titled âCheck 5: Verify Interface Assignmentâ/ip address print detail where interface=ether2Expected: Shows actual-interface reflecting VRF membership.
Troubleshooting
Section titled âTroubleshootingâ| Symptom | Cause | Solution |
|---|---|---|
| Routes not active in VRF | Gateway looking in wrong routing table | Use gateway=IP@main to specify table for gateway resolution |
| VRF interface not in firewall list (7.14+) | 7.14 changed interface behavior | Use VRF name as interface: in-interface=customer1 |
| Services not accessible in VRF | Service not bound to VRF | Configure vrf= parameter on service |
| Overlapping addresses conflicting | Interface not in VRF when address added | Create VRF before adding IP addresses |
| Wrong VRF matched | VRF matching is top-to-bottom | Reorder VRFs with /ip vrf move |
| Firewall rules broken after 7.14 upgrade | Interface matching changed | Use VRF virtual interface or connection marks |
| Ping fails from VRF | Tool using main table | Specify VRF: /ping 8.8.8.8 vrf=customer1 |
Debug: Gateway Resolution
Section titled âDebug: Gateway ResolutionâIf routes show inactive, check gateway resolution:
# Wrong - gateway looks in customer1 table where it doesn't exist/ip route add dst-address=0.0.0.0/0 gateway=10.0.0.1 routing-table=customer1
# Right - gateway explicitly resolves in main table/ip route add dst-address=0.0.0.0/0 gateway=10.0.0.1@main routing-table=customer1Debug: VRF Order
Section titled âDebug: VRF OrderâCheck current VRF order:
/ip vrf printMove specific VRF to top for priority matching:
/ip vrf move [find name=specific-vrf] destination=0Common Mistakes
- Forgetting @table for gateway resolution - Use
gateway=10.0.0.1@mainwhen the gateway is in a different routing table - Adding address before VRF assignment - Always create VRF and assign interface first, then add IP addresses
- Using physical interface in firewall (7.14+) - After 7.14, use VRF name (
in-interface=customer1) not physical interface - Expecting automatic NAT isolation - NAT rules must explicitly reference VRF source addresses
- Not specifying VRF for diagnostic tools - Use
vrf=parameter:/ping 8.8.8.8 vrf=customer1 - Assuming services automatically use VRF - Most services require explicit
vrf=configuration
Services with VRF Support
Section titled âServices with VRF Supportâ| Service | VRF Parameter | Notes |
|---|---|---|
| BGP | Per-connection | Full VRF support |
| OSPF | vrf | Per-instance |
| DNS | vrf | Client and server |
| DHCP Relay | vrf | Added in 7.15 |
| SSH/Telnet/WWW | vrf | Via /ip service |
| NTP | vrf | Client and server |
| SNMP | vrf | |
| RADIUS | vrf | |
| Ping/Traceroute | vrf | Diagnostic tools |
| Fetch | vrf | HTTP client |
| Netwatch | vrf | Monitoring |
Limitations
Section titled âLimitationsâ- Maximum 1024 VRF instances (routing table limit)
- Not all services support VRF (check documentation)
- VRF order matters - matching is top-to-bottom
- RouterOS 7.14+ changed firewall interface matching behavior
- Some features require specific RouterOS versions for VRF support
Related Topics
Section titled âRelated TopicsâRouting
Section titled âRoutingâ- Static Routes - basic routing configuration
- Routing Tables - multiple routing table management
- Routing Rules - policy-based routing
- BGP - BGP configuration for VPN
Network Services
Section titled âNetwork Servicesâ- DHCP Relay - DHCP relay with VRF support (7.15+)
- DHCP Server - per-VRF DHCP services
- DNS Server - DNS with VRF
Security
Section titled âSecurityâ- Firewall Basics - firewall rules with VRF
- IP Services - VRF-bound management services
Reference
Section titled âReferenceâVRF Properties (/ip vrf)
Section titled âVRF Properties (/ip vrf)â| Property | Type | Default | Description |
|---|---|---|---|
name | string | - | VRF identifier (also becomes routing table name) |
interfaces | list | - | Interfaces assigned to this VRF |
disabled | yes/no | no | Disable VRF |
Route VRF Properties (/ip route vrf)
Section titled âRoute VRF Properties (/ip route vrf)â| Property | Type | Default | Description |
|---|---|---|---|
vrf | string | - | VRF name reference |
route-distinguisher | string | - | RD format: ASN:number or IP:number |
import-route-targets | list | - | Route targets to import |
export-route-targets | list | - | Route targets to export |
Common VRF Parameters for Services
Section titled âCommon VRF Parameters for Servicesâ| Parameter | Usage | Example |
|---|---|---|
vrf= | Specify VRF for service/command | /ping 8.8.8.8 vrf=customer1 |
@table | Gateway resolution in specific table | gateway=10.0.0.1@main |
routing-table= | Target routing table for routes | routing-table=customer1 |
Commands
Section titled âCommandsâ| Command | Description |
|---|---|
/ip vrf add | Create new VRF |
/ip vrf print | List VRF instances |
/ip vrf move | Reorder VRF (affects matching priority) |
/routing table print | List all routing tables including VRF tables |
/ip route print where routing-table=X | Show routes in specific VRF |