networksetup is the built-in macOS command-line utility that reads and changes persistent network configuration: network services, IP addressing, DNS servers, proxies, Wi-Fi power and network locations. In the Terminal & scripting toolkit of macOS, it is the scriptable counterpart of the Network pane in System Settings, so anything an administrator would click there can usually be expressed as one repeatable command.
The tool lives at /usr/sbin/networksetup and writes through Apple’s SystemConfiguration framework, which means its changes survive reboots and appear immediately in the graphical settings. That persistence is the key difference from low-level tools such as ifconfig, whose changes are temporary and lost at restart.
How networksetup manages network services
networksetup works on network services, not directly on hardware interfaces. A service is a named configuration such as “Wi-Fi”, “Ethernet” or “Thunderbolt Bridge” that binds a hardware port (for example the device en0) to settings like DHCP, DNS and proxies. Most commands therefore take the service name as their first argument, quoted when it contains spaces.
Changes are stored in the system preferences database at /Library/Preferences/SystemConfiguration/preferences.plist, and the configd daemon applies them to the live interfaces. Because the tool edits system-wide settings, almost every write operation needs administrator rights, so scripts typically run it with sudo or from a management agent that already runs as root.
The distinction between service names and device names explains the most common confusion. The following table maps the identifiers that networksetup commands expect.
| Identifier | Example | Where it is used |
|---|---|---|
| Network service | “Wi-Fi”, “Ethernet” | DNS, DHCP, proxy and IP commands |
| Hardware port | Wi-Fi, Thunderbolt Ethernet Slot 0 | Output of -listallhardwareports |
| Device name | en0, en1, en7 | Wi-Fi power and joining commands |
| Network location | Automatic, Office | Location creation and switching |
Essential networksetup commands
The command set is large, but a small group of verbs covers most administrative work. Commands start with a single hyphen, and running networksetup -help or networksetup -printcommands lists the full catalog on the installed macOS version.
| Command | Purpose | Needs admin rights |
|---|---|---|
-listallnetworkservices | Lists services; an asterisk marks disabled ones | No |
-listallhardwareports | Maps ports to device names and MAC addresses | No |
-getinfo "Wi-Fi" | Shows IP address, subnet mask and router | No |
-setdnsservers "Wi-Fi" 1.1.1.1 | Sets DNS servers; “Empty” clears them | Yes |
-setmanual / -setdhcp | Switches between static and DHCP addressing | Yes |
-setwebproxy, -setautoproxyurl | Configures HTTP proxies or a PAC file | Yes |
-setairportpower en0 off | Turns the Wi-Fi radio on or off | Usually |
-ordernetworkservices | Sets service priority order | Yes |
Read commands return plain, line-oriented text that is easy to parse with awk or grep in zsh scripts. Write commands normally print nothing on success, so scripts should verify the result with a matching get command rather than assume the change was applied.
networksetup compared with related network tools
macOS ships several network utilities with overlapping but distinct roles. Choosing the right one depends on whether a change must persist and on how deep into the configuration store a task reaches.
| Tool | Main role | Persistence |
|---|---|---|
| networksetup | Service-level settings matching System Settings | Persistent |
| scutil | Direct access to the dynamic configuration store | Mostly runtime |
| ifconfig | Low-level interface parameters | Lost at restart |
| ipconfig | DHCP state and interface addresses | Runtime queries |
| wdutil | Wi-Fi diagnostics, replacing the old airport tool | Diagnostic only |
A practical rule follows from this comparison: use networksetup for configuration, scutil --dns and ipconfig for inspection of the live state, and ifconfig only for short experiments. For fleets, configuration profiles delivered by MDM remain the preferred way to enforce settings, and networksetup fills the gaps profiles do not cover.
Using networksetup in scripts and automation
networksetup is most valuable inside shell scripts, launch daemons and MDM policies, where it turns manual steps into repeatable actions. Reliable scripts follow a few patterns that prevent surprises on machines with unusual hardware.
- Discover service names dynamically with
-listallhardwareportsinstead of hard-coding “Wi-Fi”, because adapters and localized names differ between Macs. - Check the exit status and re-read the value, since some commands report errors only as text.
- Use network locations (
-createlocation,-switchtolocation) to keep alternative profiles such as office and home settings separate. - Avoid storing Wi-Fi passwords in plain script files; prefer configuration profiles for credentials.
The decision table below summarizes which approach fits typical administrative situations.
| Situation | Recommended approach | Reason |
|---|---|---|
| One Mac needs new DNS servers | networksetup -setdnsservers | Quick, persistent and visible in settings |
| Hundreds of Macs need a proxy | MDM configuration profile | Enforced and reported centrally |
| Temporary test of an MTU value | ifconfig or -setMTU | Easy to revert |
| Troubleshooting DNS resolution | scutil --dns | Shows the resolver order actually in use |
Limitations and common mistakes
networksetup is powerful but not a complete network manager. It cannot configure every VPN type, and settings locked by a configuration profile may be reapplied by the management system shortly after a script changes them.
Recent macOS releases also restrict access to Wi-Fi network names for privacy reasons, so commands such as -getairportnetwork may return incomplete output on current systems. Another frequent error is passing a device name where a service name is expected, which produces a message that the service is not recognized. Finally, clearing DNS requires the literal word “Empty”; passing an empty string leaves the old servers in place.
In everyday language
Every Mac has a Network page in its settings. There you pick how it connects, which servers it asks for website addresses and whether it uses a proxy. networksetup is a typed version of that page. Instead of clicking, you type one line in Terminal.
Think of it as a remote control for network settings. It does the same job as the buttons, but a script can press them for you. The changes stay in place after a restart, just like changes made with the mouse.
Seen in the real world
An IT technician at a school with 60 MacBook laptops must move every machine to new internal DNS servers before a weekend migration. Clicking through System Settings on each laptop would take most of a day, so the technician writes a short zsh script. It finds the Wi-Fi service with networksetup -listallhardwareports, runs networksetup -setdnsservers with the two new addresses and then checks the result with -getdnsservers.
The management system pushes the script to all laptops as a root policy. Within an hour, the reports show that 58 machines applied the change and two failed because they used a USB Ethernet adapter with a different service name. After the script is adjusted to handle any active service, the migration completes without a single manual visit.