Bruviks blog

OS X, iOS, configuration management and stuff

Setting proxy settings on OS X from command line

OS X comes with a tool called networksetup, that lets you change networksettings on OS X from the command line. Among other things, it can be used to set proxy settings for network interfaces, even when the options are not visible in the GUI.

To list all network interfaces:

$ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
Thunderbolt Ethernet
Wi-Fi
VPN (Cisco IPSec)
Bluetooth DUN 2
iPad USB
iPhone
Bluetooth PAN

To list information about HTTPS proxy settings for a particular interface:

$ networksetup -getsecurewebproxy 'iPad USB'
Enabled: No
Server: 127.0.0.1
Port: 8888
Authenticated Proxy Enabled: 0

Similarly, this command showes proxy settings for HTTP proxies:

$ networksetup -getwebproxy 'iPad USB'
Enabled: No
Server: 127.0.0.1
Port: 8888
Authenticated Proxy Enabled: 0

Use man networksetup to see all options to networksetup. There are options to show all different settings for various proxies.

To turn on or off a proxy, use networksetup -setsecurewebproxystate 'iPad USB' on. This command turns on HTTPS-proxy for the iPad USB interface. You can use the same command to turn off.

The full command to change settings for the proxy is networksetup -setsecurewebproxy <networkservice> <domain> <port number> <authenticated> <username> <password> The <domain> and <portnumber> is the hostname and port of the proxy.