Set proxy for CMD/Powershell/Terminal/Git
Set proxy for CMD/Powershell/Terminal/Git
CMD
1
proxy_type=<protcol>://<username>:<password>@<server>:<port>
For examples:
1
2
3
4
5
6
7
8
9
10
set http_proxy=http://127.0.0.1:PORT
set https_proxy=http://127.0.0.1:PORT
set http_proxy=socks5://127.0.0.1:PORT
set https_proxy=socks5://127.0.0.1:PORT
# -v verbose (print errors/warnings while in event loop)
# -vv very verbose (also print client commands/reponses)
# -vvv extremely verbose (also print internal state transitions)
# -k ignore the certificate check
To clear the proxy:
1
2
set http_proxy=
set https_proxy=
Powershell
Very similar to cmd, here’s the examples:
1
2
$Env:http_proxy="http://127.0.0.1:PORT";
$Env:https_proxy="http://127.0.0.1:PORT";
Additionally, you can add these lines of command to the Powershell’s profile, the follow command will create and open a new profile. The commands in the profile file will run automatically when Powershell starts.
1
2
if (!(Test-Path -Path $PROFILE )) { New-Item -Type File -Path $PROFILE -Force }
notepad $PROFILE
Terminal
Examples:
1
2
3
4
5
6
7
export http_proxy="http://127.0.0.1:PORT/"
export https_proxy="https://127.0.0.1:PORT/"
export http_proxy="socks5://127.0.0.1:PORT/"
export https_proxy="socks5://127.0.0.1:PORT/"
export all_proxy="socks5://127.0.0.1:PORT/"
You can edit your
~./bashrc
or~/.zshrc
to easily set proxy in terminals, as an example below:
1
2
alias setproxy="export http_proxy=http://127.0.0.1:PORT/; export https_proxy=http://127.0.0.1:PORT/; echo 'Set proxy successfully'"
alias unsetproxy="unset http_proxy; unset https_proxy; echo 'Unset proxy successfully'"
source ~/.bashrc
to take effect.
Proxychains
Proxychains is a tool that forces any TCP connection made by any given application to follow through proxy like TOR or any other SOCKS4, SOCKS5 or HTTP(S) proxy.
Proxychains-ng, the ng standing for next generation, is an enhanced iteration of the defunct proxychains project. It offers improved functionality and enhanced compatibility. Except in cases where proxychains is more suitable due to limitations, proxychains-ng is generally advised.
Installation
Proxychains-ng already comes pre-installed in most distributions. You can check by entering the command:
1
proxychains4
However Proxychains-ng isn’t installed on distributions like Ubuntu. You can install it with apt
.
1
2
sudo apt update
sudo apt install proxychains4
You can install proxychains on Mac OS X with an homebrew. You have to download unofficial brew formula for proxychains4: https://gist.github.com/allenhuang/3792521.
1
2
3
git clone git://gist.github.com/3792521.git gist-3792521
brew install --HEAD gist-3792521/proxychains4_formula.rb
# The default config file will be located in /usr/local/etc/proxychains.conf
1
brew install proxychains
To run current source code version:
1
2
3
4
5
6
7
git clone https://github.com/haad/proxychains.git
cd proxychains
# needs a working C compiler, preferably gcc
./configure
make
sudo make install
Configure Proxychains
Open the proxychains configuration file using a text editor.
1
sudo vi /etc/proxychains4.conf
Add proxies to the bottom of the file (under [ProxyList]). Ensuring they are in the format of
You can also configure how proxychains uses the list of proxies you’ve provided. These can be dynamic, strict, round-robin, or random chains.
-
Dynamic Chain: Attempt to use the proxies in the listed order. However, if one fails, it’ll skip it and move on to the next one.
-
Strict Chain: Every proxy is used in the listed order, from the first to the second, third, and so on. If one proxy fails, the entire connection fails.
-
Round-Robin Chain: The chained proxies are used circularly to distribute the connection amongst the provided proxies. Each connection request goes to the next one in the list, and once it reaches the end, it starts over again at the beginning.
-
Random Chain: Selects proxies for each connection in a random order. It does not use the proxies in order and provides a unique path through each listed proxy.
Use Proxychains
For example, to use proxy with curl
, you just need to enter the following command:
1
proxychains4 curl
Git
Set globally:
1
2
3
4
5
git config --global http.proxy http://127.0.0.1:PORT
git config --global https.proxy https://127.0.0.1:PORT
git config --global http.https://github.com.proxy socks5://127.0.0.1:PORT
git config --global https.https://github.com.proxy socks5://127.0.0.1:PORT
Only set for Github:
1
2
git config --global http.https://github.com.proxy https://127.0.0.1:PORT
git config --global https.https://github.com.proxy https://127.0.0.1:PORT
Unset proxy:
1
2
git config --global --unset http.proxy
git config --global --unset https.proxy
Check current proxy:
1
git config --global -l
You can write your configurations into .gitconfig
:
1
vi ~/.gitconfig
1
2
3
4
5
6
7
[http]
proxy = socks5://127.0.0.1:PORT
proxy = http://127.0.0.1:PORT
[https]
proxy = socks5://127.0.0.1:PORT
proxy = https://127.0.0.1:PORT
To take effect:
1
git config -l --global