networksetup - macOS
Overview
networksetup is a macOS command-line tool for managing network settings and configurations. It offers comprehensive control over various network interfaces and provides advanced options for configuring network-related parameters.
Syntax
networksetup [command] [interface]
Commands
- listallhardwareports: List all available network hardware ports.
- listnetworkservices: List all active network services.
- createlocation: Create a new network location.
- deletelocation: Delete a network location.
- switchtolocation: Switch to a specific network location.
- listpreferredwirelessnetworks: List preferred wireless networks.
- setairportpower: Enable or disable the AirPort hardware.
- setdnsservers: Set the DNS servers for a specific interface.
- setgateways: Set the default gateways for a specific interface.
- setmacaddress: Set the MAC address for a specific interface.
- setproxy: Set proxy settings for a specific interface.
- setsecurewebproxy: Set secure web proxy settings for a specific interface.
- setwebproxy: Set web proxy settings for a specific interface.
- showpppoe: Display PPPoE settings for a specific interface.
- setuppppoe: Set up PPPoE for a specific interface.
Options/Flags
| Option/Flag | Description | Default |
|—|—|—|
| -h
| Display help | |
| -v
| Verbose mode | |
| -SetDNS
| Custom DNS servers | |
| -SetGateway
| Custom gateway | |
| -SetMACAddress
| Custom MAC address | |
| -SetProxy
| Proxy settings | |
| -SetSecureWebProxy
| Secure web proxy settings | |
| -SetWebProxy
| Web proxy settings | |
| -installdhcpclient
| Install customized DHCP client script | |
| -remove
| Remove network interface | |
Examples
-
List all network services:
networksetup listnetworkservices
-
Set DNS servers for Wi-Fi interface:
networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4
-
Disable Airport (Wi-Fi):
networksetup -setairportpower off
-
Set a static IP address for Ethernet interface:
networksetup -setmacaddress Ethernet 00:11:22:33:44:55 networksetup -setdnsservers Ethernet 8.8.8.8 8.8.4.4 networksetup -setgateways Ethernet 192.168.0.1 networksetup -setwebproxy Ethernet myproxy.example.com 8080
Common Issues
- “Command not found” error: Ensure that the command is run from the Terminal application and not from a shell script or other context.
- Permission denied: Run the command with administrator privileges (e.g.,
sudo networksetup
). - Invalid interface name: Verify that the specified interface name matches an existing physical or virtual interface.
Integration
- Combine with ifconfig to configure network interfaces in scripts.
- Use with scutil to manage system network settings.
- Create custom network scripts using networksetup -installdhcpclient.
Related Commands
- ifconfig: Manage network interfaces.
- scutil: Configure system network settings.
- airport: Control Wi-Fi settings.