How to Configure Network Location Profiles, DNS Search Domains, and Static Routes in macOS Terminal

Architectural Foundation of the macOS System Configuration Framework

Modern mobile engineering workstations frequently transition across diverse network environments—including high-security corporate LANs, data centre management fabrics, home offices, and remote client sites. In macOS, network interfaces and protocol bindings are governed by the System Configuration framework (configd daemon). The system maintains an authoritative XML dynamic store located at /Library/Preferences/SystemConfiguration/preferences.plist, orchestrating network interfaces, hardware addresses, proxy parameters, and routing tables.

A central capability within this architecture is Network Locations (Sets). A Network Location represents an isolated configuration snapshot encapsulating distinct network service orders, static IP assignments, DNS search domain lists, and MTU states. Rather than manually reconfiguring IP addresses or modifying proxy rules whenever you move between the office and the lab, switching network locations prompts configd to swap active preference keys atomically, re-initialising network interfaces without requiring a system reboot.

Network Parameter System Configuration Key CLI Management Utility Runtime Scope
Location Profile (Set) /Sets/[Set-ID]/ networksetup -switchtolocation System-wide interface bundle
Service Priority Order /Sets/[Set-ID]/Network/Global/IPv4 networksetup -ordernetworkservices Default gateway & metric precedence
DNS Search Domains /Network/Service/[UUID]/DNS networksetup -setsearchdomains Resolver short-name completion
Static Kernel Routes BSD Routing Socket (rt_msghdr) route / netstat -rn Kernel forwarding table (XNU)

Managing Network Locations via macOS Terminal

While macOS Ventura, Sonoma, and Sequoia streamlined the graphical System Settings menu, complete control over network location profiles, cloning, and switching remains fully accessible via the networksetup command-line interface.

Step 1: Audit and Enumerate Existing Network Locations

# List all configured network locations
networksetup -listlocations

# Identify the currently active network location
networksetup -getcurrentlocation

Step 2: Create and Populate a New Location Profile

To establish an isolated profile for data centre or corporate office use:

# 1. Create a new location titled "Corporate-Office" populated with active interfaces
networksetup -createlocation "Corporate-Office" populate

# 2. Switch the active macOS system state to the new location
networksetup -switchtolocation "Corporate-Office"

# 3. Verify the active profile switch
networksetup -getcurrentlocation
# Returns: Corporate-Office

Configuring Interface Service Priority Orders

When multiple network interfaces are active simultaneously (for example, Thunderbolt Ethernet and Wi-Fi), macOS routes traffic based on the Network Service Order. If Wi-Fi occupies a higher priority than physical Ethernet, high-bandwidth transfers inadvertently traverse slower wireless links.

# 1. Inspect the current service order and associated BSD interface names
networksetup -listnetworkserviceorder

# 2. Reorder interfaces to prioritize physical Ethernet over wireless connections
sudo networksetup -ordernetworkservices "Thunderbolt Ethernet" "USB 10/100/1000 LAN" "Wi-Fi"

# 3. Verify that Ethernet now occupies Index (1)
networksetup -listnetworkserviceorder

Configuring DNS Nameservers and Domain Search Lists

When connecting to enterprise intranets, querying short hostnames (such as jira or git-internal) requires configuring DNS Search Domains alongside upstream recursive nameservers.

# 1. Assign explicit primary and secondary DNS nameservers to Thunderbolt Ethernet
sudo networksetup -setdnsservers "Thunderbolt Ethernet" 10.200.0.10 10.200.0.11

# 2. Configure DNS search domains for automated FQDN completion
sudo networksetup -setsearchdomains "Thunderbolt Ethernet" "corp.enterprise.co.uk" "internal.lan"

# 3. Inspect the updated DNS configuration
networksetup -getdnsservers "Thunderbolt Ethernet"
networksetup -getsearchdomains "Thunderbolt Ethernet"

# 4. Flush the macOS mDNSResponder cache to apply changes immediately
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Establishing Persistent Static IP Routes in macOS

By default, executing sudo route add -net 10.150.0.0/16 192.168.1.254 modifies the XNU kernel routing table in volatile memory. When macOS disconnects from Wi-Fi or restarts, the static route is purged. To make static routes permanent across reboots and network toggles, construct a native launchd daemon.

Step 1: Create the Static Route Shell Script

# Create administrative directory and script
sudo mkdir -p /Library/Scripts/Network
sudo tee /Library/Scripts/Network/static_routes.sh << 'EOF'
#!/bin/bash
# Wait for primary interface initialization
sleep 5
# Inject persistent enterprise routes into the XNU kernel routing table
/sbin/route add -net 10.150.0.0/16 192.168.1.254
/sbin/route add -host 172.16.50.1 192.168.1.254
EOF

sudo chmod +x /Library/Scripts/Network/static_routes.sh

Step 2: Deploy a launchd Persistent Daemon

sudo tee /Library/LaunchDaemons/uk.co.enterprise.staticroutes.plist << 'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>uk.co.enterprise.staticroutes</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Library/Scripts/Network/static_routes.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <false/>
</dict>
</plist>
EOF

# Load and register the daemon
sudo launchctl load /Library/LaunchDaemons/uk.co.enterprise.staticroutes.plist

# Verify route in kernel table
netstat -rn -f inet | grep "10.150"

Troubleshooting macOS Network Locations and Routing Errors

Observed Anomaly Underlying Root Cause Technical Verification Method Remediation Protocol
Network Locations Missing in macOS System Settings GUI Apple moved the Location manager in Ventura+; GUI hides setting under advanced sub-menus System Settings does not display the legacy top-level “Location” dropdown Click System Settings > Network > … (three dots icon) > Locations, or use networksetup -switchtolocation in Terminal
Traffic Routes via Slower Wi-Fi Despite Ethernet Cable Connected Service order priority inverted; Wi-Fi ranks above Ethernet in the active Location Execute netstat -rn; default route (0.0.0.0) bound to en0 (Wi-Fi) instead of en5 Execute networksetup -ordernetworkservices to position Ethernet at Index 1
Short Hostnames Fail to Resolve on Intranet Search domains not appended to the active network interface, or mDNSResponder cached failure Run scutil --dns; check if target search domains appear in the resolver array Set search domains via networksetup -setsearchdomains and flush mDNSResponder
Static Route Drops Upon Sleep / Wake Cycle Manual route add was not registered with launchd; interface down event flushed route Interface wakes from sleep; pinging internal IP returns No route to host Deploy the launchd automation script to monitor network configuration state changes

Get the best tech tips delivered straight to your inbox.

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