networksetup
"networksetup -- configuration tool for network settings in System Preferences." - man networksetup
networksetup
is a standard tool on MacOS
Examples
List all network services
Network Services are not the same as hardware devices.
$ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Ethernet Adapter (en4)
Wi-Fi
Thunderbolt Bridge
$ networksetup -listnetworkserviceorder
An asterisk (*) denotes that a network service is disabled.
(1) Ethernet Adapter (en4)
(Hardware Port: Thunderbolt Ethernet Slot 0, Device: en4)
(2) Wi-Fi
(Hardware Port: Wi-Fi, Device: en0)
(3) Thunderbolt Bridge
(Hardware Port: Thunderbolt Bridge, Device: bridge0)
Modify DNS for a device
Using Empty
is pretty unintuitive. This is used in a few other places in networksetup
.
$ networksetup -getdnsservers Wi-Fi
There aren't any DNS Servers set on Wi-Fi.
$ networksetup -setdnsservers Wi-Fi 8.8.8.8
$ networksetup -getdnsservers Wi-Fi
8.8.8.8
$ networksetup -setdnsservers Wi-Fi Empty
$ networksetup -getdnsservers Wi-Fi
There aren't any DNS Servers set on Wi-Fi.
Show info for the device named Wi-Fi
networksetup -getinfo "Wi-Fi"
Show all connected hardware ports
networksetup -listallhardwareports
Show all search domains
networksetup -listallnetworkservices |
tail -n +2 |
xargs -I :: networksetup -getsearchdomains "::"
Create a bunch of VLAN interfaces
for X in {1..32} ; do
sudo networksetup -createVLAN "vlan${X}" en3 "${X}" ;
done ;
Delete a bunch of VLAN interfaces
for X in {1..32} ; do
sudo networksetup -deleteVLAN "vlan${X}" en3 "${X}" ;
done ;