Routing Policies could be used to tell the router (self or neighbors) what routes and their attributes needs to be put into the routing table.
There could be a wide range of routing policies. Some examples are below:
- Set some metric to routes learned from a particular neighbor
- Set some attributes (like AS PATH or Community value) to advertised routes to neighbors
- Prefer a specific routing protocol routes over another routing protocol running on the same router
Routing Policy Example¶
#Create policy set policy route-map setmet rule 2 action 'permit' set policy route-map setmet rule 2 set as-path-prepend '2 2 2' #Apply policy to BGP set protocols bgp 1 neighbor 126.96.36.199 address-family ipv4-unicast route-map import 'setmet' set protocols bgp 1 neighbor 188.8.131.52 address-family ipv4-unicast soft-reconfiguration 'inbound' <<<< *** *** get policy update without bouncing the neighbor
Routes learned before routing policy applied:
vyos@vos1:~$ show ip bgp BGP table version is 0, local router ID is 192.168.56.101 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, R Removed Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 184.108.40.206/32 220.127.116.11 1 0 2 i < Path Total number of prefixes 1
Routes learned after routing policy applied:
vyos@vos1:~$ sho ip b BGP table version is 0, local router ID is 192.168.56.101 Status codes: s suppressed, d damped, h history, * valid, > best, i - internal, r RIB-failure, S Stale, R Removed Origin codes: i - IGP, e - EGP, ? - incomplete Network Next Hop Metric LocPrf Weight Path *> 18.104.22.168/32 22.214.171.124 1 0 2 2 2 2 i < longer AS_path length Total number of prefixes 1 vyos@vos1:~$
Policy-Based Routing (PBR)¶
VyOS supports Policy Routing, allowing traffic to be assigned to a different routing table. Traffic can be matched using standard 5-tuple matching (source address, destination address, protocol, source port, destination port).
The following example will show how VyOS can be used to redirect web traffic to an external transparent proxy:
set policy route FILTER-WEB rule 1000 destination port 80 set policy route FILTER-WEB rule 1000 protocol tcp set policy route FILTER-WEB rule 1000 set table 100
This creates a route policy called FILTER-WEB with one rule to set the routing table for matching traffic (TCP port 80) to table ID 100 instead of the default routing table.
To create routing table 100 and add a new default gateway to be used by traffic matching our route policy:
set protocols static table 100 route 0.0.0.0/0 next-hop 10.255.0.2
This can be confirmed using the show ip route table 100 operational command.
Finally, to apply the policy route to ingress traffic on our LAN interface, we use:
set interfaces ethernet eth1 policy route FILTER-WEB