Some times I want to use the ppp internet connection provided by one 3gdongle connected to my bananapi internet server, without breaking the routing for incoming connections on eth0.
The problem is asymmetric routing caused by the change of the default gateway.
Before the ppp connection the default gateway is the 192.168.1.1. When the connection with ppp is established, it changes the default gateway to 10.64.64.64, so any incoming requests is replied using the new default gateway, and the connection breaks.
- request > eth0 > [HOST] > reply > ppp0
What I want is:
- request > eth0 > [HOST] > reply > eth0
- request > ppp0 > [HOST] > reply > ppp0
So I want : Incoming connection to eth0 when ppp0 is up
The solution is using the Routing Policy Database and Multiple Routing Tables or RPDB.
And it Works!
Implementation tried with:
- eth0: 192.168.1.10 gw 192.168.1.1
- ppp0: 10.206.203.229 gw 10.64.64.64
10.206.255.192
ppp connection handle
ifup gprs ifdown gprs
Some findings
ll /proc/sys/net/ipv4/conf/ cat /proc/sys/net/ipv4/conf/eth0/rp_filter cat /proc/sys/net/ipv4/conf/ppp0/rp_filter #echo 2 >/proc/sys/net/ipv4/conf/eth0/rp_filter #echo 2 >/proc/sys/net/ipv4/conf/ppp0/rp_filter
Implementation
ip route add 192.168.1.0/24 dev eth0 table 1 ip route add default via 192.168.1.1 table 1 ip route add 10.0.0.0/8 dev ppp0 table 2 ip route add default via 10.64.64.64 table 2 ip rule add from 192.168.1.10/32 table 1 priority 100 ip rule add from 10.206.203.229/32 table 2 priority 110 ip route add default via 192.168.1.1
After configuration we need to use the command:
ip route flush cache
Update
As I far as i know this kind of rules are not persistent (i try to handle that later), after some: ifdown gprs and ifup gprs, the symetric route was broken.
The table 2 was lost and need to be recreated with:
ip route add 10.0.0.0/8 dev ppp0 table 2 ip route add default via 10.64.64.64 table 2
The ip change to 10.206.255.192, the table 2 priority 110 need to be inserted with comand:
ip rule add from 10.206.255.192/32 table 2 priority 110
TODO: In order to use always the same commands i shall try to change the command:
ip rule add from 10.206.255.192/32 table 2 priority 110
– to –
ip rule add from 10.206.0.0/16 table 2 priority 110
Usefull commands
ip route flush cache
ip route show table 1
ip route show table 2
ip rule show
To delete rules just change the add for del in the comand issued.
ip rule add from 10.206.255.192/32 table 2 priority 110
– removed with –
ip rule del from 10.206.255.192/32 table 2 priority 110
Get public ip address
wget -qO- http://checkip.dyndns.com/ –bind-address 10.206.x.x
Testing
- ping -I ppp0 google.com (ok)
- ping -I eth0 google.com (ok)
- traceroute -i ppp0 google.com (ok)
- traceroute -i eth0 google.com (ok)
- incoming connection to eth0 when ppp0 is up (ok)
request > eth0 > [HOST] > reply > eth0 - Incoming connection to ppp0 (not tryed, the public ip is random)
request > ppp0 > [HOST] > reply > ppp0
Update: 2017-04-16
After writing this, i notice that i forgot to address my second network on 192.168.0.0/24, and communications to 192.168.1.0/24 network was broken.
To solve i i try these commands:
ip route add 192.168.1.0/24 dev eth0 table 1 ip route add default via 192.168.1.1 table 1 ip route add 192.168.0.0/24 dev eth0 table 2 ip route add default via 192.168.1.254 table 2 ip route add 10.0.0.0/8 dev ppp0 table 3 ip route add default via 10.64.64.64 table 3 ip rule add from 192.168.1.10/32 table 1 priority 100 ip rule add from 192.168.1.10/32 table 1 priority 110 ip rule add from 10.206.255.192/32 table 3 priority 120
And doesn’t work.
On other dongle that have a public ip address (in the other network) i also try:
ip route add 192.168.0.0/24 dev eth0 table 1 ip route add default via 192.168.0.1 table 1 ip route add 192.168.1.0/24 dev eth0 table 2 ip route add default via 192.168.0.1 table 2 ip route add 10.0.0.0/8 dev ppp0 table 3 ip route add default via 10.64.64.64 table 3 ip rule add from 192.168.0.10/32 table 1 priority 100 ip rule add from 192.168.0.10/32 table 2 priority 110 ip rule add from 89.180.3.61/32 table 3 priority 120
And doesn’t work.
Try the bellow one but I lost connection at the last one..
ip route add 192.168.0.0/24 dev eth0 table 1 ip route add 192.168.1.0/24 dev eth0 table 1 ip route add default via 192.168.0.1 table 1 ip route add 89.180.3.61/32 dev ppp0 table 2 ip route add default via 10.64.64.64 table 2 ip rule add from 192.168.0.10/32 table 1 priority 100
Don’t even run the last one:
ip rule add from 89.180.3.61/32 table 2 priority 120
What i dont understand it why?
Did a public ip get priority over private ip as origin?
For now I quit. Maybe later I get on this again.
But for a single network its working good.