Openvpn as gateway client and personal server at same time.
Posted: Fri Apr 15, 2016 5:58 pm
Hello, I have very basic linux knowledge and I'd really like if someone can help me out here.
I currently have my raspberry Pi configured as a vpn gateway (working perfectly). Openvpn is setup to act as a client (tun0) and it connects to a vpn service provider, that way my devices in my house are connected through the vpn tunnel.
I'm trying to have another instance of openvpn running as a server in the same raspberry pi in order to be able to access my home network whenever I'm outside but I have not been able to do it. Independently I've been able to set up the raspberry as an openvpn client to my vpn service provider and also as a personal openvpn server successfully, allowing me to connect to my home but I haven't been able to have both instances running at the same time. Ports are forwarded correctly in the main router as I'm able to use the my personal oepnvpn server when I set it up alone (independently of the client conf)
Currently my home network is like (rpi acting only as a client):

***Now at the same time I want to have another instance of openvpn running as a server where it would allow me to browse my local lan remotely.***
I currently have the openvpn daemon autorun every time the rpi boots by using "systemctl enable openvpn@torguard"
My conf files:
torguard.conf (client conf file for connecting private vpn provider)
and my server.conf file (which is my personal openvpn server configuration file)
My Nat and Routing setup when running openvpn as client, is as follows (rules are persistent through boot):
And the below iptable settings when setting up de raspberrypi as a personal server
Any guidance on how I can accomplish this would be greatly appreciated.
Thanks
I currently have my raspberry Pi configured as a vpn gateway (working perfectly). Openvpn is setup to act as a client (tun0) and it connects to a vpn service provider, that way my devices in my house are connected through the vpn tunnel.
I'm trying to have another instance of openvpn running as a server in the same raspberry pi in order to be able to access my home network whenever I'm outside but I have not been able to do it. Independently I've been able to set up the raspberry as an openvpn client to my vpn service provider and also as a personal openvpn server successfully, allowing me to connect to my home but I haven't been able to have both instances running at the same time. Ports are forwarded correctly in the main router as I'm able to use the my personal oepnvpn server when I set it up alone (independently of the client conf)
Currently my home network is like (rpi acting only as a client):

***Now at the same time I want to have another instance of openvpn running as a server where it would allow me to browse my local lan remotely.***
I currently have the openvpn daemon autorun every time the rpi boots by using "systemctl enable openvpn@torguard"
My conf files:
torguard.conf (client conf file for connecting private vpn provider)
Code: Select all
client
dev tun
proto udp
remote la.serveraddress.com 443
resolv-retry infinite
remote-cert-tls server
nobind
tun-mtu 1500
tun-mtu-extra 32
mssfix 1450
ca /etc/openvpn/ca.crt
auth-user-pass /etc/openvpn/login.txt
comp-lzo
fast-io
ping-restart 0
route-delay 2
route-method exe
script-security 3 system
mute-replay-warnings
verb 3
Code: Select all
local 192.168.3.100 # Raspberry IP address
dev tun1
proto tcp #Using TCP
port 443
ca /etc/openvpn/easy-rsa/keys/ca.crt
cert /etc/openvpn/easy-rsa/keys/Home.crt # My CRT file
key /etc/openvpn/easy-rsa/keys/Home.key # My Key
dh /etc/openvpn/easy-rsa/keys/dh2048.pem
server 10.8.0.0 255.255.255.0
ifconfig 10.8.0.1 10.8.0.2 # server and remote endpoints
# Route to Client routing table for the OpenVPN Server
push "route 10.8.0.1 255.255.255.255"
# Route to Client routing table for the OpenVPN Subnet
push "route 10.8.0.0 255.255.255.0"
# My local subnet
push "route 192.168.3.0 255.255.255.0" # Raspberry PI network range address
push "dhcp-option DNS 192.168.3.1"
push "redirect-gateway def1"
client-to-client
duplicate-cn
keepalive 10 120
tls-auth /etc/openvpn/easy-rsa/keys/ta.key 0
cipher AES-128-CBC
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status /var/log/openvpn-status.log 20
log /var/log/openvpn.log
verb 1
Code: Select all
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
iptables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT
Code: Select all
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j SNAT --to-source 192.168.3.100
Thanks