How to Use the macOS networksetup Command to Manage Wi-Fi Connections

Beyond the System Settings GUI

When you need to connect a Mac to Wi-Fi, change DNS servers, or set up a static IP address, the standard method is to open “System Settings” (or “System Preferences” on older macOS versions), navigate to the Network panel, and click through various graphical menus.

While this is fine for casual use, it is highly inefficient for IT administrators or power users. If you need to quickly diagnose a connection drop, force a Mac to prioritize a specific Wi-Fi network, or script a network configuration across fifty corporate laptops, clicking through menus is not a viable option.

macOS includes a powerful command-line utility called networksetup. This tool allows you to manipulate virtually every aspect of your Mac’s networking stack directly from the Terminal, often bypassing GUI glitches entirely.

Step 1: Identifying Network Interfaces

Before you can modify a connection, you must know what the system calls it. macOS hardware interfaces are assigned specific device names (like en0 or en1).

To list all available network hardware on your Mac, open the Terminal and run:

networksetup -listallhardwareports

You will see an output similar to this:

Hardware Port: Wi-Fi
Device: en0
Ethernet Address: f8:4d:89:12:34:56

Hardware Port: Thunderbolt Bridge
Device: bridge0

In almost all modern MacBooks, the Wi-Fi card is assigned the device identifier en0. Keep this in mind for future commands.

Step 2: Connecting to a Wi-Fi Network via Terminal

If your graphical interface has crashed, or you are managing a Mac remotely via SSH, you can scan for and connect to Wi-Fi networks entirely via the command line.

First, verify that Wi-Fi is actually turned on. You can power it on with:

networksetup -setairportpower en0 on

Next, you can command the Mac to join a specific network, assuming you know the SSID (network name) and the password. The syntax is -setairportnetwork [interface] [SSID] [Password].

networksetup -setairportnetwork en0 "Office_Guest" "SecurePass123"

The command will pause for a few seconds while the handshake occurs, and then return you to the prompt if successful.

Step 3: Changing DNS Servers

If your internet feels sluggish, or certain websites refuse to load, your ISP’s default DNS servers might be failing. You can instantly force your Wi-Fi connection to use a faster, more secure public DNS (like Google’s 8.8.8.8 or Cloudflare’s 1.1.1.1).

The syntax requires you to use the “Hardware Port” name (e.g., “Wi-Fi”), not the device identifier (en0).

To set your Wi-Fi to use Google DNS, type:

networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4

If you ever want to clear these custom servers and revert to whatever your router provides automatically, run the command with the word “Empty”:

networksetup -setdnsservers Wi-Fi Empty

Step 4: Forcing a Static IP Address

By default, your Mac requests an IP address from your router via DHCP. However, if you are hosting a local web server or file share, you want your Mac’s IP address to remain permanent (Static).

You can configure a static IP directly from the terminal. You must provide the desired IP, the Subnet Mask, and the Router (Gateway) IP.

sudo networksetup -setmanual Wi-Fi 192.168.1.50 255.255.255.0 192.168.1.1

(Note: Modifying core IP settings requires administrator privileges, so you must prefix this command with sudo and enter your Mac password.)

To revert back to automatic DHCP assigning, simply run:

sudo networksetup -setdhcp Wi-Fi

Get the best tech tips delivered straight to your inbox.

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