Answer the question
In order to leave comments, you need to log in
How to forward traffic from eth0 to tun interface and back?
The scheme is:
Application --- some adaptation layer --- tun-interface(15.0.0.1) --- eth0(192.168.0.1) <-------> WWW(111.222.5.6)
(IP addresses wrote from the bulldozer, just for convenience and to correctly describe the essence of the problem)
The fact is that Application does not suspect that it is behind the tun interface. It thinks it is 192.168.0.1 and sends IP packets with source address=192.168.0.1, destination=111.222.5.6. The adaptation layer writes this packet to tun.
Task: somehow forward this packet from the tun interface to eth0 using iptables.
And the reverse task: a packet source=111.222.5.6, dest=192.168.0.1 comes from the network, it is necessary that the packet goes to the tun interface, and from tun through adaptation it reaches our Application with the same source=111.222.5.6, dest =192.168.0.1 in IP header.
The tun interface refers to the kernel's virtual interface, and eth0 is the real ethernet interface on a real physical network card.
Answer the question
In order to leave comments, you need to log in
Can make a bridge (tun+eth) and assign 192.168.0.1 to it? Then App will actually have 192.168.0.1...
But will it be possible to bridge tun and eth... :)
Or fence SNAT+DNAT...
The fact is that Application does not suspect that it is behind the tun interface. It thinks it is 192.168.0.1 and sends IP packets with source address=192.168.0.1, destination=111.222.5.6.
If I understand your diagram correctly, then something like this.
iptables -t nat -A POSTROUTING -s 15.0.0.0/24 -d 111.222.5.6 -o eth0 --jump SNAT --to-source 192.168.0.1
Traffic coming from tunnel 15.0.0.0/24 and going to 111.222.5.6 we are passing through gw 192.168.0.1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question