Policy-based routing (Linux)

Classic routing
– Happens based on the destination address of the ip packet

Classic routing tables

$ ip rule list
0:	from all lookup local 
32766:	from all lookup main 
32767:	from all lookup default 

The lookup order happens based on the priority (first column): local > main > default.


Policy-based routing
– Allows decision making on other parameters (e.g. source address)
– It requires more routing tables then classic routing

General workflow

  1. Add a new routing table
  2. Add rule(s) towards that table
  3. Add route(s) on that table

Possible scenario

                       PC / Laptop
|-----------------------------------------------------|
|         Webbrowser 1               Webbrowser 2     |
|       (Office content)          (Private content)   |
|               |                          |          |
|               |                        Proxy*       |
|               |                          |          |
|      Network interface 1        Network interface 2 |
| (Network card, eth0, default)     (USB slot, usb0)  |
|-----------------------------------------------------|
                |                          |
           Office LAN                  LTE modem
                | \-- Local server         |
                |                          |
            DSL modem                      |
                |                          |
                \-----------\ /------------/
                             |
                         Internet
                             |
                       Public server


*) Config: Set source ip of outgoing packets to usb0 ip.