Posts

Post not yet marked as solved
5 Replies
1.7k Views
Hi,I am developing a VPN application for professional use and I have a problem with DNS redirection. I want to use my own DNS server, so according to Apple documentation, I wrote this piece of code to redirect specific URLs to my DNS server. But it doesn't seem to work. My DNS server is never reached.import NetworkExtension open class Vpn { let manager = NEVPNManager.shared() public func setProtocol(vpnProtocol: NEVPNProtocol, vpnError: @escaping((_ error: Error?) ->())) { manager.loadFromPreferences(completionHandler: { [unowned self] error in if let errorVpn = error { print("[Vpn.setProtocol] - Load From Preferences error: \(errorVpn)") vpnError(errorVpn) } self.manager.protocolConfiguration = vpnProtocol self.manager.isEnabled = true self.manager.localizedDescription = "CustomVPN" let evaluationRule = NEEvaluateConnectionRule(matchDomains: ["url1.com", "url2.com"], andAction: .connectIfNeeded) evaluationRule.useDNSServers = ["***.***.***.***"] let onDemandRule = NEOnDemandRuleEvaluateConnection() onDemandRule.connectionRules = [evaluationRule] self.manager.onDemandRules = [onDemandRule] self.manager.isOnDemandEnabled = true self.manager.saveToPreferences(completionHandler: { error in if let errorSaving = error { print("[Vpn.setProtocol] - Save To Preferences error: \(errorSaving)") vpnError(errorSaving) } }) }) } }AndvnpProtocol = NEVPNProtocolIKEv2()I'm using Swift 5 and testing on iOS 13.4.1I hope that someone could help me.Thanks,IDNSTW
Posted
by IDNSTW.
Last updated
.