I have VPN network based on OpenVPN software. I need route all network traffic in VPN network where destination IP is from specific country via one specific client on this VPN network (VPN client IP address) - Mikrotik router where is configured NAT (MASQUERADE) for main internet interface (PPPoE). I need get public, dynamic IP address owned by this VPN client (Mikrotik router - PPPoE interface) for all this traffic. So on VPN server I created iptables mangle rule and I use geoip iptables module:
iptables -A PREROUTING -t mangle -i tun0 -m geoip --destination-country COUNTRY_CODE -j MARK --set-mark 1
So I have marked all traffic from client which have destination IP from this specific country. Next I have tried use this solution: Create specific route table and add default route. But default route can be only for next hop on this network. So when I use this command:
ip route add default via specific_VPN_client dev tun0 table CountryRoute
I get this error:
RTNETLINK answers: Network is unreachable
Is possible route specific traffic to specific client, but not to next hop please?
I tried this iptables rule too:
iptables -A PREROUTING -i tun0 -m geoip --destination-country COUNTRY_CODE -j DNAT --to-destination Mikrotik_VPN_IP
But traffic ends on Mikrotik router. Maybe would be possible solve this problem on this router?
OpenVPN server (10.1.1.1) route table:
default via PUBLIC_IP_VPN_SERVER dev eth0
10.1.1.0/24 via 10.1.1.2 dev tun0
10.1.1.2 dev tun0 proto kernel scope link src 10.1.1.1
PUBLIC_IP_VPN_SERVER/24 dev eth0 proto kernel scope link src PUBLIC_IP_VPN_SERVER
UPDATE
I used this solution for adding default route in CountryRoute table. So CountryRoute table has this content:
default via 10.1.1.30 dev tun0
I have active iptables mangle rule (mentioned above) and ip route rules:
ip rule show
0: from all lookup local
32765: from all fwmark 0x1 lookup CountryRoute
32766: from all lookup main
32767: from all lookup default
But marked traffic still ends on 10.1.1.1 - OpenVPN server, it does not continue to Mikrotik router.
UPDATE2
Currently values:
default via PUBLIC_IP_VPN_SERVER dev eth0
10.0.0.0/24 dev veth0 proto kernel scope link src 10.0.0.1
10.0.1.0/24 dev veth3 proto kernel scope link src 10.0.1.2
10.1.1.0/24 via 10.1.1.30 dev tun0
10.1.1.30 dev tun0 proto kernel scope link src 10.1.1.1
PUBLIC_IP_VPN_SERVER/24 dev eth0 proto kernel scope link src PUBLIC_IP_VPN_SERVER
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.1.1.1 P-t-P:10.1.1.30 Mask:255.255.255.255
inet6 addr: PUBLIC_IP_VPN_SERVER/64 Scope:Global
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:141437 errors:0 dropped:0 overruns:0 frame:0
TX packets:230785 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:14693683 (14.0 MiB) TX bytes:240387315 (229.2 MiB)
ip route show table CountryRoute
default via 10.1.1.30 dev tun0
UPDATE 3
ip -4 route show table all
default via 10.0.0.2 dev veth0 table CountryRoute
default via PUBLIC_IP_VPN_SERVER_gateway dev eth0 onlink
10.0.0.0/24 dev veth0 proto kernel scope link src 10.0.0.1
10.0.1.0/24 dev veth3 proto kernel scope link src 10.0.1.2
10.1.1.0/24 via 10.1.1.30 (Mikrotik_VPN_IP) dev tun0
10.1.1.30 dev tun0 proto kernel scope link src 10.1.1.1
PUBLIC_IP_VPN_SERVER/24 dev eth0 proto kernel scope link src PUBLIC_IP_VPN_SERVER
broadcast 10.0.0.0 dev veth0 table local proto kernel scope link src 10.0.0.1
local 10.0.0.1 dev veth0 table local proto kernel scope host src 10.0.0.1
broadcast 10.0.0.255 dev veth0 table local proto kernel scope link src 10.0.0.1
broadcast 10.0.1.0 dev veth3 table local proto kernel scope link src 10.0.1.2
local 10.0.1.2 dev veth3 table local proto kernel scope host src 10.0.1.2
broadcast 10.0.1.255 dev veth3 table local proto kernel scope link src 10.0.1.2
local 10.1.1.1 dev tun0 table local proto kernel scope host src 10.1.1.1
broadcast PUBLIC_IP_VPN_SERVER_networkIP dev eth0 table local proto kernel scope link src PUBLIC_IP_VPN_SERVER
local PUBLIC_IP_VPN_SERVER dev eth0 table local proto kernel scope host src PUBLIC_IP_VPN_SERVER
broadcast PUBLIC_IP_VPN_SERVER_broadcastIP dev eth0 table local proto kernel scope link src PUBLIC_IP_VPN_SERVER
broadcast 127.0.0.0 dev lo table local proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo table local proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo table local proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo table local proto kernel scope link src 127.0.0.1
UPDATE 4
ip netns exec Mikrotik ip -4 route show table all
default via 10.0.1.2 dev veth2
10.0.0.0/24 dev veth1 proto kernel scope link src 10.0.0.2
10.0.1.0/24 dev veth2 proto kernel scope link src 10.0.1.1
10.1.1.30 via 10.0.1.2 dev veth2
broadcast 10.0.0.0 dev veth1 table local proto kernel scope link src 10.0.0.2
local 10.0.0.2 dev veth1 table local proto kernel scope host src 10.0.0.2
broadcast 10.0.0.255 dev veth1 table local proto kernel scope link src 10.0.0.2
broadcast 10.0.1.0 dev veth2 table local proto kernel scope link src 10.0.1.1
local 10.0.1.1 dev veth2 table local proto kernel scope host src 10.0.1.1
broadcast 10.0.1.255 dev veth2 table local proto kernel scope link src 10.0.1.1
UPDATE 5
# ip netns exec Mikrotik traceroute -I 10.1.1.30
traceroute to 10.1.1.30 (10.1.1.30), 30 hops max, 60 byte packets
1 10.0.1.2 (10.0.1.2) 0.053 ms 0.016 ms 0.013 ms
2 10.1.1.30 (10.1.1.30) 18.868 ms 38.147 ms 98.549 ms
# ip netns exec Mikrotik traceroute 10.1.1.30
traceroute to 10.1.1.30 (10.1.1.30), 30 hops max, 60 byte packets
1 10.0.1.2 (10.0.1.2) 0.056 ms 0.019 ms 0.016 ms
2 10.1.1.30 (10.1.1.30) 19.044 ms 37.808 ms 56.347 ms
# ip netns exec Mikrotik traceroute COUNTRY_PUBLIC_IP_MARKED_TRAFFIC
traceroute to COUNTRY_PUBLIC_IP_MARKED_TRAFFIC (COUNTRY_PUBLIC_IP_MARKED_TRAFFIC), 30 hops max, 60 byte packets
1 10.0.1.1 (10.0.1.1) 3052.269 ms !H 3052.212 ms !H 3052.185 ms !H
# ip netns exec Mikrotik traceroute -I COUNTRY_PUBLIC_IP_MARKED_TRAFFIC
traceroute to COUNTRY_PUBLIC_IP_MARKED_TRAFFIC (COUNTRY_PUBLIC_IP_MARKED_TRAFFIC), 30 hops max, 60 byte packets
1 * * *
2 * * *
3 * * *
4 * * *
5 * * *
6 * 10.0.1.1 (10.0.1.1) 3067.929 ms !H 3067.883 ms !H
Thank you for your help.