You can also change the proxy server setting, which is a system-wide setting, from within some browsers, e.g., Google Chrome, where you could take the following steps to get to the SOCKS proxy server settings window.
That will take you to the System Preferences window where you can change the proxy server setting as you did above.
Alternatively, if you prefer to use a
command line interface (CLI), such as you would get by running the
Terminal
application found in Applications/Utilities
, you can
use the networksetup command.
You can use the networksetup -getsocksfirewallproxy
networkservice
command, where networkservice is a
particular network service, such as Wi-Fi, to check the settings.
You can check which network services are available with the
networksetup -listallnetworkservices
command.
$ networksetup -listallnetworkservices An asterisk (*) denotes that a network service is disabled. Bluetooth DUN Thunderbolt Ethernet USB Ethernet Thunderbolt Ethernet Slot 2 Wi-Fi Bluetooth PAN Thunderbolt Bridge
E.g., I can check on whether a SOCKS proxy is being used and the
setting for the SOCKS proxy port on a MacBook Pro laptop's WiFi connection using
networksetup -getsocksfirewallproxy Wi-Fi
.
$ networksetup -getsocksfirewallproxy Wi-Fi Enabled: No Server: 127.0.0.1 Port: 1080 Authenticated Proxy Enabled: 0
In the example above, the SOCKS proxy is not being used, though the
port is set to 1080 and the SOCKS proxy server IP address is the
localhost
address 127.0.0.1
. If I had used an
SSH
connection from the system with the -D
option, e.g.
ssh -D 1080 jdoe@example.com
, to an SSH server to set up the SOCKS
proxy then 127.0.0.1
is the address I would specify for the SOCKS
server, since it is set up on the local system and is
tunneled over the SSH connection.
When it is enabled, you will see output similar to the following, if you check the SOCKS proxy state.
$ networksetup -getsocksfirewallproxy Wi-Fi Enabled: Yes Server: 127.0.0.1 Port: 1080 Authenticated Proxy Enabled: 0
You will still see "Enabled: No" for the web proxy state, even though the
proxy server address and port may be set, if the network service is not
configured currently to use a SOCKS proxy. If you are using a SOCKS proxy rather
than an HTTP proxy as a proxy
server, you will see "Enabled: No", if you specfy the
getwebproxy
parameter rather than the getsocksfirewallproxy
parameter.
$ networksetup -getwebproxy Wi-Fi Enabled: No Server: Port: 0 Authenticated Proxy Enabled: 0 $
If a SOCKS proxy server isn't being used and you have created a SOCKS proxy server with a tunneled SSH connection, you can enable its use with the command shown below. Your account will need administrator-level access and you will receive a password prompt where you can enter your account's password.
$ sudo networksetup -setsocksfirewallproxy Wi-Fi 127.0.0.1 1080 Password: $
You would see the settings below, if you then checked the settings through the graphical user interface (GUI) mechanism for viewing and changing the network settings through System Preferences.
If I wanted to turn SOCKS proxy server support for the Wi-Fi
connection off or on, I could use -setsocksfirewallproxystate
networkservice on | off
. E.g.:
$ sudo networksetup -setsocksfirewallproxystate Wi-Fi off Password:
If you issue the above command without using sudo, a GUI window will appear prompting you to provide the credentials for an account with administrator access to the system to allow the change to occur.
To avoid that window appearing, put sudo
in front of the
command, so that the password prompt will appear on the command line.
If you then view the SOCKS proxy settings via the GUI interface provided from the Network option under System Settings, you would then see the following:
Make sure you use -setsocksfirewallproxystate
not
-setsocksfirewallproxy
, i.e., include the "state" at the end
of the command. If you mistakenly use the latter, you will be setting
the value for the "SOCKS Proxy Server" field to "off", instead of
127.0.0.1
or some other IP adddress or
fully qualified domain name (FQDN). E.g., suppose I
mistakenly issued the command below:
$ sudo networksetup -setsocksfirewallproxy Wi-Fi off Password: $
When I issued the
networksetup -getsocksfirewallproxy
command, I would see
the following:
$ networksetup -getsocksfirewallproxy Wi-Fi Enabled: Yes Server: off Port: 0 Authenticated Proxy Enabled: 0$
If I then attempted to access a website in the browser, I would see a message like "Unable to connect to the proxy server", since the system is still configured to use a SOCKS proxy. If I then checked the SOCKS Proxy setting through System Preferences/Network, I would see the following:
The syntax for the setsocksfirewall proxy
and
setsocksfirewallproxystate
options are shown below:
[-setsocksfirewallproxy networkservice domain portnumber authenticated username password] [-setsocksfirewallproxystate networkservice on | off]
Note: tested on a MacBook Pro with OS X Yosemite (Version: 10.0.5)