Where can I force a specific DNS server to be used on OS X?

6

1

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.

user124114

Posted 2012-03-28T19:14:44.020

Reputation: 473

Did you try that? Mac OS X Lion, /etc/hosts Bugs, and DNS Resolution

– None – 2012-07-30T17:58:52.840

Answers

1

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

Mikael Lepistö

Posted 2012-03-28T19:14:44.020

Reputation: 111

This accomplishes the task. – MT. – 2019-12-18T23:02:42.053

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.

Valentin

Posted 2012-03-28T19:14:44.020

Reputation: 826

thank you, but unfortunately that's not possible. So the OS offers no way for me to use a DNS server of my choice on my computer? – user124114 – 2012-03-28T20:06:53.253

Hm, OS X is still Unix. You could modifiy the /etc/resolf.conf (or the adequate counterpart of it in Unix) after you established the VPN connection. Another way might be to set an immutable bit on the file. – Valentin – 2012-03-28T20:34:58.380

Unfortunately, in OS X /etc/resolv.conf is auto-generated and changing it has no effect. – user124114 – 2012-03-28T20:43:41.723

1

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

Posted 2012-03-28T19:14:44.020

Reputation: 5 706

Thanks, I tried this. But after connecting the VPN client, the bad DNS server is still set (overwriting the previous, working one), and I still don't know how to get rid of it :( – user124114 – 2012-03-31T12:02:36.670

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

Posted 2012-03-28T19:14:44.020

Reputation: 101

The question is asking how to change the DNS server used not how to re-map individual IP addresses. – rlandster – 2019-11-04T04:12:10.583

-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]*\]
    

ralph

Posted 2012-03-28T19:14:44.020

Reputation: 1