How to Use the scutil and networksetup Commands in macOS Terminal to Manage DNS and Network Interfaces

On macOS, configuring network settings, static IP assignments, VPN split tunneling, and DNS resolvers cannot be reliably done by editing standard Unix text files like /etc/resolv.conf. The macOS networking subsystem is governed by Apple’s System Configuration framework (configd). The built-in command-line tools networksetup (high-level network service management) and scutil (System Configuration utility) provide complete programmatic control over network hardware, proxy rules, and dynamic DNS resolvers directly from Terminal.

Listing and Auditing Network Interfaces with networksetup

Before modifying network parameters, identify the active network service names and their associated hardware BSD interface names (e.g., en0 for Wi-Fi, en5 for Thunderbolt Ethernet):

# List all hardware network interfaces and MAC addresses
networksetup -listallhardwareports

# List configured network service names
networksetup -listallnetworkservices
Command Target Scope Elevation Required
networksetup -getinfo "Wi-Fi" Displays active IP, subnet mask, and router IP. No
networksetup -setdnsservers "Wi-Fi" <IPs> Configures static upstream DNS resolvers. Yes (sudo)
scutil --dns Outputs full multi-scoped DNS resolver routing table. No
scutil --get HostName Inspects the persistent system HostName. No
networksetup -ordernetworkservices Sets service binding priority order (e.g., Ethernet before Wi-Fi). Yes (sudo)

Configuring Custom DNS Resolvers and Search Domains

To assign privacy-preserving or high-performance DNS resolvers (such as Cloudflare 1.1.1.1 or Google 8.8.8.8) to the Wi-Fi service:

# Assign primary and secondary DNS resolvers
sudo networksetup -setdnsservers "Wi-Fi" 1.1.1.1 1.0.0.1 2606:4700:4700::1111

# Verify assigned DNS servers
networksetup -getdnsservers "Wi-Fi"

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

Inspecting Multi-Scoped DNS Routing with scutil –dns

Modern macOS handles DNS per-interface and per-domain (essential for VPN corporate connections). While cat /etc/resolv.conf shows a legacy stub, scutil --dns reveals the true active resolver configuration:

scutil --dns

Output shows distinct numbered resolver sections (e.g., resolver #1 for standard traffic, and dedicated resolvers for domain suffixes like .corp.internal). If an internal domain fails to resolve over VPN, checking scutil --dns identifies which interface owns the domain routing rule.

Setting Static IP Addresses and Default Gateways

To configure a manual static IPv4 address on an Ethernet interface:

# Syntax: -setmanual <service> <ip> <subnet> <router>
sudo networksetup -setmanual "Ethernet" 192.168.1.50 255.255.255.0 192.168.1.1

# Switch back to dynamic DHCP
sudo networksetup -setdhcp "Ethernet"

Flushing mDNS and Resolving Hostname Drift

Whenever you update DNS records or switch network environments, clear the local mDNSResponder cache:

sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

To set system hostnames uniformly across local networks, use scutil to configure all three hostname attributes simultaneously:

sudo scutil --set ComputerName "MacBook-Engineering"
sudo scutil --set LocalHostName "MacBook-Engineering"
sudo scutil --set HostName "macbook-engineering.local"

Using networksetup and scutil ensures full compatibility with macOS System Configuration daemons without breaking network profiles.

Get the best tech tips delivered straight to your inbox.

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