ios - 将所有 DNS 请求重定向到 iOS 应用程序中的自定义解析器
<p><p>每个人。
我正在尝试<strong>在我的 iOS 应用中覆盖 dns 解析器设置</strong>。</p>
<p>我使用<strong>NEVPNManager</strong>安装了<strong>个人vpn</strong>,然后使用<strong>onDemandRules</strong>设置特定的dns服务器。
到目前为止,我的代码<strong>适用于某些域</strong>。
下面是我的代码。</p>
<p>当我将“*.com”放入 <strong>matchDomains</strong> 时,它可以完美运行。</p>
<p>但是<strong>我想要做的</strong>是<strong>将所有 dns 查询重定向</strong>到特定的 dns 服务器。
我尝试了空匹配域([])和空字符串([“”])。
我还尝试了 ["*"] 和 ["*.*] 之类的通配符表达式。
到目前为止,我没有成功。</p>
<p>已经好几天了,我还是想不通。
谁能告诉我我在这里想念什么?
提前致谢。</p>
<pre><code> 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 = ["XXX.XXX.XXX.XXX"]
let onDemandRule = NEOnDemandRuleEvaluateConnection()
onDemandRule.connectionRules =
onDemandRule.interfaceTypeMatch = NEOnDemandRuleInterfaceType.Any
manager.onDemandRules =
manager.onDemandEnabled = true
manager.enabled = true
manager.saveToPreferencesWithCompletionHandler { error in
if let vpnError = error {
print("vpn error in saving preferences : \(vpnError)")
return
}
}
}
}
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我发现即使在最新的 iOS (10.3.1) 和使用 NEVPNProtocolIKEv2 中,这也是错误的。前一刻它可以工作,下一刻它不想启动 VPN 连接,因为它似乎误解了按需规则并返回错误,说 VPN 配置文件未启用。我最终配置了 IKEv2 服务器 (Strongswan) 以使用/etc/ipsec.conf 中的“rightdns”选项推送 DNS 设置。这给了我将 DNS 请求重定向到自定义解析器的预期结果。</p></p>
<p style="font-size: 20px;">关于ios - 将所有 DNS 请求重定向到 iOS 应用程序中的自定义解析器,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/42874507/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/42874507/
</a>
</p>
页:
[1]