OpenVPNAdapter icon indicating copy to clipboard operation
OpenVPNAdapter copied to clipboard

How can we implement Split Tunnel ?

Open nirwanrajat opened this issue 5 years ago • 10 comments

Hi,

Thanks for providing a wonderful library and for your support.

Can you please tell, how can we implement Split Tunnel using this library?

nirwanrajat avatar Jan 14 '20 11:01 nirwanrajat

Hi @nirwanrajat,

I've never done split tunneling myself but I would recommend to take a look at routes configuration. NEPacketTunnelNetworkSettings has ipv4Settings and ipv6Settings properties. Both of them have two arrays includedRoutes and excludedRoutes. routingMethod property that belongs to the NEPacketTunnelProvider also maybe useful.

ss-abramchuk avatar Jan 16 '20 07:01 ss-abramchuk

Hi @ss-abramchuk

Thanks for your response. As i look in code "routes configuration" is done inside the library. All the properties of NEPacketTunnelNetworkSettings is also set in library. So i think i have to made some changes in library routes configuration code.

Please suggest.

nirwanrajat avatar Jan 16 '20 09:01 nirwanrajat

Actually, you don't need to change anything in the library. You can override NEPacketTunnelNetworkSettings in one of the delegate methods. This one to be precise -> openVPNAdapter(openVPNAdapter:configureTunnelWithNetworkSettings:completionHandler:)

ss-abramchuk avatar Jan 16 '20 11:01 ss-abramchuk

func openVPNAdapter(_ openVPNAdapter: OpenVPNAdapter, configureTunnelWithNetworkSettings networkSettings: NEPacketTunnelNetworkSettings?, completionHandler: @escaping (OpenVPNAdapterPacketFlow?) -> Void) {
        
        // In order to direct all DNS queries first to the VPN DNS servers before the primary DNS servers
        // send empty string to NEDNSSettings.matchDomains
        networkSettings?.dnsSettings?.matchDomains = [""]

        networkSettings?.ipv4Settings?.excludedRoutes = [NEIPv4Route(destinationAddress: "xxx.xx.xxx.xx", subnetMask: "255.255.255.0")]
        // Specify the network settings for the current tunneling session.
        setTunnelNetworkSettings(networkSettings) { (error) in
            completionHandler(error == nil ? self.packetFlow : nil)
        }
    }

this is working code snippet

basheerpaliyathu avatar Jan 31 '20 05:01 basheerpaliyathu

@ss-abramchuk using this library can we implement active/in-active VPN while VPN is connected or we have only option i.e, disconnect the VPN ?

nirwanrajat avatar Feb 03 '20 07:02 nirwanrajat

Hi @basheerpaliyathu

Thanks for your response.....i have implemented this. Can you please confirm one thing can we pass domain name in destination address. Suppose we have to exclude youtube traffic so how we exclude that or there is any way to getting youtube destination address?

nirwanrajat avatar Feb 04 '20 05:02 nirwanrajat

@nirwanrajat did you achieve split tunneling for applications, for example i am using vpn on my macos app and i want skype to not use by pass vpn.

NasrullahKhan avatar Jan 08 '21 11:01 NasrullahKhan

@NasrullahKhan no i am not able to achieve. I think split tunneling can not be do.

nirwanrajat avatar Jan 08 '21 11:01 nirwanrajat

Hi guys, is there a way to pass a list of apps that only can use the vpn connection? example: I only need "WhatsApp, viber, others apps" to use the vpn other apps will bypass the vpn connection. Thank you in advance.

ChadiGSfeir avatar Feb 10 '21 09:02 ChadiGSfeir

Did anyone figure out how to bypass VPN on specific apps?=) It's strange, that there is no any useful info/example how to do it...

alloc33 avatar Nov 12 '21 13:11 alloc33