SwiftNIO Local Proxy DNS settings

I make local proxy with swiftnio(and NEPacketTunnelProvider) successfully. and I have a question about DNS settings.

In this way, the local proxy server connects to the host.

ClientBootstrap(group: context.eventLoop)
            .channelInitializer { channel in
            .connect(host: String(host), port: port)

I would like to configure DNS settings (like here. Is there a way to do this?

NIO uses the system resolver, so today you can't easily override it on a per-process basis. Can you set the system resolver?

Thanks for reply.

I don't know much yet, so this is my first time hearing the system resolver.

But does that mean I just need to set up the system resolver?

and note that local proxy is in ios platform.(not mac)

Yes, so you just need to set as the DNS resolver on iOS.

1 Like

I searched on google "DNS resolver on IOS", but im not sure.

Are you talking about this?

settings.dnsSettings = NEDNSSettings(servers: ["", "", ""])
settings.dnsSettings?.matchDomains = [""]

However, it is the original code and the DNS has not been changed.

If you don't mind, could you tell me in detail?

That won’t work for code running inside the Network Extension provider, because NECP means that the extension ignores its own network. I talk about this more in A Peek Behind the NECP Curtain. Admittedly, that’s focused on interfaces, but the same applies for DNS resolvers.

There are two parts to this question. The first is: How does SwiftNIO use DNS? Cory answered this to confirm that it relies on the system resolver.

That leads to a second question: How can you change the behaviour of the system resolver on iOS? That’s very specific to Apple platforms, and so off-topic for Swift Forums. If you bounce over to Apple Developer Forums, I can help you out there.

Make sure to tag your thread with Network Extension so that I see it.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple


I post the question to Apple Developer Forum!


reply please..!

1 Like