How to enable custom DNS settings from DNSSettingsManager on macOS?

Currently, I'm working on NEDNSSettingsManager on macOS.

I succeeded in loading settings using loadFromPreferences(completionHandler:), and also saving settings using saveToPreferences(completionHandler:). Then, macOS' System Preferences showed "Not Running" and I couldn't enable it.

How do I enable it on System Preferences?

My code looks like the following.
On iOS, I can enable it on Settings app using the same code.

Thank you.
Answered by Systems Engineer in 656500022
I did some digging into this and created a test bed project of my own on macOS. When you create the Network Configuration for NEDNSSettingsManager and call saveToPreferences the Network Configuration should be able to be seen in the System Preferences. From there, click on the new Network Configuration in the left side pane. At the bottom of the list should be a circle icon with "..." in the middle. Click this button and click "Make Service Active." Next, click Apply and this should activate your new Network Configuration. From there you should be able to prove that DoT or DoH is being used with URLSessionTaskMetrics via something like:

Code Block swift
switch metric.domainResolutionProtocol {
case .https:
print("DoH was used")
case .tls:
print("Dot was used")
case .udp:
print("Unencrypted DNS was used")
default:
print("Nothing was determined about resolution")
}
}



Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

Then, macOS' System Preferences showed "Not Running" and I couldn't enable it.

Is there any code or logs you can share here to see what might be going wrong?


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Thank you for replying. I pasted URLs of my code, but it seemed that my GitHub username was suppressed with asterisks. I paste them again, so please could you replace 3 asterisks with k+k+k (without +) in the following URLs?

Code 1
Code 2

Screenshot
Accepted Answer
I did some digging into this and created a test bed project of my own on macOS. When you create the Network Configuration for NEDNSSettingsManager and call saveToPreferences the Network Configuration should be able to be seen in the System Preferences. From there, click on the new Network Configuration in the left side pane. At the bottom of the list should be a circle icon with "..." in the middle. Click this button and click "Make Service Active." Next, click Apply and this should activate your new Network Configuration. From there you should be able to prove that DoT or DoH is being used with URLSessionTaskMetrics via something like:

Code Block swift
switch metric.domainResolutionProtocol {
case .https:
print("DoH was used")
case .tls:
print("Dot was used")
case .udp:
print("Unencrypted DNS was used")
default:
print("Nothing was determined about resolution")
}
}



Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Thank you Matt. I've succeeded in enabling my Network Configuration by following your instructions. Also, thanks for an additional advice about URLSessionTaskMetrics.

Thank you Matt. I've succeeded in enabling my Network Configuration by following your instructions. Also, thanks for an additional advice about URLSessionTaskMetrics.

No problem. Glad to help out.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
How to enable custom DNS settings from DNSSettingsManager on macOS?
 
 
Q