为命令行程序设置代理
http_proxy 环境变量用于为 curl 和 wget 等客户端程序指定代理设置。
以下是为命令行程序使用代理的各种示例:
1. 无需用户名和密码的代理:
要配置没有用户名和密码的代理:
# export http_proxy=http://SERVER:PORT/
2. 使用用户名密码认证的代理:
要使用用户名和密码身份验证配置代理服务器:
# export http_proxy=http://USERNAME:PASSWORD@SERVER:PORT/
3. 需要域、用户名和密码:
要使用用户名/密码身份验证以及域名配置代理:
# export http_proxy=http://DOMAIN\USERNAME:PASSWORD@SERVER:PORT/
为其他程序设置 proxu
要在代理后面配置 yum,请使用以下内容修改 /etc/yum.conf:
# vi /etc/yum.conf proxy=http://proxy.example.com:3128 proxy_username=yum-user proxy_password=qwerty
注意:其他程序(例如 Firefox)将有自己的内部代理使用设置。
什么是代理服务器(Proxy Server)
代理服务器是一种服务器,它充当客户端请求在 Internet 或者外部网络上寻求资源的中介。
将其视为代表客户端发出请求的中间人,确保我们网络之外的任何人都不知道请求主机的详细信息。
验证服务器上是否设置了代理
此命令将显示系统上是否配置了代理服务器:
# echo $http_proxy
更多: zhilu jiaocheng
特殊字符处理
反斜杠字符 (\) 需要转义,如下所示。
# export http_proxy=http://DOMAIN\USERNAME:PASSWORD@SERVER:PORT/
当用户名或者密码使用 @ 符号时,在 @ 前添加反斜杠 (\),例如:
# export http_proxy=http://DOMAIN\USERN\@ME:PASSWORD@SERVER:PORT
或者
# export http_proxy=http://DOMAIN\USERNAME:P\@SSWORD@SERVER:PORT
在 CentOS/RHEL 7 中永久配置代理(对于没有 shell 的进程)
如果要在 CentOS/RHEL 7 中添加永久代理,请在 /etc/environment 文件中定义环境变量。
# echo "http_proxy=http://proxy.example.com:3128/" > /etc/environment
请注意,与下一节中描述的 /etc/profile.d 中的 shell 脚本不同,/etc/environment 文件不是 shell 脚本,它适用于所有没有 shell 的进程。
使用 SHELL 为进程配置代理
对于 bash 和 sh 用户,将上面给出的导出行添加到名为 /etc/profile.d/http_proxy.sh 文件的新文件中:
# echo "export http_proxy=http://proxy.example.com:3128/" > /etc/profile.d/http_proxy.sh
对于 csh 和 tcsh 用户,使用以下命令在名为 /etc/profile.d/http_proxy.csh 文件的新文件中设置 http_proxy 变量:
# echo "setenv http_proxy http://proxy.example.com:3128/" > /etc/profile.d/http_proxy.csh
这些文件的扩展名决定了哪个 shell 会读取它们。
这些命令不可互换。
日期:2020-09-17 00:13:22 来源:oir作者:oir