D
D
Dmitry2016-11-28 18:21:26
linux
Dmitry, 2016-11-28 18:21:26

How to configure traffic redirection from the main inet interface to the tap interface?

I'm trying to configure not the most popular VPN solution govpn through tap interfaces.
Configured on the server:

ip tuntap add dev tap10 mode tap
ip addr add 172.16.0.1/24 dev tap10
ip link set up dev tap10

Configured on the client:
ip tuntap add dev tap10 mode tap
ip addr add 172.16.0.2/24 dev tap10
ip link set up dev tap10

If added on the client
ip route add 0/1 via 172.16.0.1
ip route add 128/1 via 172.16.0.1

from the tutorial, the network basically stops responding. As I understand it, this is due to the fact that traffic (including the connection to the server) is trying to go through the internal tap10 interface, but it does not know how to route traffic to its own. (The connection of the client to the VPN server with this configuration simply does not occur, the client cannot reach the server).
Without the last two lines, the client can successfully ping the server on 172.16.0.1, but all other Internet traffic goes through the standard interface.
I looked at what the output of ip route looks like when connected via OpenVPN, there 2 lines with default via appear in addition to the rest:
default via <ip на tun0> dev tun0 proto static metric 50
default via <ip на wlp3s0> dev wlp3s0 proto static metric 750

The iptables tables are empty.
There are two questions:
1) How does the system understand that the traffic from the tap / tun interface eventually goes through the interface that has access to the network in the case of OpenVPN at the exit from the tap / tun?
2) How to eventually redirect all Internet traffic through the tap interface? (Main question)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
younghacker, 2016-12-10
@Liro

Before wrapping the default gateway through your tap interface, you first need to add a route to your VPN server through your eth (or whatever you have) network interface and assign the smallest metric to it. After that, add a default gateway through the tap interface and give it a larger metric.
Here is part of my routing table

$ ip route
default via 10.22.0.5 dev tun0
10.22.0.1 via 10.22.0.5 dev tun0
10.22.0.5 dev tun0  proto kernel  scope link  src 10.22.0.6
80.232.124.241 via 172.16.35.1 dev eth0
172.16.35.0/24 dev eth0  proto kernel  scope link  src 172.16.35.254  metric 100

In other words, when your default route is wrapped in a tap interface, the system should not lose the route to the VPN server through the eth interface.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question