Jade Yao
Jade Yao

Reputation: 55

configure network preferences from command lines with Mac

Is there a way to programmatically configure network preferences, such as changing the "location" from the command line (bash or shell) on a Mac. I'm trying to call it from another script.

Network Preferences

Upvotes: 2

Views: 701

Answers (1)

Travis Clarke
Travis Clarke

Reputation: 6681

Check out the networksetup command.

networksetup: The networksetup command is used to configure network settings typically configured in the System Preferences application. The networksetup command requires at least "admin" privileges to run. Most of the set commands require "root" privileges to run.

sudo networksetup -switchtolocation "location"  # set network location
sudo networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4  # set dns servers
# ... and many more! Reference the `networksetup` man page. 

Upvotes: 2

Related Questions