Community Support Forum
 
  OpenVPN.net  •  Forum Index  •  FAQ  

It is currently Wed May 16, 2012 2:57 pm




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
 allow ssh via on non vpn address while vpn is open 
Author Message
 Post subject: Re: allow ssh via on non vpn address while vpn is open
PostPosted: Mon Sep 26, 2011 5:54 pm 
OpenVPN User

Joined: Sun Sep 25, 2011 2:43 pm
Posts: 11
After some testing, the internal VPN IP changes everytime I reconnect. I assume I would need a static IP on my tun0 iface for this to work? If so, is that my control or the servers control?


Offline
 Profile  
 
 Post subject: Re: allow ssh via on non vpn address while vpn is open
PostPosted: Mon Sep 26, 2011 6:05 pm 
OpenVpn Newbie
User avatar

Joined: Wed May 25, 2011 10:54 am
Posts: 6
skrewt wrote:
After some testing, the internal VPN IP changes everytime I reconnect. I assume I would need a static IP on my tun0 iface for this to work? If so, is that my control or the servers control?


Do you manage the VPN server?

If so, each client can have a static IP configured on the server.

Kadu


Offline
 Profile  
 
 Post subject: Re: allow ssh via on non vpn address while vpn is open
PostPosted: Mon Sep 26, 2011 6:13 pm 
OpenVPN User

Joined: Sun Sep 25, 2011 2:43 pm
Posts: 11
I do not manage the VPN server, just the SSH server that is serving as the VPN client.


Offline
 Profile  
 
 Post subject: Re: allow ssh via on non vpn address while vpn is open
PostPosted: Mon Sep 26, 2011 7:46 pm 
OpenVpn Newbie
User avatar

Joined: Wed May 25, 2011 10:54 am
Posts: 6
skrewt wrote:
I do not manage the VPN server, just the SSH server that is serving as the VPN client.


You can use the openvpn up/down options together with some variables provided by openvpn to setup the correct uptables rules.

Check the man pages for --up and --route-up, you should be able to get it from there.

Kadu


Offline
 Profile  
 
 Post subject: Re: allow ssh via on non vpn address while vpn is open
PostPosted: Mon Sep 26, 2011 7:54 pm 
I should be on the dev team.
User avatar

Joined: Fri Aug 29, 2008 5:42 pm
Posts: 652
topic7175.html


Offline
 Profile  
 
 Post subject: Re: allow ssh via on non vpn address while vpn is open
PostPosted: Mon Sep 26, 2011 8:27 pm 
OpenVPN User

Joined: Sun Sep 25, 2011 2:43 pm
Posts: 11
Thanks for the untold amounts of help I received in the IRC channel, as well as the help from this forum, I have finally gotten this to work. Per the link posted above to a similar thread, the following 2 lines were all that was needed to complete this setup:

Code:
ip rule add from <internal IP of SSH server/VPN client> table 10
ip route add default via <internal IP of gateway/router> table 10


Everything works as it should. Again, thank you so much! I will continue to hang out in the IRC channel and provide others with help if I am able to.


Offline
 Profile  
 
 Post subject: Re: allow ssh via on non vpn address while vpn is open
PostPosted: Wed Feb 08, 2012 10:15 am 
OpenVpn Newbie

Joined: Wed Feb 08, 2012 10:11 am
Posts: 1
bent wrote:
krzee wrote:
bent wrote:
Somehow the vpn client must be pushing everything through tun0 but I'm failing to understand how to make this exception work.


0.0.0.0/1 via 10.71.0.25 dev tun0
128.0.0.0/1 via 10.71.0.25 dev tun0
that is the 'somehow' you spoke of

Unless you find some way to route based on port in iptables (seemed that example 2 in your link was for that, but i dont even use linux so i wont be testing), routing works based on subnet, not port.



I'm did a bit of reading again so if I understood correctly:
Quote:
0.0.0.0/1 via 10.71.0.25 dev tun0
128.0.0.0/1 via 10.71.0.25 dev tun0

Combined those 2 are pretty much the whole internet and openvpn uses them because it doesn't want to overwrite the default route.

What if I add the same 2 lines for dev eth0 and the router gateway which is chosen and why ? Does the order make a difference ?

