I have a quick question regarding the behaviour of priority when using policy based routing. I'm running Ubuntu 18.04 (kernel is 4.15.0-1021-aws).

I'm using this machine as a gateway to forward packets from one interface to another. Let's say eth0 -> eth1.

For packets generated by the machine itself, I don't want them to be routed through eth1 ever. However, packets originating from different machines (in the same subnet as eth0, need to be routed through eth1.

The ip address of eth0 is The routing table for forwarding packets is called forwarded. So I have added the following rules:

0:  from all lookup local 
1:  from lookup default 
10: from lookup forwarded 
32766:  from all lookup main 
32767:  from all lookup default 

However, when I try and ping from this machine, it uses the forwarded routing table. Is there a way of doing this or have I made some error here?


Packets created on the local machine first of all recieve as source ip, which is called the unspecified address and this address is at some point replaced by the kernel with the ip of the interface through which the packet leaves the machine.

To properly route the local sourcing packets it is often helpful to use a from rule to delegate those in the right direction. This is escpecially important for packets from services which are not bound to a specific interface interface ip.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.