December 30, 2011

Setup DNS on macos from command line

If you get to remotely manage mac users over ssh, the networksetup command is a great tool.

The full manual is here : https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man8/networksetup.8.html

Here’s how to setup a dns server:

  1. find the interface name

networksetup -listnetworkserviceorder

  1. your output would look similiar to this:

(1) Bluetooth DUN
(Hardware Port: Bluetooth DUN, Device: Bluetooth-Modem)

(2) Ethernet
(Hardware Port: Ethernet, Device: en0)

(3) AirPort
(Hardware Port: AirPort, Device: en1)

3.choose the device you want to apply the dns settings to and run this command ( in this example were applying it to the AirPort interface ), change the google dns addresses to your preferred ones.

networksetup -setdnsservers AirPort 8.8.8.8 8.8.8.4

  1. verify your changes using :

scutil –dns