I have this configuration which comes from official and unofficial guides and questions readings here and a lot of failed tests.
CentOS 7 and Ubuntu server 15 (LAMP and only eth0).
/etc/iproute2/rt_tables
1 tunnel0
I PREPARE THE ROUTES AND MARKS
ip route add 0.0.0.0/0 dev tun0 table 1
ip rule add from all fwmark 1 table 1
ip route flush cache
(also tried to use table ID, to declare via "10.123.123.x" with the tun0 address and the tun0 gateway…)
IPTABLES
iptables -A PREROUTING -t mangle -p tcp --dport 80 -j MARK --set-mark 1
iptables-save
I see the eth0 ISP public IP, instead of tun0, which I can see forcing a "route add" static route. What am I missing? Thank you.
Best Answer
I solved and documented it here: http://aftermanict.blogspot.it/2015/11/bash-iptables-iproute2-and-multiple.html
This will make the kernel permanently route packets, enables multiple routes and even for networks not attested on the machine:
This will initialize iptables and in particular mangle and nat, which are needed for marking the traffic:
add the alternative routes editing:
Add (names are your references):
add routes and rules, we use tables IDs instead of names which are more immediate. As you can notice, the gateway is irrelevant, especially for tunnels which can have dynamic gateways:
add rules to mark traffic and bind to the corresponding table:
check if you like:
if you miss something, you can delete this way:
NOW THE MISSING PART: THIS WONT WORK:
THIS WILL:
Do you need to select traffic and push it simultaneously in a device / tunnel? No problem, I solved this too:
NAT mandatory for reply