How to set proxy in Bash and Zsh

To set proxy in bash and zsh, we need to code the bash script or zsh script.
We will edit the .bashrc or .zshrc dot file in your home path like:

1
2
3
/home/yourname/.bashrc
or
/home/yourname/.zshrc

Then, use neovim (maybe you can chose your favourite editor whatever :D ) to edit:
1
$ nvim ~/.bashrc

or
1
$ nvim ~/.zshrc


Add the proxy and noproxy function:
1
2
3
4
5
6
7
8
proxy(){
export all_proxy=socks5://localhost:7890
echo "All proxy On!"
}
noproxy(){
unset all_proxy
echo "All proxy Off!"
}

After the bash command source ~/.bashrc, you can use proxy command to set the proxy on. Also use noproxy command to set the proxy off.
image.png

You can echo "proxy" > ~/.zshrc if you like to set proxy when open the terminal (Just like python haha).

Author

InverseDa

Posted on

2023-02-01

Updated on

2023-03-30

Licensed under

Comments

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×