侧边栏壁纸
博主头像
运维匠-运维工程师知识分享经验和最佳实践博主等级

生活百般滋味,人生需要笑对

  • 累计撰写 58 篇文章
  • 累计创建 3 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Linux 使用代理上网

运维匠
2024-06-16 / 0 评论 / 0 点赞 / 38 阅读 / 2140 字
温馨提示:
本文最后更新于 2024-06-17,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

Linux使用代理上网

原理

linux 的代理配置是对系统环境变量进行设置

  • HTTP_PROXY http代理
  • HTTPS_PROXY https 代理
  • NO_PROXY # 禁止使用代理的地址
    配置代理的脚本,并将脚本写入~/.bashrc 中
cat >> ~/.bashrc << EOF

# where need proxy
proxy() {
    export PROXY_IP=10.0.0.1
    export PROXY_PORT=8000
    export NO_PROXY=127.0.0.1,localhost,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,apiserver.cluster.local
    export https_proxy=http://${PROXY_IP}:${PROXY_PORT} http_proxy=http://${PROXY_IP}:${PROXY_PORT} all_proxy=socks5://${PROXY_IP}:${PROXY_PORT}
    export HTTPS_PROXY="${https_proxy}" HTTP_PROXY="${http_proxy}" ALL_PROXY="${all_proxy}"
    echo "System http, https, socks5 Proxy on, proxy ip: ${PROXY_IP}, proxy port: ${PROXY_PORT}"
}

# where need noproxy
noproxy() {
    echo "System http, https, socks5 Proxy off, proxy ip: ${PROXY_IP}, proxy port: ${PROXY_PORT}"
    unset https_proxy http_proxy all_proxy HTTPS_PROXY HTTP_PROXY ALL_PROXY
}
EOF

source ~/.bashrc

使用方式

# 开启代理
proxy

#关闭代理
noproxy
0

评论区