The Need for Command-Line Networking
Configuring a Mac’s network settings via the System Settings app is perfectly fine for a single user at a coffee shop. However, if you are an IT administrator deploying 50 new Macs, or a developer who needs to instantly switch between a static internal IP address and a DHCP configuration, clicking through graphical menus is agonizingly slow.
macOS provides a powerful, built-in terminal utility specifically for managing all graphical network interfaces: networksetup. This command allows you to view, modify, and script every aspect of the Mac’s network hardware, bypassing the System Settings app entirely.
Note: Because these commands modify core system connectivity, most require administrator privileges (sudo).
1. Identifying Your Hardware Services
Before you can change a setting, you must know what Apple calls your network hardware. (For example, what you call “Wi-Fi,” the system might internally track as “Wi-Fi” or “en0”).
networksetup -listallnetworkservices
This command outputs a clean list of all available network interfaces, such as:
- Wi-Fi
- Ethernet
- Thunderbolt Bridge
You will use these exact names (including spaces) in the subsequent commands.
2. Managing Wi-Fi Connections
If a Mac’s graphical interface is frozen, or if you are managing a Mac remotely via SSH, you can control the Wi-Fi card directly from the terminal.
Turn Wi-Fi On or Off
sudo networksetup -setairportpower Wi-Fi off
sudo networksetup -setairportpower Wi-Fi on
List Available Wi-Fi Networks
To see all the SSIDs currently broadcasting in your immediate area:
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s
Note: This specific airport command requires calling the hidden executable directly, as Apple removed this specific functionality from the core networksetup wrapper.
Connect to a Specific Network
To force the Mac to join a specific network (you must provide the SSID and the password):
sudo networksetup -setairportnetwork Wi-Fi "CompanyNetwork" "Password123"
3. Configuring IP Addresses (DHCP vs. Static)
Switching between dynamic (DHCP) and static IP addresses is a common task for network engineers testing localized server environments.
Set to DHCP (Automatic)
To tell the Ethernet adapter to automatically request an IP address from the local router:
sudo networksetup -setdhcp "Ethernet"
Set a Static IP
To force the Ethernet adapter to use a specific, hard-coded IP address, Subnet Mask, and Router IP:
sudo networksetup -setmanual "Ethernet" 192.168.1.50 255.255.255.0 192.168.1.1
4. Managing DNS Servers
If a user is complaining that “the internet is down,” but you can successfully ping 8.8.8.8, the issue is DNS resolution. You can instantly force the Mac to use a reliable external DNS server (like Google or Cloudflare) via the terminal.
sudo networksetup -setdnsservers "Wi-Fi" 8.8.8.8 8.8.4.4
To verify the change was successful and see the current DNS servers:
networksetup -getdnsservers "Wi-Fi"
To clear the custom servers and revert back to whatever the router provides automatically, pass the word “Empty”:
sudo networksetup -setdnsservers "Wi-Fi" Empty
Conclusion
The networksetup command is the definitive tool for macOS network administration. By utilizing this utility, you can build bash scripts that instantly configure a Mac for a specific corporate environment—setting the Wi-Fi profile, locking the DNS, and defining the proxy settings—in a fraction of a second, without ever opening System Settings.