I'm playing with iptables and routing.
So I have an Ubuntu machine with 2 interface eth0(192.168.2.100, gw 192.168.2.1) and tun0(10.7.7.2, gw 10.7.7.1).
I want traffic to this site ifconfig.me go via tun0(10.7.7.1) and ipinfo.io via eth0(192.168.2.1)
So I did:
I created new entry in /etc/iproute2/rt_tables
:
echo 1 vpn >> /etc/iproute2/rt_tables
Then I added default route to new table:
ip route add default via 10.7.7.1 dev tun0 table vpn
I added rule so all packets with makr 1 are going to be routed via table vpn:
ip rule add fwmark 0x1 table vpn
And I mark all outgoing traffic to ifconfig.me with mark 1:
iptables -A OUTPUT -t mangle -d ifconfig.me -j MARK --set-mark 1
When I do curl to ipinfo.io curl ipinfo.io
I get correct IP back, form gateway provided by eth0, but when I try to get a response from ifconfig.me curl ifconfig.me
nothing is happening(i think its timing out). So it looks that traffic is going via the correct table but it stops there.
ip route show table vpn
:
default via 10.7.7.1 dev tun0