Set Proxy For Mac
Mac OS X does a good job of juggling proxy configurations for graphical applications while moving between wired and wireless network connections. However, this functionality doesn’t extend to command-line work in Terminal or iTerm and can be a pain when using git or package managers like npm, apm, pip, or homebrew while switching between environments. This post describes a method for programmatically setting the command-line network proxy environment variables based on the configured proxy in the Network System Preferences pane.
Mac OS X Proxy Behavior
Mac OS X maintains individual network proxy settings for each network adapter. For example, a Thunderbolt ethernet adapter has its own proxy configuration associated with it that is separate from a wireless adapter. The operating system uses the proxy configuration for the currently-connected adapter, updating the system proxy as adapter connection states change. If more than one adapter is connected, the operating system uses the proxy configuration for the connected adapter highest on the adapter list in the Network System Preferences pane. The adapter order can be changed by clicking on the gear icon at the bottom of the list and clicking the “Set Service Order…” menu item.
Access System Proxy settings in Terminal
How to set up a proxy server on a Mac running macOS. Here's how to set up a proxy server on a Mac running macOS 10.15 Catalina. Other macOS versions use essentially the same commands. Open System Preferences. One way to get there is to click on the Apple menu System Preferences. Choose the Network icon to adjust connectivity settings.
The scutil
command-line utility allows for management for a variety of system configuration parameters and can be used to access system proxy configuration with the --proxy
flag.
Mac System Proxy
Here is the output of scutil --proxy
without a configured proxy:
Once you've selected a network card, click on 'Advanced.' , then click the 'Proxies' header. Check the box for 'Web Proxy(HTTP)' and enter the IP address for your SecureSchool appliance, and the correct proxyport. Do the same for 'Secure Web Proxy(HTTPS)'. Go step-by-step through following instructions in order to setup a proxy in Google Chrome on Mac. In the Chrome browser, press the “Customize and control Google Chrome” button and choose “Settings”. Scroll down to “Advanced” and click on it. Scroll down to the “System” title and click on “Open proxy settings”. To set up a proxy using Mac Leopard, open your system preferences and select 'Network.' Select 'Internet Connection.' Click on the network that you are using; it usually has a green circle next to it. Then, click on 'Advanced.' Click on the 'Proxies' tab. In Windows Command Line environment (NOT powershell), you can use below commands to set http and https proxy. Set httpproxy=protocol://ip:port set httpsproxy=protocol://ip:port For example, if you have a local socks 5 proxy (such as ShadowSocks), commands will be as below.
and here is the output of scutil --proxy
with example.proxy
set as the system proxy for the HTTP and HTTPS protocols:
Mac Socks Proxy
Parse scutil
output
We can use awk
to parse the output of scutil
and extract the proxy configuration. The following snippet does the trick:
This script looks for HTTPEnable
, HTTPProxy
, and HTTPPort
in the output of scutil
. If the proxy is enabled, the script prints out the proxy URL and sets it as the http_proxy
environment variable. If the proxy is not enabled, the script sets http_proxy
to an empty string. The final line sets the HTTP_PROXY
environment variable as well since some command-line applications use that instead.
Placing this snippet in your .bash_profile
ensures that your proxy will stay configured automatically while switching between wired and wireless networks.
After updating to Mojave, I started having connection issues (email mostly but also internet at times). It turns out, I had SOCKS Proxy selected in my Network Preferences. I deselected and applied my changes. But whenever I restart my computer, SOCKS Proxy autoselects. Is this Malware or a Virus? It's annoying but if benign, I can continue to deselect it. However, I know that botnets use SOCKS Proxy to control computers so I would prefer to disable it permanently. Any suggestions?
MacBook Pro (Retina, 13-inch, Mid 2014)
Mac Global Proxy
Posted on