ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

ubuntu proxy变量设置

2022-06-01 10:04:03  阅读:161  来源: 互联网

标签:http 变量 environment export proxy ubuntu my your


 

原文:https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-configure-proxy-on-ubuntu-18-04/

----------------------

Single User Temporary Proxy Settings

You may not always want to force Internet traffic through a proxy.  Sometimes you need to override existing settings, and you can do this safely by setting the proxy environment variables from the command line.

The following will set a proxy for HTTP and HTTPS, while preventing local traffic from going through the proxy. Our example proxy server endpoint is my.proxy.server:8080 for HTTP traffic and my.proxy.server:8081 for HTTPS.

  1. Open a Terminal window where you need proxy access.
  2. Set and export the HTTP_PROXY variable.
    export HTTP_PROXY=user:pass@my.proxy.server:8080
  3. Set and export the HTTPS_PROXY variable.
    export HTTPS_PROXY=user:pass@my.proxy.server:8081
  4. Set and export the NO_PROXY variable to prevent local traffic from being sent to the proxy.
    export NO_PROXY=localhost,127.0.0.1,*.my.lan.domain

 

Single User Persistent Proxy Settings

  1. Open your bash profile file into a text editor.
    vi ~/.bash_profile
  2. Add the following lines, modifying them to match your environment.
    export http_proxy=username:password@proxyhost.com:8080
    export https_proxy=username:password@proxyhost.com:8081
    exprot no_proxy=localhost, 127.0.0.1, *.my.lan
  3. Save your settings.
  4. The proxy settings will be applied the next time you start a session, by logging into the server or opening a new Terminal window from a Desktop.
  5. To force apply your new proxy settings in the current Terminal session, execute the source command against your bash profile.
    source ~/.bash_profile

 

All Users

You will need administrative rights to perform this task. All versions of Ubuntu and Debian have a file called /etc/environment. Within this file, we can set global variables and other such things.

Similar to how you set proxy settings for your own local proxy, we’ll be adding the environment variables to this file. The variables will be set when a new user session is created, which is to say when you log in next.

  1. Using an administrator account, open /etc/environment into a text editor.
    sudo vi /etc/environment
  2. Add the following lines, modifying them to fit your environment. Username and password may be omitted, if not required.
    http_proxy="http://<username>:<password>@<hostname>:<port>/"
    https_proxy="http://<username>:<password>@<hostname>:<port>/"
    ftp_proxy="http://<username>:<password>@<hostname>:<port>/"
    no_proxy="<pattern>,<pattern>,...

    For example, if you do not need to enter a username or password, and your proxy server is my.proxyserver.net at port 8080, and you do not want local traffic going through the proxy, you would enter the following:

    http_proxy="http://my.proxyserver.net:8080/"
    https_proxy="http://my.proxyserver.net:8080/"
    ftp_proxy="http://my.proxyserver.net:8080/"
    no_proxy="localhost,127.0.0.1,::1
  3. Save your changes and exit the text editor.

标签:http,变量,environment,export,proxy,ubuntu,my,your
来源: https://www.cnblogs.com/oxspirt/p/16333254.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有