Post not yet marked as solved
Post marked as unsolved with 14 replies, 8,532 views
Hi, everyone.I am trying to override dns resolver settings in my app.I used NEVPNManager to install a personal vpn and then used onDemandRules to set specific dns servers.So far my code works for some domains.Below is my code.When I put "*.com" in matchDomains, it works perfectly.But what I wnat to do is to redirect all dns queries to specific dns server.I tried empty matchDomains([]) and empty string([""]).I also tried wildcard expression like ["*"] and ["*.*].So far I had no success.It's been a few days and I still can't figure it out.Can anybody tell me what I am missing here?Thanks in advance.let manager = NEVPNManager.sharedManager()
manager.loadFromPreferencesWithCompletionHandler { error in
if let vpnError = error {
print("vpn error in loading preferences : \(vpnError)")
return
}
if manager.protocolConfiguration == nil {
let myIPSec = NEVPNProtocolIPSec()
myIPSec.username = "username"
myIPSec.serverAddress = "server address"
myIPSec.passwordReference = self.getPersistentRef()
myIPSec.authenticationMethod = NEVPNIKEAuthenticationMethod.SharedSecret
myIPSec.sharedSecretReference = self.getPersistentRef()
myIPSec.useExtendedAuthentication = true
manager.protocolConfiguration = myIPSec
manager.localizedDescription = "myDNS"
let evaluationRule = NEEvaluateConnectionRule(matchDomains: ["*.com"], andAction: NEEvaluateConnectionRuleAction.ConnectIfNeeded)
evaluationRule.useDNSServers = ["***.***.***.***"]
let onDemandRule = NEOnDemandRuleEvaluateConnection()
onDemandRule.connectionRules = [evaluationRule]
onDemandRule.interfaceTypeMatch = NEOnDemandRuleInterfaceType.Any
manager.onDemandRules = [onDemandRule]
manager.onDemandEnabled = true
manager.enabled = true
manager.saveToPreferencesWithCompletionHandler { error in
if let vpnError = error {
print("vpn error in saving preferences : \(vpnError)")
return
}
}
}
}