OpenVPN access to router in front of OpenVPN client router

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
plawer
DD-WRT User


Joined: 11 Aug 2019
Posts: 156

PostPosted: Mon May 25, 2020 19:32    Post subject: OpenVPN access to router in front of OpenVPN client router Reply with quote
WRT3200ACM - v3.0-r42602 std
WNDR4300 - v3.0-r40559 std

I have a setup with an OpenVPN server on my router at home, and an OpenVPN client router behind another router remotely. I can reach the remote router of 192.168.4.1 and the remainder of that network. I am trying to set up the routing so I can also reach the router in front (10.1.10.1).

I configured the CCD for the remote router. If I have understood it correctly, I only need to add the iroute for 10.1.10.0 since the actual route for that network is already registered in the router.

Code:
ifconfig-push 192.168.102.4 255.255.255.0
iroute 192.168.4.0 255.255.255.0
iroute 10.1.10.0 255.255.255.0


In the Additional Configuration on the server a route to the 10.1.10.0 net is added.

Code:
route 10.1.10.0 255.255.255.0 vpn_gateway
route 192.168.4.0 255.255.254.0 vpn_gateway


The routing table on my home router looks something like this. There is an entry to send the traffic to 10.1.10.0.

Code:
Destination LAN NET   Subnet Mask   Gateway   Flags   Metric   Interface
default   0.0.0.0   x.x.x.x   UG   0   WAN
10.1.10.0   255.255.255.0   192.168.102.2   UG   0   tun2
x.x.x.x   255.255.252.0   *   U   0   WAN
192.168.2.0   255.255.255.0   *   U   0   LAN & WLAN
192.168.4.0   255.255.254.0   192.168.102.2   UG   0   tun2
192.168.102.0   255.255.255.0   *   U   0   tun2


On the client router WAN:10.1.10.113/LAN:192.168.4.1 there is the standard route to 10.0.10.0.

Code:
Destination LAN NET   Subnet Mask   Gateway   Flags   Metric   Interface
default   0.0.0.0   10.1.10.1   UG   0   WAN
10.1.10.0   255.255.255.0   *   U   0   WAN
192.168.0.0   255.255.252.0   192.168.102.1   UG   0   tun1
192.168.4.0   255.255.255.0   *   U   0   LAN & WLAN


Yet I can't reach the secondary router at 10.1.10.1 from home. Any suggestions where I am hitting a snag?

_________________
Linksys: Several WRTxx00AC variations | Netgear: 4x WNDR4500v2, 7x WNDR4300, R6400v1 | Asus: 2x RT-AC66U | Gl.inet: 3x GL-AR150
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Mon May 25, 2020 19:48    Post subject: Reply with quote
On the client router you have to set a NAT rule out for the Openvpn sub net.

Just like you are doing on the server.

40599 is a crappy build consider upgrading

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
plawer
DD-WRT User


Joined: 11 Aug 2019
Posts: 156

PostPosted: Mon May 25, 2020 20:01    Post subject: Reply with quote
You mean like this on the client? That got omitted in my copy/paste and is in place.

192.168.102.0 255.255.255.0 * U 0 tun1

_________________
Linksys: Several WRTxx00AC variations | Netgear: 4x WNDR4500v2, 7x WNDR4300, R6400v1 | Asus: 2x RT-AC66U | Gl.inet: 3x GL-AR150
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Mon May 25, 2020 20:06    Post subject: Reply with quote
No the rule from step 8a from the guide.
_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
plawer
DD-WRT User


Joined: 11 Aug 2019
Posts: 156

PostPosted: Mon May 25, 2020 20:34    Post subject: Reply with quote
Thanks. Adding the following solved it.

iptables -t nat -A POSTROUTING -o $(nvram get wan_iface) -j MASQUERADE

_________________
Linksys: Several WRTxx00AC variations | Netgear: 4x WNDR4500v2, 7x WNDR4300, R6400v1 | Asus: 2x RT-AC66U | Gl.inet: 3x GL-AR150
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Mon May 25, 2020 21:03    Post subject: Reply with quote
It is not the best rule but it gets the job done.
_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
plawer
DD-WRT User


Joined: 11 Aug 2019
Posts: 156

PostPosted: Mon May 25, 2020 21:27    Post subject: Reply with quote
What would you advice it be? I tried a few variations with the specific subnet included, but it didn't work for me (or I did something wrong).
_________________
Linksys: Several WRTxx00AC variations | Netgear: 4x WNDR4500v2, 7x WNDR4300, R6400v1 | Asus: 2x RT-AC66U | Gl.inet: 3x GL-AR150
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Tue May 26, 2020 11:00    Post subject: Reply with quote
Well it is an academic discussion like I said your rule gets the job done.

in general I was taught to be as specific as possible when setting firewall rules so as to not leave holes open.
As the purpose of this rule is to NAT traffic out via the WAN interface coming from the OpenVPN's subnet I would specify the openVPN's subnet, like
Code:
-s 10.8.0.0/24
.

Second point, at least you specify the interface that is good, the interface is the WAN and if you know your WAN you can add it directly (VLAN2, VLAN0, ETH0 , PPoE0 etc) and as there is no intermediate step that is actually the quickest but that is nitpicking.
So we use something to query the router for the used WAN interface

Basically you can use 4 queries (well there are more but these are the four most used):
nvram get wan_ifname
nvram get wan_iface
get_wanface

WAN_IF="$(route -n | awk '/^0.0.0.0/{wif=$NF} END {print wif}')"
echo $WAN_IF

The first two are working in 90% of the routers the third in 99,99%

The fourth can be used if the third is not working
(It will also work in 99,99% of normal use cases)

So I do not advice to use the first two as someone sees it use it and it might not work.
So my ideal rule would be:
Code:
iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o $(get_wanface) -j MASQUERADE


That is if 10.8.0.0/24 is your VPN subnet.
As users do not literally follow the guide and use other subnets but still copy the rule from the guide (and then of course it is not working) a lot of instructions omit the subnet like you are doing.

As I said yours is not wrong it is also a matter of personal preference

But anyway glad you solved it Smile

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
plawer
DD-WRT User


Joined: 11 Aug 2019
Posts: 156

PostPosted: Tue May 26, 2020 19:33    Post subject: Reply with quote
I do see your point, but I can't get it to work like that.

My VPN net is 192.168.102.0/24. If I use this then I can't reach the second router.

Code:
iptables -t nat -I POSTROUTING -s 192.168.102.0/24 -o $(get_wanface) -j MASQUERADE


If I change the subnet to the actual subnet at home it does work and I can ping the remote router.

Code:
iptables -t nat -I POSTROUTING -s 192.168.2.0/24 -o $(get_wanface) -j MASQUERADE


Given that there are at least 3 OpenVPN clients connecting to the main server and routing to each client, I've ended up with the original statement modified on the get_wanface. If I encounter issues, I will define each applicable subnet in the iptables.

Code:
iptables -t nat -I POSTROUTING -o $(get_wanface) -j MASQUERADE


Thanks for the explanation.

_________________
Linksys: Several WRTxx00AC variations | Netgear: 4x WNDR4500v2, 7x WNDR4300, R6400v1 | Asus: 2x RT-AC66U | Gl.inet: 3x GL-AR150
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12889
Location: Netherlands

PostPosted: Tue May 26, 2020 19:53    Post subject: Reply with quote
Yes the server is probably not natting on the tun interface.
So traffic to the client can come from the servers subnet and from one of the connected VPN clients.

So in that case you should specify the OVPN subnet and the servers subnet.

But like I said you are good as it is

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum