networksetup on macOS: DNS, Wi-Fi, Proxies, and Service Order

Run a Speed Test

networksetup is the macOS command-line tool for many settings hidden behind System Settings. It is especially useful for DNS, proxies, Wi-Fi power, and service order.

Quick Answer

Use networksetup when you need to inspect or change macOS network settings from Terminal. It is safer than editing /Library/Preferences/SystemConfiguration/ preference files directly, scriptable for repeatable configs, and often faster than navigating several System Settings panes — especially during remote sessions where GUI access is awkward.

Step 1: Find Your Service Names

Every networksetup command that targets a specific interface uses a service name, not a BSD interface name. Get the exact names first:

# List all network services
networksetup -listallnetworkservices

# Get detailed info about a service
networksetup -getinfo "Wi-Fi"
networksetup -getinfo "Ethernet"
networksetup -getinfo "USB 10/100/1000 LAN"

The service names are case-sensitive and must match exactly. Common names are Wi-Fi, Ethernet, Thunderbolt Ethernet, and USB 10/100/1000 LAN. VPN services also appear in this list.

DNS Commands

# Read current DNS servers
networksetup -getdnsservers "Wi-Fi"

# Set custom DNS (Cloudflare)
sudo networksetup -setdnsservers "Wi-Fi" 1.1.1.1 1.0.0.1

# Set custom DNS (Google)
sudo networksetup -setdnsservers "Wi-Fi" 8.8.8.8 8.8.4.4

# Reset DNS to DHCP-automatic
sudo networksetup -setdnsservers "Wi-Fi" Empty

# Read search domains
networksetup -getsearchdomains "Wi-Fi"

# Clear search domains
sudo networksetup -setsearchdomains "Wi-Fi" Empty

DNS changes take effect immediately without a restart. Flush the DNS cache after changing: sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Wi-Fi Control

# Check Wi-Fi power state
networksetup -getairportpower en0

# Turn Wi-Fi off
sudo networksetup -setairportpower en0 off

# Turn Wi-Fi on
sudo networksetup -setairportpower en0 on

# List available Wi-Fi networks
networksetup -listpreferredwirelessnetworks en0

# Remove a saved network
sudo networksetup -removepreferredwirelessnetwork en0 "NetworkName"

# Join a network
networksetup -setairportnetwork en0 "NetworkName" "password"

Replace en0 with your actual Wi-Fi interface — find it with networksetup -listallhardwareports.

Proxy Settings

# Check HTTP proxy
networksetup -getwebproxy "Wi-Fi"

# Check HTTPS proxy
networksetup -getsecurewebproxy "Wi-Fi"

# Check SOCKS proxy
networksetup -getsocksfirewallproxy "Wi-Fi"

# Disable HTTP proxy
sudo networksetup -setwebproxystate "Wi-Fi" off

# Disable HTTPS proxy
sudo networksetup -setsecurewebproxystate "Wi-Fi" off

Stale proxy settings are a common cause of browsers failing while ping and traceroute still work. Check all three proxy types when only web traffic is broken and network connectivity appears fine.

Network Service Order

# View current service order
networksetup -listnetworkserviceorder

# Set service order (first listed has highest priority)
sudo networksetup -ordernetworkservices "Ethernet" "Wi-Fi" "Thunderbolt Bridge"

macOS uses the service order to determine which interface handles traffic when multiple are active. Put wired Ethernet above Wi-Fi so that plugging in a cable automatically takes priority.

Hardware Ports and Interface Names

# Map service names to BSD interface names (en0, en1, etc.)
networksetup -listallhardwareports

This command is essential for finding which BSD interface name (en0, en1, utun0) corresponds to which physical or virtual adapter. Use it before any command that takes an interface name rather than a service name.

When This Helps

networksetup is ideal for:

  • Documenting the exact DNS and proxy configuration of a Mac for a support ticket
  • Clearing stale VPN proxy settings that security software left behind
  • Scripting a known-good network configuration that can be applied after security policy changes
  • Diagnosing why browsers fail while ping and SSH work (almost always a proxy issue)
  • Remote sessions via SSH where System Settings is not accessible
  • MDM scripting where network settings need to be applied programmatically

Frequently Asked Questions

Is networksetup built into macOS?

Yes. It ships with every macOS version and runs from Terminal with no installation. It is the same tool that System Settings uses under the hood for most network preference changes.

Do I need sudo?

Read-only commands (getting DNS, listing services, checking proxy state) do not require sudo. Write commands (setting DNS, changing proxy state, controlling Wi-Fi power) require sudo. Running without sudo on a write command gives a "Error: Could not find default configuration" or permission error.

How do I reset DNS to automatic?

Use sudo networksetup -setdnsservers "Wi-Fi" Empty, replacing Wi-Fi with your exact service name from -listallnetworkservices. The literal word Empty tells networksetup to remove all custom DNS entries and revert to DHCP-assigned servers. Follow with a DNS cache flush.

Why does networksetup show a different interface than ifconfig?

networksetup uses logical service names (human-readable, from System Settings). ifconfig and ping use BSD interface names (en0, en1, utun0). Use networksetup -listallhardwareports to see the mapping between them.

Related Guides

More From This Section