Score:1

How to tunnel all the traffic for one interface through another interface

cm flag

I have two working interfaces on my ubuntu machine:

  • tun0 - OpenVPN server with the internal address of: 10.8.0.0/24
  • wg0 - WireGuard peer interface with the internal address of: 10.7.0.0/24 which is connected to an external WireGuard server with a successful handshake.

And I'm trying to tunnel all the requests for tun0 through wg0. So when I connect to the OpenVPN tunnel, it would be as if I'm connected to the WireGuard server.

And this is how my iptables backup looks like before making any changes:

*filter
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -s 10.8.0.0/24 -j ACCEPT
COMMIT
*nat
-A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to-source MACHINE_IP_ADDRESS
COMMIT

So by looking at this I figured if I replaced the MACHINE_IP_ADDRESS with the internal IP of WireGuard connection it might work:

-A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to-source 10.7.0.0

Which did not work. I also tried:

-A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -o wg0

And in both cases, the OpenVPN connection was established but fully timed out.

Is there a way I can achieve this without too much configuration?

Score:0
sv flag

That sounds to me like a "reverse proxy" behavior, you could use Caddy or nginx for this, I think it should be fairly easy, something like:

caddy reverse-proxy --from 10.8.0.0:2080 --to 10.7.0.0:9000

With iptables, I'm not so sure but I found:

https://serverfault.com/questions/1025857/iptables-as-a-reverse-proxy

Which seems very similar to your solutions, but it seems they map one port at a time, did you try to map a specific port?

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.