Set IP on macOS: Configure Static and DHCP Addresses EasilyNetworking on macOS is usually seamless — plug in an Ethernet cable or connect to Wi‑Fi and your Mac gets an IP address automatically. However, there are many situations where you’ll want to set a specific IP address: running a local server, troubleshooting connectivity, using a development environment, configuring port forwarding on a router, or connecting to devices on a small LAN with static addressing. This article walks through macOS networking basics, how to configure both DHCP and static IP addresses via System Settings (System Preferences on older macOS versions) and Terminal, how to manage DNS and search domains, how to set up IP reservations on your router instead of device‑level static addresses, and troubleshooting tips.
Table of contents
- Basics: IP, DHCP, and static addressing
- Prepare: Gather information you need
- Set IP using System Settings (macOS Ventura and later)
- Set IP using System Preferences (macOS Monterey and earlier)
- Configure IP from Terminal (networksetup and ifconfig)
- Manage DNS and search domains
- Use DHCP reservations on your router (recommended alternative)
- Advanced: Multiple services, locations, and IPv6 considerations
- Troubleshooting common problems
- Security and best practices
- Quick reference commands
Basics: IP, DHCP, and static addressing
- IP address: numerical label that identifies your device on a network (IPv4 like 192.168.1.12 or IPv6 like fe80::1).
- DHCP (Dynamic Host Configuration Protocol): automatic assignment of IP address, subnet mask, gateway, and DNS by a DHCP server (commonly your router).
- Static IP: manually assigned address that doesn’t change unless you change it. Useful for servers, printers, and development machines.
- Subnet mask / prefix: defines the network portion of the address (e.g., 255.255.255.0 or /24).
- Router / gateway: the local network device that forwards traffic outside your LAN (e.g., 192.168.1.1).
- DNS: resolves domain names to IP addresses.
When to use DHCP: almost always for laptops and devices moving between networks.
When to use static IP: servers, network shares, printers, and when you need a predictable address.
Prepare: Gather information you need
Before setting a static IP, collect:
- Your desired IP address (choose an address outside the router’s DHCP pool or use a reservation; e.g., 192.168.1.100).
- Subnet mask or prefix length (commonly 255.255.255.0 or /24).
- Router / gateway IP (e.g., 192.168.1.1).
- DNS server addresses (your router, ISP, or public DNS like 1.1.1.1 or 8.8.8.8).
- Verify the IP isn’t already in use (ping it from another device, or from the Mac after changing, check for conflicts).
A quick way to see current settings: Apple menu → About This Mac → System Report → Network, or run in Terminal:
ifconfig scutil --dns netstat -rn
Set IP using System Settings (macOS Ventura and later)
- Open System Settings (click Apple menu → System Settings).
- In the sidebar choose Network.
- Select the interface you want to configure — e.g., Wi‑Fi or Ethernet.
- Click Details (or the Info button) for that interface.
- Under “Configure IPv4” choose:
- Automatically (DHCP) — device gets an IP from the network’s DHCP server.
- Manually — enter IP address, Subnet Mask (or Prefix Length), and Router (gateway).
- Enter DNS servers under DNS settings (click DNS and add server IPs) and add search domains if needed.
- Click Done, then Apply (if shown). macOS will apply the new settings immediately.
Notes:
- For Wi‑Fi, you may need to rejoin the network after switching to Manual.
- If you prefer DHCP with a manual IP lease, choose DHCP and then click “Renew DHCP Lease” — but to set a fixed address on the device you must use Manual (or set DHCP reservation on router).
Set IP using System Preferences (macOS Monterey and earlier)
- Open System Preferences → Network.
- Select the active interface from the left column (Wi‑Fi or Ethernet).
- Click Advanced → TCP/IP tab.
- For “Configure IPv4,” pick Using DHCP or Manually.
- If Manual, fill in IPv4 Address, Subnet Mask, and Router.
- Use the DNS tab to set DNS servers.
- Click OK → Apply to save changes.
Configure IP from Terminal (networksetup and ifconfig)
Terminal gives more control and is scriptable.
Check available network services:
networksetup -listallnetworkservices
Find current IPv4 configuration:
networksetup -getinfo "Wi-Fi"
Set an IPv4 address manually:
sudo networksetup -setmanual "Wi-Fi" 192.168.1.100 255.255.255.0 192.168.1.1
Where arguments are: service name, IP address, subnet mask, router.
Return to DHCP:
sudo networksetup -setdhcp "Wi-Fi"
Set DNS servers:
sudo networksetup -setdnsservers "Wi-Fi" 1.1.1.1 8.8.8.8
Clear DNS to use default (often router):
sudo networksetup -setdnsservers "Wi-Fi" Empty
(If you need to use CIDR prefix notation or more advanced configuration, use ifconfig and route commands — but networksetup covers most use cases.)
Example: using ifconfig to add an alias (temporary, resets on interface down/restart):
sudo ifconfig en0 alias 192.168.1.150 netmask 255.255.255.0
To see interface names:
ifconfig -a networksetup -listallhardwareports
Manage DNS and search domains
- DNS servers can be set per‑service in System Settings/Preferences or via networksetup.
- Search domains are useful for resolving short hostnames (e.g., ping server → server.example.local).
- Order of DNS resolution: per service settings → system resolver configuration.
- To flush DNS cache after changes:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
Use DHCP reservations on your router (recommended alternative)
Instead of setting a static IP on each device, assign a DHCP reservation in your router’s admin interface. This binds a specific IP to a device’s MAC address so the router always issues the same IP via DHCP. Benefits:
- Centralized control (easier to manage).
- Avoids IP conflicts caused by devices moving between networks.
- Keeps device network settings as DHCP (simpler for laptops).
General steps:
- Find your Mac’s MAC address (System Settings → Network → Details, or
ifconfig
/networksetup -getmacaddress "Wi-Fi"
). - Log into router admin page (usually 192.168.1.1).
- Locate DHCP reservation/Address Reservation/DHCP Static Lease.
- Add an entry with your MAC and desired IP.
- Save and reboot the device or renew DHCP lease.
Advanced: Multiple services, Locations, and IPv6
- Locations: macOS supports network “Locations” (System Settings → Network → Manage Locations) to store different sets of network settings (home, work).
- Multiple services: You can set static configs for Ethernet, Wi‑Fi, Thunderbolt, etc., independently.
- IPv6: macOS supports IPv6; in System Settings you can configure IPv6 to Automatic, Link‑local only, or Manually (rarely needed). Common IPv6 addresses are in the fe80::/64 range for link‑local.
- VPNs: VPN clients often create virtual network interfaces; configure IPs carefully to avoid route conflicts.
Troubleshooting common problems
- No connectivity after manual IP: check gateway and subnet—if gateway is outside the subnet, routing fails.
- IP conflict: if another device uses the same IP you’ll see intermittent connectivity. Change address or set a reservation.
- DNS resolution fails but ping IP works: check DNS servers and search domains. Try 1.1.1.1 or 8.8.8.8 to test.
- Wi‑Fi network settings not applying: remove network from Preferred Networks and rejoin, or reboot.
- Revert to DHCP if unsure:
sudo networksetup -setdhcp "Wi-Fi"
- Check routing table:
netstat -rn
- View current addresses:
ipconfig getifaddr en0 # IPv4 for en0 ipconfig getifaddr en1
Security and best practices
- Prefer DHCP with router reservations for portable devices.
- Use static IPs only for devices that need a fixed address.
- Keep static IPs outside the DHCP pool to avoid conflicts.
- Use strong router admin passwords and secure management interfaces.
- For server-facing services, consider also firewall rules and SSH key authentication rather than exposing services broadly.
Quick reference commands
- List network services:
networksetup -listallnetworkservices
- Get service info:
networksetup -getinfo "Wi-Fi"
- Set manual IP:
sudo networksetup -setmanual "Wi-Fi" 192.168.1.100 255.255.255.0 192.168.1.1
- Set DHCP:
sudo networksetup -setdhcp "Wi-Fi"
- Set DNS:
sudo networksetup -setdnsservers "Wi-Fi" 1.1.1.1 8.8.8.8
- Flush DNS cache:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
- Show interfaces:
ifconfig -a
If you want, I can provide step‑by‑step screenshots for your macOS version, a script to switch between DHCP and static IPs, or specific commands for IPv6 configuration.
Leave a Reply