假设代理服务器为:10.124.160.10:9254
全局上网
no_proxy 参数可以设置不使用代理的 ip,解决一些内网访问的问题
# 新增代理配置
echo 'export http_proxy=http://10.124.160.10:9254' >> /etc/profile
echo 'export https_proxy=http://10.124.160.10:9254' >> /etc/profile
echo 'no_proxy_ip=$(echo 10.124.160.{1..255})' >> /etc/profile
echo 'export no_proxy="127.0.0.1,localhost,.devops.com,${no_proxy_ip// /,}"' >> /etc/profile
# 使生效
source /etc/profile
取消代理
unset http_proxy
unset https_proxy
工具上网
FTP
echo 'export ftp_proxy=http://10.124.160.10:9254' >> /etc/profile
source /etc/profile
npm
npm install elasticdump -g --proxy http://10.124.160.10:9254 --registry=https://registry.npmmirror.com
yum
echo 'proxy=http://10.124.160.10:9254' >> /etc/yum.conf
wget
echo 'http_proxy=http://10.124.160.10:9254' >> /etc/wgetrc
echo 'https_proxy=http://10.124.160.10:9254' >> /etc/wgetrc
git
# 全局代理
git config --global https.proxy http://10.124.160.10:9254
git config --global https.proxy https://10.124.160.10:9254
# 指定代理 oa.com
git config --global http.http://oa.com.proxy http://10.124.160.10:9254
git config --global http.https://oa.com.proxy https://10.124.160.10:9254
yarn
yarn config set proxy http://10.124.160.10:9254
yarn config set https-proxy http://10.124.160.10:9254
docker
Docker Container代理
https://docs.docker.com/network/proxy/
注意:添加代理配置后,新创建的容器才生效。
# ~/.docker/config.json
"proxies":
{
"default":
{
"httpProxy": "http://43.138.216.160:9253",
"httpsProxy": "http://43.138.216.160:9253",
"noProxy": "localhost,127.0.0.1,172.18.1.0/24"
}
}
# 重启docker
systemctl restart docker
Docker Daemon代理
mkdir -p /etc/systemd/system/docker.service.d
cat > /etc/systemd/system/docker.service.d/http-proxy.conf <<EOF
[Service]
Environment="HTTP_PROXY=http://10.124.160.10:9254" "HTTPS_PROXY=http://10.124.160.10:9254"
EOF
systemctl daemon-reload
systemctl restart docker
pip 上网
pip3 install -r requirements.txt --proxy=http://10.124.160.10:9254
ansible
配置到 playbook 的环境变量中
environment:
http_proxy: http://10.124.160.10:9254
https_proxy: http://10.124.160.10:9254
ssh
# 系统默认 nc已升级为 Ncat,注意配置参数
ssh -o ProxyCommand='/usr/bin/nc --proxy-type socks5 --proxy 10.124.160.10:9254 %h %p' root@10.124.160.13
# 如果还是 nc,参数如下
ssh -o ProxyCommand='/usr/bin/nc -X 5 -x 10.124.160.10:9254 %h %p' root@10.124.160.13
scp
scp -o ProxyCommand='/usr/bin/nc --proxy-type socks5 --proxy 10.124.160.10:9254 %h %p' cm-7.1.4.tar root@10.124.160.13:/data/
网友评论