10

On OS X Leopard, scutil gives me

$ scutil --dns
DNS configuration

resolver #1
  nameserver[0] : 192.168.1.1
  nameserver[1] : 192.168.2.1
  order   : 200000

resolver #2
  domain : local
  options : mdns
  timeout : 2
  order   : 300000

...

Now, how do I remove the first "resolver #1" and replace with a DNS server of my choosing?


Context: A VPN client sets this bogus DNS entry on connection, replacing my working DNS settings. I haven't been able to figure out how to stop it from doing so (see here), so now I'm trying to remove this unwanted effect ex-post, after I connect. A command line script to do this would be perfect.

I tried sudo scutil as per instructions here, but no love -- scutil --dns still reports the settings unchanged, and DNS resolution still doesn't work. Modifying /etc/resolv.conf has no effect on OS X.

6 Answers6

6

For temporary override on command line you can do:

sudo networksetup -setdnsservers Wi-Fi <dnsserver1ip> <dnsserver2ip>

and reset settings with:

sudo networksetup -setdnsservers Wi-Fi empty

If connected with some other interface than Wi-fi you can check valid names with:

sudo networksetup -listallnetworkservices
2

In my experience if you specify a particular DNS server in Network preferences, even if you're using DHCP, Mac OS uses that server in preference to the one obtained through DHCP. So if you always want to use 192.168.1.1, put that in explicitly.

System Preferences -> Network -> Ethernet (left pane) should produce a window that has a "DNS Server:" text box you can fill in with the IP address of your desired DNS server. Click "Apply" to apply the change, and you're done; you shouldn't have to make this change again. (If your VPN connection is WiFi instead of Ethernet, then you should click on that instead of Ethernet above.)

Kyle Jones
  • 6,364
1

Well, most VPN connections I am aware of are able to push a DNS server to the VPN client. My suggestion would be to ask your VPN provider to not push the DNS server for your connection. Please note that this might have some negative impact on your VPN session.

0

I suggest using a different approach:

You can use your Mac HOSTS FILE to solve the problem (The Hosts file is used to map human-friendly domain names to numerical IP addresses....google it to know more about it).

Simply add to the host file the DNS record that you need in your case so that even if you are using the VPN the OS will use the IP that you specify in the file.

Below how to open and edit the file:

sudo nano /private/etc/hosts

The DNS cache needs to be flushed after every change:

dscacheutil -flushcache
user72708
  • 101
0

On current (2024) versions of OSX, DNS resolution can be messed up by the "Limit IP address tracking" option under the "Details..." button for the network in System Settings.

When "Limit IP address tracking" is on, DNS resolution may not work as expected on local networks.

Turn "Limit IP address tracking" off to debug DNS resolution.

Fergie
  • 301
  • 2
  • 5
-1

You should have your vpn set up in your network. I have private internet access and have it manually installed in my network. My network shows Airport, Ethernet and Private Internet access.

To change my dns:

  • click on your vpn network
  • hit advanced and in options "send all traffic over VPN" should be checked
  • click the DNS tab and add your dns in the box. If you don't put any dns servers it will push to your ethernet dns settings.
  • Now to check if you are running on your dns ccp this in terminal:

    scutil --dns | grep nameserver\[[0-9]*\]
    
Andrea
  • 1,536
ralph
  • 1