Get the Local IP of an Interface with ipconfig getifaddr
macOS's ipconfig prints a single address per interface — ideal for shell scripts and prompts.
Run `ipconfig getifaddr en0` to print only that interface's IPv4 address, with no extra formatting to strip.
01Command
Command
$ ipconfig getifaddr en0
# Which interface serves the default route:
route -n get default | awk '/interface:/{print $2}'02What it does
Unlike ifconfig, which dumps every interface plus flags, `ipconfig getifaddr en0` emits exactly one line — the IPv4 address — or nothing when the interface has no lease. That clean contract makes it the go-to for scripts that need the current Wi-Fi address in a variable. On desktop Macs en0 is usually Wi-Fi and en1 Ethernet, but the mapping varies, so pair it with `networksetup -listallhardwareports` to be sure.
03Risk
!Warning: The command prints nothing (empty output) on interfaces without an IPv4 lease — script for that case instead of assuming a value.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- ipconfig — macOS Command ReferenceEvidence: Documents getifaddr and getpacket for per-interface IP data.
Last verified: 2026-09-17 · Category: Network