# networksetup — Configure Network Settings via CLI

> Practical guide to networksetup — configure network services, Wi-Fi, DNS, proxies and interfaces on macOS from the command line.

Source: https://www.jpkc.com/db/en/cheatsheets/macos/networksetup/

<!-- PROSE:intro -->
`networksetup` is the CLI for macOS network system settings – use it to configure network services and interfaces, Wi-Fi, DNS, proxies and VPN directly from the command line. It is effectively the counterpart to "System Settings > Network", only scriptable and without the clicking. That makes it ideal for automation, remote administration over SSH and reproducible setups. This guide walks you through the commands you reach for daily, from listing services to setting a static IP and a proxy.
<!-- PROSE:intro:end -->

## List & Info

`networksetup -listallnetworkservices` — List all network services (interfaces).

```bash
networksetup -listallnetworkservices
```

`networksetup -listallhardwareports` — List hardware ports with device names and MAC addresses.

```bash
networksetup -listallhardwareports
```

`networksetup -getinfo '<service>'` — Show IP, subnet, router, and DNS for a service.

```bash
networksetup -getinfo 'Wi-Fi'
```

`networksetup -getmacaddress <device>` — Show the MAC address of a device.

```bash
networksetup -getmacaddress en0
```

## Wi-Fi

`networksetup -setairportpower en0 on` — Turn Wi-Fi on.

```bash
networksetup -setairportpower en0 on
```

`networksetup -setairportpower en0 off` — Turn Wi-Fi off.

```bash
networksetup -setairportpower en0 off
```

`networksetup -setairportnetwork en0 '<SSID>' '<password>'` — Connect to a Wi-Fi network.

```bash
networksetup -setairportnetwork en0 'MyNetwork' 'mypassword'
```

`networksetup -getairportnetwork en0` — Show the currently connected Wi-Fi network.

```bash
networksetup -getairportnetwork en0
```

`networksetup -listpreferredwirelessnetworks en0` — List preferred (saved) Wi-Fi networks.

```bash
networksetup -listpreferredwirelessnetworks en0
```

`networksetup -removepreferredwirelessnetwork en0 '<SSID>'` — Remove a saved Wi-Fi network.

```bash
networksetup -removepreferredwirelessnetwork en0 'OldNetwork'
```

## DNS

`networksetup -getdnsservers '<service>'` — Show DNS servers for a network service.

```bash
networksetup -getdnsservers 'Wi-Fi'
```

`networksetup -setdnsservers '<service>' <dns1> <dns2>` — Set DNS servers for a network service.

```bash
networksetup -setdnsservers 'Wi-Fi' 1.1.1.1 8.8.8.8
```

`networksetup -setdnsservers '<service>' empty` — Reset DNS to default (DHCP-provided).

```bash
networksetup -setdnsservers 'Wi-Fi' empty
```

`networksetup -getsearchdomains '<service>'` — Show search domains.

```bash
networksetup -getsearchdomains 'Wi-Fi'
```

`networksetup -setsearchdomains '<service>' <domain1> <domain2>` — Set search domains.

```bash
networksetup -setsearchdomains 'Wi-Fi' example.com local
```

## IP Configuration

`networksetup -setdhcp '<service>'` — Set a service to use DHCP.

```bash
networksetup -setdhcp 'Ethernet'
```

`networksetup -setmanual '<service>' <ip> <subnet> <router>` — Set a static IP address.

```bash
networksetup -setmanual 'Ethernet' 192.168.1.100 255.255.255.0 192.168.1.1
```

`networksetup -setv6automatic '<service>'` — Set IPv6 to automatic.

```bash
networksetup -setv6automatic 'Wi-Fi'
```

`networksetup -setv6off '<service>'` — Disable IPv6 on a service.

```bash
networksetup -setv6off 'Wi-Fi'
```

## Proxy

`networksetup -getwebproxy '<service>'` — Show HTTP proxy settings.

```bash
networksetup -getwebproxy 'Wi-Fi'
```

`networksetup -setwebproxy '<service>' <host> <port>` — Set HTTP proxy.

```bash
networksetup -setwebproxy 'Wi-Fi' proxy.example.com 8080
```

`networksetup -setwebproxystate '<service>' off` — Disable HTTP proxy.

```bash
networksetup -setwebproxystate 'Wi-Fi' off
```

`networksetup -setsocksfirewallproxy '<service>' <host> <port>` — Set SOCKS proxy.

```bash
networksetup -setsocksfirewallproxy 'Wi-Fi' localhost 1080
```

`networksetup -setproxybypassdomains '<service>' <domains>` — Set proxy bypass domains.

```bash
networksetup -setproxybypassdomains 'Wi-Fi' localhost 127.0.0.1 *.local
```

<!-- PROSE:outro -->
## Conclusion

`networksetup` makes macOS network configuration scriptable and therefore reproducible – ideal for provisioning, remote administration and quick DNS or proxy switches without clicking through System Settings. The writing commands (`-set…`) change active network, DNS, and proxy settings and usually require `sudo`; over SSH, a wrong value can cut your own connection, so test such changes carefully. Also note that Wi-Fi passwords passed as a plaintext argument to `-setairportnetwork` end up in your shell history and process list.

## Further Reading

- [networksetup in the macOS User Guide](https://support.apple.com/guide/terminal/welcome/mac) – Apple's Terminal documentation
- [man networksetup](https://keith.github.io/xcode-man-pages/networksetup.8.html) – complete man page with all options
<!-- PROSE:outro:end -->

## Related Commands

- [caffeinate](https://www.jpkc.com/db/en/cheatsheets/macos/caffeinate/) – prevent the Mac from going to sleep
- [defaults](https://www.jpkc.com/db/en/cheatsheets/macos/defaults/) – read and write macOS preferences (plist files)
- [diskutil](https://www.jpkc.com/db/en/cheatsheets/macos/diskutil/) – manage disks, volumes and partitions

