Setting up a connection to two OpenVPN servers with "onion-like" encryption involves creating a layered or multi-hop VPN setup where your traffic is encrypted and routed through multiple servers. While it's not the same as Tor's onion routing, you can create a similar effect by chaining VPNs. Here's a detailed guide on how to achieve this with OpenVPN:
Overview
- Server A and Server B: Two independently configured OpenVPN servers.
- Client Configuration: The client computer connects to Server A, and Server A routes the connection through to Server B.
- Encryption: Each server encrypts the traffic separately, providing two layers of encryption (outer and inner layers).
Steps to Set Up
Server Configuration
Server A Configuration:
-
Set up Server A with OpenVPN using a unique subnet, e.g., 10.8.0.0/24.
-
Enable IP forwarding by executing echo "1" > /proc/sys/net/ipv4/ip_forward.
-
Adjust firewall rules to permit OpenVPN traffic. Use iptables to manage NAT:
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
-
Create a server configuration file /etc/openvpn/serverA.conf.
port 1194
proto udp
dev tun
ca ca.crt
cert serverA.crt
key serverA.key
dh dh.pem
server 10.8.0.0 255.255.255.0
keepalive 10 120
comp-lzo
persist-key
persist-tun
status /var/log/openvpn-status.log
verb 3
Server B Configuration:
-
Set up Server B similarly with a different subnet, e.g., 10.9.0.0/24.
-
Enable IP forwarding on Server B as well.
-
Modify iptables accordingly.
-
Create a server configuration file /etc/openvpn/serverB.conf.
port 1195
proto udp
dev tun
ca ca.crt
cert serverB.crt
key serverB.key
dh dh.pem
server 10.9.0.0 255.255.255.0
keepalive 10 120
comp-lzo
persist-key
persist-tun
status /var/log/openvpn-status.log
verb 3
Client Configuration
Setup for Client to Server A:
- Create a client configuration file
client-to-serverA.ovpn.
client
dev tun
proto udp
remote <Server A IP> 1194
resolv-retry infinite
nobind
persist-key
persist-tun
ca ca.crt
cert client.crt
key client.key
cipher AES-256-CBC
auth SHA256
comp-lzo
verb 3
Setup for Server A to Act as Client for Server B:
- Create a new OpenVPN client configuration file
serverA-to-serverB.ovpn on Server A.
client
dev tun1
proto udp
remote <Server B IP> 1195
resolv-retry infinite
nobind
persist-key
persist-tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/serverA-to-serverB.crt
key /etc/openvpn/serverA-to-serverB.key
cipher AES-256-CBC
auth SHA512
comp-lzo
verb 3
- Launch a separate instance of OpenVPN on Server A using this client configuration to connect to Server B.
Routing Configuration
-
Ensure that traffic originating from the client (connected to Server A) is routed through the newly established tunnel to Server B:
iptables -t nat -A POSTROUTING -o tun1 -j MASQUERADE
iptables -A FORWARD -i tun0 -o tun1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i tun1 -o tun0 -j ACCEPT
Testing
- Connect: Start by connecting the client to Server A.
- Verify: Ensure connection from Server A to Server B is up and that traffic is properly double-encrypted.
- Check Routing: Use tools like
traceroute to confirm your data follows the expected path.
Considerations
- Security and Performance: Double encryption and chained VPNs can increase latency but provide a higher security layer compared to traditional VPN usage.
- Separate Encryption: Ensure different keys and algorithms for each layer to avoid a single point of failure.
- Logging and Monitoring: Implement logging and monitoring to ensure the tunnels remain open and secure.
By using a layered approach similar to the onion routing of the Tor network, your online activities can gain significant additional privacy and security benefits.