If my understanding is correct with iptables I should be able to mark the incoming ssh traffic and choose whatever route I want for it with ip rule

:mrgreen:

_________________
Providing moroccanoil reviews,moroccano oil reviews,hair oil,hair oil reviews and moroccan oil review in hope that giving some advices before you decide to buy.
http://www.moroccanoil-reviews.com/


Offline
 Profile  
 
 Post subject: Re: allow ssh via on non vpn address while vpn is open
PostPosted: Sat Mar 17, 2012 9:11 pm 
OpenVpn Newbie

Joined: Sun Mar 11, 2012 7:59 pm
Posts: 1
Hello.
I have recently faced this very issue and in extensive research found bits and pieces of information around this subject but not the total and complete solution.
Therefore I'd like to share the solution to the problem.
Note this guide is based around linux, I'm not sure how to do the same in windows, but I imagine it is possible, perhaps some 3rd party software allows to configure it.

The issue:
Routing is traditionally done on level 3 of OSi reference model. This implies that "traditional" routing is based around hosts or networks. So i.e. it is possible to say, all traffick from/to this host/network go via this gateway/interface.

The challenge:
We want to route traffick based on source or destination port, which is something that "traditional" Level 3 routing does not support.

I my particular case, I'm using commercial "anonymising" VPN service. OpenVPN config is provided by the service, and once openvpn client is started then all the traffick is redirected via vpn. However then http server no longer works (which is using the public, nonvpn ip). This machine is also serving as Wireless access point, so it routes packets between wlan and internet.

The solution:
Linux iproute2 has the capability of routing packets based on iptables rules, so anything you can specify as an iptable rule can be routed differently.

Very important:
ipforwarding has to be enabled and rp_filter has to be disabled for involved interfaces.
Especially the later is hardly mentioned in any documentation, and these days it is enabled in most distros. Having this enabled will most ikely screw up your attempts to mark and route the packets. the rp_filter, aka Reverse Path Filter, it inspects incomming packet and checks whether the the packet has valid return path (via gateway). If not it will drop the packet. I was tearing my hair out, seeing incomming http requests to the server in the tcpdump, however apache would not log any access attempts. This is because rp_filter was dropping them. It would not show in iptables counters.

Anyways, without further ado:

to check for ip_forwarding and rp_filter:

Code:
sysctl net.ipv4.conf.all.rp_filter = 1
sysctl -a | grep \\.rp_filter
sysctl net.ipv4.conf.[interface].rp_filter = 0


Then create a new routing table:

Code:
echo 100 openvpn >> /etc/iproute2/rt_tables
ip route add default via <nonvpn gateway ip> dev <nonvpn interface> table nonvpn
ip route show table nonvpn


Add ip forwarding rule

Code:
ip rule mark fwmark 1 lookup nonvpn
ip rule show


Create iptables rules to mark packets intended to route via nonvpn table. Those rules need to go to the 'mangle' iptable. Rules which mark packets originating from the localhost have to go into the 'OUTPUT' chain, whereas rules marking packets from different networks go to 'PREROUTING' chain

Code:
iptables -A OUTPUT -t mangle -p tcp --sport 80 -j MARK --set-mark=1 //reply packets from http server
iptables -A OUTPUT -t mangle -p tcp --sport 22 -j MARK --set-mark=1 //reply packets from ssh
iptables -A PREROUTING -t mangle -i wlan0 -j MARK --set-mark=1 //packets from wlan on dev box


That's all.

Troubleshooting tools i found usefull:
1. Use tcpdump or wireshark to see the packets sent/recieved on the relevant interface(s)
2. reset iptables counters (-Z) and then generate packets and see the counters as to which tables/chains/rules packets get to and which not.

Credits:
http://www.tldp.org/HOWTO/Adv-Routing-HOWTO/lartc.netfilter.html
http://lartc.org/howto/lartc.cookbook.fullnat.intro.html
http://www.wlug.org.nz/SourceBasedRouting
http://www.tolaris.com/2009/07/13/disabling-reverse-path-filtering-in-complex-networks/


Offline
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2


 Who is online 

Users browsing this forum: No registered users and 0 guests


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 post attachments in this forum

Jump to:  


phpBB SEO
[ Time : 0.076s | 11 Queries | GZIP : On ]

 
Index  |  FAQ


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group