How do I set the proxy for specific networks in order that it really works positive on each apps?
You might have configured a number of proxies in System Preferences, and that is the precise technique to do it (that is why the App Retailer app and Safari work positive). Sadly, Terminal is an exception and wishes its personal proxy settings.
Why is that? Terminal is merely a container that runs a shell. A shell a program that, merely put, shows a immediate and waits patiently so that you can execute instructions like ls
and rm
.
Shells predate macOS and have their very own guidelines for configuring proxies. Shells know nothing about proxy settings in System Preferences, and so they have to be configured individually.
macOS’s default shell is Bash (yow will discover out which shell you might be working by executing echo $0
on the immediate) so I will clarify how you can set the proxy in Bash.
The straightforward answer
-
Launch Terminal and kind this command to alter listing to our residence listing:
cd ~
-
Kind these instructions to open
.bash_profile
with TextEdit:contact .bash_profile open -a TextEdit .bash_profile
-
Set the proxy setting variables by typing the next textual content in TextEdit and exchange
<your http proxy>
,<your https proxy>
and<your ftp proxy>
together with your proxy server (if TextEdit already incorporates textual content, add the textual content under on the finish of the file):export HTTP_PROXY="<your http proxy>" export http_proxy=$HTTP_PROXY export HTTPS_PROXY="<your https proxy>" export http_proxy=$HTTP_PROXY export FTP_PROXY="<your ftp proxy>" export ftp_proxy=$FTP_PROXY
If in case you have configured in System Preferences a listing of hosts and domains that ought to be contacted straight bypassing the proxy, add them like this:
export NO_PROXY="<comma-separated checklist of hosts>" export no_proxy=$NO_PROXY
For instance:
export HTTP_PROXY="http://10.11.0.1:8080" export http_proxy=$HTTP_PROXY export HTTPS_PROXY="http://10.11.0.1:8080" export http_proxy=$HTTP_PROXY export FTP_PROXY="http://10.11.0.1:8080" export ftp_proxy=$FTP_PROXY export NO_PROXY="localhost,127.0.0.1" export no_proxy=$NO_PROXY
-
Save the file with ⌘S and shut TextEdit.
- Shut Terminal and reopen it. Now the proxy settings ought to work accurately.
A extra elaborate answer
The strategy above has a disadvantage: you must maintain two configurations, the one in System Preferences and the one in .bash_profile
.
Fortunately, as defined on Derek Morgan’s weblog, you’ll be able to have Bash import the System Preferences proxy settings utilizing the scutil
command. Merely observe the steps detailed within the earlier part, however in step 3 set the http/https/ftp proxy setting variables as follows:
export HTTP_PROXY=$(scutil --proxy | awk '
/HTTPEnable/ { enabled = $3; }
/HTTPProxy/ { server = $3; }
/HTTPPort/ { port = $3; }
END { if (enabled == "1") { print "http://" server ":" port; } }')
export http_proxy=$HTTP_PROXY
export HTTPS_PROXY=$(scutil --proxy | awk '
/HTTPSEnable/ { enabled = $3; }
/HTTPSProxy/ { server = $3; }
/HTTPPort/ { port = $3; }
END { if (enabled == "1") { print "http://" server ":" port; } }')
export https_proxy=$HTTP_PROXY
export FTP_PROXY=$(scutil --proxy | awk '
/FTPEnable/ { enabled = $3; }
/FTPProxy/ { server = $3; }
/FTPPort/ { port = $3; }
END { if (enabled == "1") { print "http://" server ":" port; } }')
export ftp_proxy=$FTP_PROXY
Within the definitions above, I set http://
because the scheme for all proxy servers, you may want to switch them to socks5://
for SOCKS or https://
for HTTPS as crucial.