在Linux終端下使用代理訪問網路__Linux

來源:互聯網
上載者:User

有些區域網路環境上網需要使用代理上網,圖形介面的很好解決就設定一下瀏覽器的代理就好了,但是linux純命令列的介面就需要手動設定了。

一、使用wget命令進行代理訪問

wget非常強大,支援代理設定,代理可以在環境變數或wgetrc檔案中設定

方法1:當前環境變數設定

#export PROXY=http://219.239.66.253:80/
這樣,就可以使用wget進行代理下載境外網路了。
不過,這種環境變數設定只對當前環境有效,重啟後設定將消失。

方法2:wget設定檔設定

#vi /etc/wgetrc
ftp_proxy = http://219.239.66.253:80/
http_proxy = http://219.239.66.253:80/
https_proxy = http://219.239.66.253:80/ (注意:無引號”")

方法3:wget命令列參數中設定

wget支援-e參數來進行代理設定
#wget -e “http_proxy=http://[username]:[password]@proxyip:port/” “http://www.baidu.com”
其中,-e, –execute=COMMAND   執行`.wgetrc’格式的命令,wgetrc格式參見/etc/wgetrc或~/.wgetrc記錄和輸入檔案

二、在環境變數中進行代理設定

主要是在/etc/profile檔案中環境變數設定代理(機器重啟後代理設定效果不在消失)。

# /etc/profile

# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc

ftp_proxy=222.47.26.12:8888
http_proxy=222.47.26.12:8888
https_proxy=222.47.26.12:8888
no_proxy=192.168.95.20
export ftp_proxy
export http_proxy
export https_proxy
export no_proxy

添加完後重啟系統即可。這時所有的網路連接均通過代理來連網。

執行個體:[root@localhost ~]# wget “www.blogger.com”
–2011-09-06 07:29:17–  http://www.blogger.com/
Connecting to 222.47.26.12:8888… connected.
Proxy request sent, awaiting response… 200 OK
Length: 81 [text/html]
Saving to: `index.html’

100%[====================================>] 81          –.-K/s   in 0s

2011-09-06 07:29:17 (7.72 MB/s) – `index.html’ saved [81/81]

三、部分網站不走代理

如果要全域使用者使用應用於所有的Shell,就需要修改 /etc/profile 檔案

# vi /etc/profile  
在檔案中添加以下配置

http_proxy=proxy.abc.com:8080  https_proxy=$http_proxy  ftp_proxy=user:password@proxy.abc.com:8080  no_proxy=*.abc.com,10.*.*.*,192.168.*.*,*.local,localhost,127.0.0.1  export http_proxy https_proxy ftp_proxy no_proxy  

其中
http_proxy:http協議使用Proxy 伺服器地址;
https_proxy:https協議使用安全Proxy 位址;
ftp_proxy:ftp協議使用Proxy 伺服器地址;
user:代理使用的使用者名稱;
password:代理使用使用者名稱的密碼;
proxy.abc.com:Proxy 位址,可以是IP,也可以是網域名稱;
8080:使用的連接埠;
no_proxy:不使用代理的主機或IP。

        儲存退出,登出重新登陸系統即可生效。

        此方法只適合配置http代理,使用socket代理上網的另有其他配置方法。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.