lan traffic through vpn server

Scripts with setup, destroy, and modify routing tables and firewall rulesets for client connections.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
newuser44
OpenVPN User
Posts: 34
Joined: Mon Jan 13, 2014 9:55 pm

lan traffic through vpn server

Post by newuser44 » Wed Jul 23, 2014 6:29 pm

lan clients (192.168.11.x) -> router(ubuntu,192.168.11.115,10.8.33.25) -> router(openwrt, 192.168.11.1) -> inet -> openvpn server(10.8.33.1)


yes i know that the ubuntu router is not needed, but this is just a test setup for traffic shaping
icmp redirects on ubuntu are disabled, so the clients will always go over this router and then the real one.
it only has eth0


the router got a vpn connection to the openvpn server

router
route:

Code: Select all

0.0.0.0         192.168.11.1    0.0.0.0         UG    0      0        0 eth0
10.8.33.0       10.8.33.25      255.255.255.0   UG    0      0        0 tun0
10.8.33.25      0.0.0.0         255.255.255.255 UH    0      0        0 tun0
169.254.0.0     0.0.0.0         255.255.0.0     U     1000   0        0 eth0
192.168.11.0    0.0.0.0         255.255.255.0   U     1      0        0 eth0
iptables-save

Code: Select all

# Generated by iptables-save v1.4.12 on Wed Jul 23 20:28:35 2014
*filter
:INPUT ACCEPT [1823326:2372828464]
:FORWARD ACCEPT [1247173:280199859]
:OUTPUT ACCEPT [1347457:108842556]
COMMIT
# Completed on Wed Jul 23 20:28:35 2014
# Generated by iptables-save v1.4.12 on Wed Jul 23 20:28:35 2014
*nat
:PREROUTING ACCEPT [6558:475103]
:INPUT ACCEPT [3249:257116]
:OUTPUT ACCEPT [8467:556795]
:POSTROUTING ACCEPT [1572:101843]
-A POSTROUTING -s 192.168.11.0/24 -o eth0 -j MASQUERADE
COMMIT
# Completed on Wed Jul 23 20:28:35 2014

the clients can ping the openvpn server
if it was only one client you could use "redirect-gateway def1" on the server side and all traffic would go over the vpn and you would be done with it.

but i want some of my clients to over the vpn, or if thats not possible all of them.

what do i have to change on the router to tell it to do this?

newuser44
OpenVPN User
Posts: 34
Joined: Mon Jan 13, 2014 9:55 pm

Re: lan traffic through vpn server

Post by newuser44 » Thu Jul 24, 2014 10:06 pm

Solution:

Code: Select all

ip route add 88.198.127.81/32 via 192.168.11.1 &&  ip route replace default dev tun0 && iptables -t nat -A POSTROUTING -s 192.168.11.0/24 -o tun0 -j MASQUERADE

this is ONE solution, there are others. maybe better ones. but this one works

Post Reply