macOS: ifconfig, ipconfig, networksetup and scutil
macOS is a BSD underneath, so it has ifconfig. It also has a command called ipconfig that has nothing to do with the Windows one, a configuration tool called networksetup that mirrors System Settings, and scutil for the system configuration database. Knowing which one to reach for saves a lot of time.
Which tool for which job
| Task | Command |
|---|---|
| See my IPv4 address | ipconfig getifaddr en0 |
| See everything about an interface | ifconfig en0 |
| See the address, mask, router and MAC in a readable form | networksetup -getinfo "Wi-Fi" |
| See the default gateway | route -n get default or netstat -rn | grep default |
| See DNS servers actually in use | scutil --dns |
| See DNS servers configured for a service | networksetup -getdnsservers "Wi-Fi" |
| See the DHCP lease details | ipconfig getpacket en0 |
| See the Wi-Fi network name and signal | wdutil info (macOS 14+, needs sudo) or networksetup -getairportnetwork en0 |
| Renew the DHCP lease | sudo ipconfig set en0 DHCP |
| Set a static IP | networksetup -setmanual "Wi-Fi" 192.168.1.50 255.255.255.0 192.168.1.1 |
| Set DNS servers | networksetup -setdnsservers "Wi-Fi" 1.1.1.1 1.0.0.1 |
| Flush DNS | sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder |
| Turn Wi-Fi off / on | networksetup -setairportpower en0 off / on |
| See which interface is en0 | networksetup -listallhardwareports |
| Public IP | curl ipconfig.co.uk/ip |
Interface names on a Mac
macOS numbers interfaces by driver, not by function, and the numbering depends on the hardware. Use networksetup -listallhardwareports to map names to ports:
networksetup -listallhardwareportsHardware Port: Ethernet Adapter (en5)
Device: en5
Ethernet Address: 00:e0:4c:68:1a:2b
Hardware Port: Wi-Fi
Device: en0
Ethernet Address: f0:18:98:3a:2b:1c
Hardware Port: Thunderbolt 1
Device: en1
Ethernet Address: 36:8a:2f:11:22:01
Hardware Port: Thunderbolt Bridge
Device: bridge0
Ethernet Address: 36:8a:2f:11:22:01
VLAN Configurations
===================| Name | What it is |
|---|---|
en0 | Wi-Fi on every Mac with built-in Wi-Fi made since about 2010. On older Macs with built-in Ethernet, en0 was Ethernet and en1 Wi-Fi. On the Mac mini and Mac Studio en0 is Ethernet. |
en1–en9 | Thunderbolt ports (each gets a virtual interface for IP-over-Thunderbolt), USB Ethernet adapters, docks, iPhone USB tethering |
lo0 | Loopback |
bridge0 | Thunderbolt Bridge; groups the Thunderbolt interfaces |
awdl0 | Apple Wireless Direct Link: AirDrop, AirPlay, Sidecar, Continuity |
llw0 | Low-latency WLAN, paired with awdl0 |
ap1 | The Wi-Fi access point interface used for Internet Sharing and Personal Hotspot |
utun0–utun9 | Tunnels: VPN apps, iCloud Private Relay, Tailscale. Two or three exist even with no VPN installed. |
gif0, stf0 | Generic and 6to4 tunnel placeholders; ignore |
anpi0, anpi1 | Apple internal (debug/USB-C) interfaces on Apple silicon; ignore |
vmenet0, bridge100 | Created by VMware Fusion, Parallels, Docker Desktop or UTM |
The names in networksetup commands are network service names ("Wi-Fi", "Ethernet", "USB 10/100/1000 LAN", "Thunderbolt Bridge"), not device names. networksetup -listallnetworkservices lists them; an asterisk marks a disabled service.
The macOS ipconfig command
/usr/sbin/ipconfig controls the macOS IP configuration agent (configd's IPConfiguration plugin). It has no relationship to Windows ipconfig beyond the name. It is the most convenient tool for one-line answers in scripts.
usage: ipconfig <command> <args>
where <command> is one of waitall, getifaddr, ifcount, getoption, getpacket, getv6packet,
getra, getsummary, getdhcpduid, getdhcpiaid, set, setverbose| Command | What it does |
|---|---|
ipconfig getifaddr en0 | Print the IPv4 address of en0, nothing else. Exit status 1 and no output if there is none. |
ipconfig getsummary en0 | Everything IPConfiguration knows about en0: DHCP lease, router, DNS, IPv6 state, Wi-Fi SSID (macOS 12+) |
ipconfig getpacket en0 | Decode the last DHCP ACK: server, lease time, all options. Empty if the interface is static. |
ipconfig getv6packet en0 | The same for DHCPv6 |
ipconfig getra en0 | The last IPv6 router advertisement received (macOS 13+) |
ipconfig getoption en0 router | One DHCP option by name or number: router, domain_name_server, subnet_mask, lease_time, domain_name, server_identifier, or a number such as 42 |
ipconfig ifcount | Number of interfaces |
ipconfig getdhcpduid / getdhcpiaid en0 | DHCPv6 identifiers |
ipconfig waitall | Block until all interfaces have finished configuring; used by startup scripts |
sudo ipconfig set en0 DHCP | Switch to DHCP, which also renews the lease |
sudo ipconfig set en0 MANUAL 192.168.1.50 255.255.255.0 | Static address (temporary; the setting in System Settings still says DHCP) |
sudo ipconfig set en0 BOOTP | Use BOOTP |
sudo ipconfig set en0 NONE | Remove IPv4 configuration |
sudo ipconfig set en0 AUTOMATIC-V6 / MANUAL-V6 addr prefixlen / 6TO4 / LINKLOCAL-V6 / NONE-V6 | IPv6 modes |
sudo ipconfig setverbose 1 | Verbose logging from IPConfiguration to the unified log |
ipconfig getifaddr en0
ipconfig getoption en0 router
ipconfig getoption en0 domain_name_server
ipconfig getoption en0 lease_time192.168.1.23
192.168.1.1
192.168.1.1
86400ipconfig getpacket en0op = BOOTREPLY
htype = 1
flags = 0
hlen = 6
hops = 0
xid = 0x6a1b3c4d
secs = 0
ciaddr = 192.168.1.23
yiaddr = 192.168.1.23
siaddr = 0.0.0.0
giaddr = 0.0.0.0
chaddr = f0:18:98:3a:2b:1c
sname =
file =
options:
Options count is 7
dhcp_message_type (uint8): ACK 0x5
server_identifier (ip): 192.168.1.1
lease_time (uint32): 0x15180
subnet_mask (ip): 255.255.255.0
router (ip_mult): {192.168.1.1}
domain_name_server (ip_mult): {192.168.1.1}
domain_name (string): homeThe set … DHCP form is the command-line equivalent of the Renew DHCP Lease button in System Settings, and it is the fix for a Mac stuck on a 169.254 self-assigned address once the underlying problem is solved.
ifconfig on macOS
Covered in full on the ifconfig page. The macOS-specific points:
- Netmasks print in hex (
0xffffff00= /24). ifconfig -llists names;ifconfig -ushows only interfaces that are up;ifconfig -v en0is verbose;ifconfig -Ladds IPv6 lifetimes.- Address changes made with ifconfig are overwritten as soon as the DHCP client or
configdnext runs, which can be seconds. Usenetworksetuporipconfig setfor anything you want to survive. sudo ifconfig en0 downon Wi-Fi disconnects it;upreconnects.- To change the Wi-Fi MAC:
sudo ifconfig en0 ether 02:xx:xx:xx:xx:xxwhile disassociated. macOS 15 and later can randomise it per network in System Settings, which is normally the better choice.
networksetup
networksetup is the command-line face of the Network pane in System Settings. Its changes are persistent and per network service and location. Most setter commands need sudo; getters do not.
Viewing
networksetup -listallnetworkservices
networksetup -listallhardwareports
networksetup -listnetworkserviceorder
networksetup -getinfo "Wi-Fi"
networksetup -getdnsservers "Wi-Fi"
networksetup -getsearchdomains "Wi-Fi"
networksetup -getmacaddress en0
networksetup -getMTU en0
networksetup -getairportpower en0
networksetup -getairportnetwork en0
networksetup -getwebproxy "Wi-Fi"
networksetup -getcurrentlocation
networksetup -listlocations$ networksetup -getinfo "Wi-Fi"
DHCP Configuration
IP address: 192.168.1.23
Subnet mask: 255.255.255.0
Router: 192.168.1.1
Client ID:
IPv6: Automatic
IPv6 IP address: none
IPv6 Router: none
Wi-Fi ID: f0:18:98:3a:2b:1c-getdnsservers prints There aren't any DNS Servers set on Wi-Fi. when DNS comes from DHCP; that is not an error. To see the servers actually in use, run scutil --dns. On macOS 14 and later -getairportnetwork may print You are not associated with an AirPort network for privacy reasons even when connected; use sudo wdutil info or ipconfig getsummary en0 | grep SSID instead.
Setting a static IP
sudo networksetup -setmanual "Wi-Fi" 192.168.1.50 255.255.255.0 192.168.1.1
# back to DHCP
sudo networksetup -setdhcp "Wi-Fi"
# DHCP with a manual address (DHCP for router/DNS, fixed IP)
sudo networksetup -setmanualwithdhcprouter "Wi-Fi" 192.168.1.50
# DHCP with a client ID
sudo networksetup -setdhcp "Wi-Fi" myclientidDNS and search domains
sudo networksetup -setdnsservers "Wi-Fi" 1.1.1.1 1.0.0.1
sudo networksetup -setdnsservers "Wi-Fi" Empty # back to DHCP-supplied
sudo networksetup -setsearchdomains "Wi-Fi" home.arpa
sudo networksetup -setsearchdomains "Wi-Fi" EmptyIPv6
networksetup -getinfo "Wi-Fi" | grep IPv6
sudo networksetup -setv6automatic "Wi-Fi"
sudo networksetup -setv6linklocal "Wi-Fi" # effectively disables global IPv6
sudo networksetup -setv6off "Wi-Fi" # newer versions
sudo networksetup -setv6manual "Wi-Fi" 2001:db8::50 64 2001:db8::1Wi-Fi
networksetup -setairportpower en0 off
networksetup -setairportpower en0 on
networksetup -setairportnetwork en0 "MySSID" "password"
networksetup -listpreferredwirelessnetworks en0
sudo networksetup -removepreferredwirelessnetwork en0 "OldSSID"
sudo networksetup -addpreferredwirelessnetworkatindex en0 "MySSID" 0 WPA2 "password"Other useful setters
sudo networksetup -setMTU en0 1400
sudo networksetup -setnetworkserviceenabled "Thunderbolt Bridge" off
sudo networksetup -ordernetworkservices "Ethernet" "Wi-Fi" "Thunderbolt Bridge"
sudo networksetup -setwebproxy "Wi-Fi" proxy.example.com 8080
sudo networksetup -setwebproxystate "Wi-Fi" off
sudo networksetup -createlocation Office populate
sudo networksetup -switchtolocation Office
sudo networksetup -setcomputername "my-mac"networksetup -help lists around 100 commands; networksetup -printcommands gives a compact list.
scutil
scutil reads the System Configuration dynamic store, which is the source of truth for what the system is actually using right now.
scutil --dns # resolver configuration, per interface and scoped
scutil --nwi # network information: primary interface, reachability
scutil --proxy # proxy settings
scutil --get HostName
scutil --get LocalHostName
scutil --get ComputerName
sudo scutil --set HostName my-mac.home.arpa
sudo scutil --set LocalHostName my-mac
sudo scutil --set ComputerName "My Mac"$ scutil --nwi
Network information
IPv4 network interface information
en0 : flags : 0x5 (IPv4,DNS)
address : 192.168.1.23
reach : 0x00000002 (Reachable)
REACH : flags 0x00000002 (Reachable)
IPv6 network interface information
No IPv6 states found
REACH : flags 0x00000000 (Not Reachable)
Network interfaces: en0scutil --dns is the only reliable way to see DNS on a Mac, because macOS has per-interface, per-domain and VPN-scoped resolvers that networksetup does not show. Look at resolver #1 for the servers used by default. There is no /etc/resolv.conf worth reading; the file exists for BSD compatibility and is often stale.
Interactive mode lets you walk the store: scutil then list, then show State:/Network/Global/IPv4 to see the primary interface and router, or show State:/Network/Service/<id>/DHCP for lease details.
Routing and ARP
route -n get default # default gateway and interface
netstat -rn # full routing table
netstat -rn -f inet # IPv4 only
sudo route add -net 10.0.0.0/8 192.168.1.254
sudo route delete -net 10.0.0.0/8
sudo route flush # dangerous: removes all routes
arp -a # ARP cache
arp -an # without name resolution
sudo arp -d -a # clear the ARP cache
ndp -an # IPv6 neighbour cache$ route -n get default
route to: default
destination: default
mask: default
gateway: 192.168.1.1
interface: en0
flags: <UP,GATEWAY,DONE,STATIC,PRCLO,GLOBAL>
recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu expire
0 0 0 0 0 0 1500 0Note the BSD route syntax (route add -net, no gw keyword) differs from Linux net-tools.
DNS on macOS
# flush the resolver cache
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
# look something up the way the system would (honours scoped resolvers, hosts file, mDNS)
dscacheutil -q host -a name example.com
# look something up directly with DNS
dig example.com
nslookup example.com
host example.com
# DNS-over-HTTPS/TLS status (macOS 11+)
scutil --dns | grep -i -A2 'flags'The two-command flush is needed because dscacheutil clears the Directory Services cache while mDNSResponder holds the actual DNS cache; the HUP tells it to drop everything. Older versions used discoveryutil (10.10) or just killall -HUP mDNSResponder. All versions →
Wi-Fi diagnostics
sudo wdutil info # macOS 14+: SSID, BSSID, RSSI, channel, security, IP
sudo wdutil diagnose # collect a full diagnostics bundle to /private/tmp
system_profiler SPAirPortDataType # hardware and current network details
networksetup -getairportnetwork en0
ipconfig getsummary en0 | grep -E 'SSID|BSSID|Security'The old airport binary in /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/ (airport -I, airport -s for scanning) was removed in macOS 14.4. wdutil and system_profiler replace it. Holding Option while clicking the Wi-Fi menu still shows the same information graphically and offers Open Wireless Diagnostics.
Other macOS commands
| Command | Purpose |
|---|---|
hostname | The current hostname (may differ from ComputerName) |
netstat -an | grep LISTEN | Listening ports |
lsof -i -P -n | grep LISTEN | Listening ports with process names (the macOS equivalent of ss -tulpn) |
lsof -i :443 | What is using a port |
traceroute example.com | Path to a host; traceroute6 for IPv6 |
ping -c 4 example.com | Reachability; ping6 for IPv6 |
nc -zv host 443 | Test a TCP port |
sudo tcpdump -i en0 -n port 53 | Packet capture |
sysctl net.inet.ip.forwarding | Is IP forwarding on |
sudo sysctl -w net.inet.ip.forwarding=1 | Enable forwarding (until reboot) |
sudo pfctl -s rules | Firewall (pf) rules |
/System/Library/PrivateFrameworks/SystemAdministration.framework/Resources/activateSettings -u | Apply settings changed by some scripts (rarely needed) |
sudo launchctl kickstart -k system/com.apple.mDNSResponder | Restart mDNSResponder |
sudo ifconfig en0 down; sudo ifconfig en0 up | Bounce an interface |
Full network reset on macOS
There is no single "network reset" button as in Windows. The closest equivalent, for a Mac whose networking is thoroughly confused:
- Turn Wi-Fi off, wait ten seconds, turn it on. Renew the DHCP lease:
sudo ipconfig set en0 DHCP. - Flush DNS:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder. - Forget and re-join the Wi-Fi network:
sudo networksetup -removepreferredwirelessnetwork en0 "SSID", then join again. - Remove the network service and re-add it: System Settings › Network › … › Delete Service, then Add Service.
- Move the preference files aside and reboot:
sudo mkdir ~/Desktop/netprefs && sudo mv /Library/Preferences/SystemConfiguration/{NetworkInterfaces.plist,preferences.plist,com.apple.airport.preferences.plist,com.apple.network.eapolclient.configuration.plist} ~/Desktop/netprefs/. macOS recreates them at boot. This is the nuclear option and forgets every saved network and location. - Reset the SMC or NVRAM on Intel Macs; on Apple silicon just restart.