Linux 中快速开启/关闭代理
在 ~/.bashrc 中添加以下函数,用于快速开启、关闭、测试代理。
function echo_error() {
echo -e "\033[41;37m $* \033[0m"
}
function enableproxy() {
export http_proxy="http://192.168.110.200:7897"
export https_proxy="http://192.168.110.200:7897"
export HTTP_PROXY="$http_proxy"
export HTTPS_PROXY="$https_proxy"
echo "proxy enabled: $http_proxy"
}
function disableproxy() {
unset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
echo 'proxy disabled.'
}
function testproxy() {
if [ -z "$http_proxy" ] || [ -z "$https_proxy" ]; then
echo_error "proxy is incomplete."
echo_error "please run: ep or enableproxy"
return 1
fi
echo "testing proxy: $http_proxy"
if curl -s -I -x "$http_proxy" --connect-timeout 5 --max-time 10 https://www.google.com >/dev/null; then
echo -e "\033[42;37m proxy ok. \033[0m"
else
echo -e "\033[41;37m proxy failed. \033[0m"
return 1
fi
}
alias ep='enableproxy'
alias dp='disableproxy'
alias tp='testproxy'作者:张三 创建时间:2026-06-10 15:59
最后编辑:张三 更新时间:2026-06-10 16:14
最后编辑:张三 更新时间:2026-06-10 16:14