How to Use the macOS networksetup Command for Advanced Wi-Fi and Proxy Configuration

The Limitation of System Settings

For standard users, configuring a network connection on macOS is a simple affair: click the Wi-Fi icon in the menu bar, select a network, and type the password.

However, for system administrators managing a fleet of Macs, this graphical interface is completely useless. If you need to deploy an automated script that connects a MacBook to a hidden corporate Wi-Fi network, explicitly sets the DNS servers to an internal domain controller, and configures an authenticated HTTP proxy for web filtering, you cannot rely on the user clicking through menus.

To control the macOS networking stack programmatically, Apple provides the highly powerful networksetup command-line utility. This tool allows administrators to read, write, and aggressively modify every aspect of the Mac’s networking hardware directly from the terminal.

Step 1: Identifying Network Services

macOS does not interact directly with raw hardware devices (like en0 or en1) when configuring IPs and DNS. Instead, it interacts with “Network Services” (the logical names that appear in System Settings, such as “Wi-Fi” or “Ethernet”).

Before configuring anything, you must list all available network services to ensure you are targeting the correct one:

networksetup -listallnetworkservices

The output will typically include:

Wi-Fi
Thunderbolt Ethernet
Bluetooth PAN

Note: If a service name contains a space (like “Thunderbolt Ethernet”), you must enclose it in quotation marks when using it in subsequent commands.

Step 2: Advanced Wi-Fi Management

The networksetup command is the definitive way to manage wireless connections via bash scripts.

To ensure the Wi-Fi radio is physically turned on:

networksetup -setairportpower en0 on

(Assuming en0 is your Wi-Fi hardware port; you can verify this by running networksetup -listallhardwareports).

To forcefully join a specific Wi-Fi network and supply the WPA2 password in a single command:

networksetup -setairportnetwork en0 "Corporate_Secure" "SuperSecretPassword123"

This command is frequently embedded into MDM deployment scripts. When a new Mac boots up during provisioning, the script executes this command, connecting the Mac to the network instantly so it can begin downloading corporate software packages without user intervention.

Step 3: Configuring Static IP and DNS Servers

While most environments use DHCP, servers (like a Mac Mini running Xcode Server) or specialized lab machines often require static IP addresses.

To configure a static IP on the Ethernet interface:

networksetup -setmanual "Ethernet" 192.168.10.50 255.255.255.0 192.168.10.1

To revert the interface back to automatic IP assignment via DHCP:

networksetup -setdhcp "Ethernet"

Even if you are using DHCP, you may want to override the DNS servers provided by the router and force the Mac to use specific enterprise DNS (e.g., Cisco Umbrella or internal Domain Controllers):

networksetup -setdnsservers "Wi-Fi" 10.0.1.15 8.8.8.8

To clear the custom DNS servers and return to the DHCP-provided defaults, pass the word “Empty”:

networksetup -setdnsservers "Wi-Fi" "Empty"

Step 4: Configuring HTTP and HTTPS Proxies

In highly secure enterprise environments, direct outbound internet access is often blocked at the firewall. All web traffic must be explicitly routed through a corporate proxy server (like a Squid proxy or a Fortinet appliance) for inspection.

You can use networksetup to configure these proxies instantly across the entire operating system.

To configure the HTTP proxy for the Wi-Fi interface:

networksetup -setwebproxy "Wi-Fi" proxy.company.internal 8080

To configure the HTTPS (Secure) proxy:

networksetup -setsecurewebproxy "Wi-Fi" proxy.company.internal 8080

If the proxy requires authentication, you can append the username and password directly to the command (though this is risky as it leaves plaintext passwords in the bash history):

networksetup -setwebproxy "Wi-Fi" proxy.company.internal 8080 on "username" "password"

Finally, to ensure the Mac doesn’t attempt to use the proxy to reach local servers (which would cause a massive routing loop), you must define bypass domains:

networksetup -setproxybypassdomains "Wi-Fi" "*.company.local" "192.168.*.*" "localhost" "127.0.0.1"

Step 5: Managing Network Locations

macOS supports “Locations”—entire sets of network configurations bundled together. A user might have a “Home” location (using standard DHCP) and an “Office” location (using static IPs and proxies).

Administrators can use networksetup to create and switch between these profiles dynamically.

networksetup -createlocation "Office_Secure"
networksetup -switchtolocation "Office_Secure"

By scripting this switch, an IT department can use a tool like ControlPlane to detect when a Mac connects to the corporate VPN, and automatically trigger a bash script that switches the Network Location to enforce strict proxy and DNS rules, reverting them the moment the VPN disconnects.

Conclusion

The networksetup command is the absolute cornerstone of macOS network automation. By moving beyond the graphical System Settings and mastering this utility, Mac administrators can effortlessly script massive deployments, seamlessly configure complex enterprise proxy routing, and forcefully manage the exact state of every network interface on their fleet.

RELATED POSTS

  • How to Enable and Configure macOS Content Caching to Save Bandwidth
  • How to Use macOS Network Utility Command Line Alternatives for Network Diagnostics
  • How to Manage and Reclaim Storage Space on macOS
  • How to Create a Spanning Bootable RAID 0 Array on macOS Using Disk Utility
  • How to Securely Erase and Factory Reset Your Mac Before Selling
  • Get the best tech tips delivered straight to your inbox.

    Join thousands of readers mastering Apple, Google, Microsoft, and Linux.