Linux命令行模式如何设置代理

一、四种代理方式

http_proxy:http代理
https_proxy:https安全代理
ftp_proxy:ftp代理
no_proxy:不使用代理的IP

二、代理语法

http_proxy=http://username:password@proxyserver:port/
  • http_proxy:表示使用http的代理方式,也可以使用https_proxy、ftp_proxy
  • username:使用代理的用户名,有特殊字符的,用\转换.
  • password:使用代理的密码,有特殊字符的,用\转换.
  • proxyserver:代理地址,可以是IP,域名
  • port:使用代理的端口
例如:
http_proxy=http://10.199.75.12:8080
ftp_proxy=http://10.199.75.12:8080
no_proxy
no_proxy是一系列IP的集合,中间用','隔开,网络上有说可以设置网域,我没有测试成功....以后再补充.
export

三、设置方法详解

  • 方法一、命令
# export http_proxy=http://10.199.75.12:8080
# export https_proxy=http://10.199.75.12:8080
# export ftp_proxy=http://10.199.75.12:8080

特点:即时生效,重启后失效

  • 方法二、当前用户下有效
# vi ~/.bashrc

添加如下代码:
http_proxy=http://10.199.75.12:8080
https_proxy=http://10.199.75.12:8080
ftp_proxy=http://10.199.75.12:8080
no_proxy=192.168.80.1,localhost,127.0.0.1
export http_proxy https_proxy ftp_proxy no_proxy

保存退出vi后,可以执行

# source ~/.bashrc,即时生效。

特点:针对当前用户有效,使用source可及时生效,或重启生效

  • 方法三、所有用户有效
# vi /etc/profile

添加如下代码:
http_proxy=http://10.199.75.12:8080
https_proxy=http://10.199.75.12:8080
ftp_proxy=http://10.199.75.12:8080
no_proxy=192.168.80.1,localhost,127.0.0.1
export http_proxy https_proxy ftp_proxy no_proxy

特点:对所有用户有效,需重启生效。

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>