centos7 设置代理
实验环境:centos7.6 ,代理服务器 IP,192.168.1.199,端口 3200
需要设置 192.168.1.0/24 ,10.2.7.0/24 网段,*.domain.com 不通过代理。
centos7 通过设置 https_proxy 和 https_proxy 设置代理,通过 no_proxy 跳过不需要代理的网址。
操作步骤:
1、此处设置全局代理,直接在 /etc/profile 中添加 no_proxy,https_proxy,http_proxy 环境变量
[root@docker01 ~]# cat /etc/profile
...
no_proxy_192=$(echo 192.168.1.{1..255}|sed 's/ /,/g')
no_proxy_10=$(echo 10.2.7.{1..255}|sed 's/ /,/g')
export no_proxy="127.0.0.1,localhost,.domain.com,${no_proxy_192},${no_proxy_10}"
export https_proxy=https://192.168.1.199:3200
export http_proxy=http://192.168.1.199:3200
no_proxy,即跳过代理的地址,若本系统(服务器)需要与其他同局域网服务器进行通信,需要在这里配置跳过代理。这里不支持通配符(.xx.com 或 192.168.)、不支持网段(192.168.0.0/16),只能一个一个 IP 或域名的配置,如果 IP 是连续的,可以使用 “穷举法”:
2、立即生效
[root@docker01 ~]# source /etc/profile
3、测试:
走代理
[root@docker01 ~]# curl baidu.com
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>
不走代理
[root@docker01 ~]# curl 10.2.7.200:32023
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Harbor</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico?v=2">
<link rel="preload" as="style" href="./light-theme.css">
<link rel="preload" as="style" href="./dark-theme.css">
<link rel="stylesheet" href="styles.db9e76a7be3134550b52.css"></head>
<body>
<harbor-app>
<div class="spinner spinner-lg app-loading app-loading-fixed">
Loading...
</div>
</harbor-app>
<script src="runtime.9ad22a88fcc70a015907.js" defer></script><script src="polyfills-es5.c04cfdffe6ecc730c69c.js" nomodule defer></script><script src="scripts.7fa3fa51e1a86dfba2c8.js" defer></script><script src="main.a80322eb60fcaa1287e9.js" defer></script></body>
</html>
注意:
no_proxy 穷举的 ip 不能太多,不然执行 ls,vi 等命令会出现错误 Argument list too long
[root@docker01 ~]# ls
-bash: /usr/bin/ls: Argument list too long
解决方法
[root@docker01 ~]# unset no_proxy
然后,修改 /etc/profile 中 no_proxy 参数
参考文章:
https://serverfault.com/questions/623543/centos-6-5-proxy-bypass-no-proxy-not-working