Score:0

How to route all network traffic back and forth to an external computer on the internet?

ph flag

Due to our restricted internet in Iran, I need to establish an internet connection through an OpenVPN server-which is located in Iran- and then route all network packets from the VPN clients to another server-which is located on a free and open internet-.

I am a software developer and don't have any deep knowledge in networking. I just know some basics. So, it would be so great if you enlighten me in this problem.

I set up some iptables rules in order to route the packets using NAT. But it won't send any packets to the outside server.

The following are my iptables rules:

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
ACCEPT     udp  --  anywhere             <iran-vps-hostname>      udp dpt:<open-vpn-port>
ACCEPT     tcp  --  anywhere             anywhere                 tcp dpt:ssh
DNAT       tcp  --  anywhere             <iran-vps-hostname>      tcp to:<free-vps-ip>
DNAT       udp  --  anywhere             <iran-vps-hostname>      udp to:<free-vps-ip>

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  10.8.0.0/24          anywhere
SNAT       tcp  --  anywhere             <free-vps-ip>        tcp dpt:http to:<iran-vps-ip>
SNAT       tcp  --  anywhere             <free-vps-ip>        tcp to:<iran-vps-ip>
SNAT       udp  --  anywhere             <free-vps-ip>        udp to:<iran-vps-ip>

As it's obvious, I established an OpenVPN server in my Iran machine and get iptables to accept to OpenVPN port in order to accept OpenVPN clients' connection.

The MASQUERADE rule also is for OpenVPN configuration. The other rules which are PREROUTING and POSTROUTING have been added by myself.

The flow I want to create is as follows:

(my computer(as a vpn client)) <==connects-to==> [IRAN VPS] <==routes-all-network==> [OPEN WORLD VPS]

How can I achieve to this flow?

NOTE: I also established an OpenVPN server on the open world vps, but I cannot connect to it through UDP, and with TCP, it faces to TLS handshaking failure.

A.B avatar
cl flag
A.B
This was also asked on UL SE: https://unix.stackexchange.com/questions/730742/how-to-route-all-network-traffic-back-and-forth-to-an-external-computer-on-the-i
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.