Text Mode Use Http Proxy On Linux

Text Mode Use Http Proxy On Linux

Linux 上沒有用過的東西實在太多太多,過年期間裝了 Ubuntu 後要開始慢慢玩了,因為我選擇先安裝在我的 x60 上面,而 x60 又有需求上班時使用,所以對於連線方式要開始一些設定,當然這裡只是說一些基本的設定,太高深的技巧我也不會啦!

若只是透過瀏覽器上網,那麼瀏覽器上的設定填一填就好,這個設定我想大家應該都會吧!要介紹給大家怎樣設定嗎?應該是不用吧!對我來說第一次研究的是該如何在 text mode 上透過 http proxy 連上線。

先示範一般狀況下載一張圖片
$ wget https://host.easylife.tw/pics/200802/0212/DSC02029.jpg
--19:33:52--  https://host.easylife.tw/pics/200802/0212/DSC02029.jpg
           => `DSC02029.jpg'
正在查找主機 pic.easylife.idv.tw... 211.76.137.37
正在連接 pic.easylife.idv.tw

211.76.137.37

:80... 連上了。
已送出 HTTP 要求,正在等候回應... 200 OK
長度: 81,898 (80K) [image/jpeg]

100%[====================================>] 81,898        56.93K/s            

19:33:55 (56.82 KB/s) -- 已儲存 ‘DSC02029.jpg’ [81898/81898])
這不用解釋太多,基本的 wget 指令下載一張圖片。

透過 http proxy 下載一張圖片
$ export http_proxy=http://proxy.hinet.net:80
這部份是設定 http_proxy,如同我們想要做的一樣,指令很直接,只是沒用過怎會知道呢?
$ wget https://host.easylife.tw/pics/200802/0212/DSC02029.jpg
--19:39:11--  https://host.easylife.tw/pics/200802/0212/DSC02029.jpg
           => `DSC02029.jpg.1'
正在查找主機 proxy.hinet.net... 61.219.36.250, 61.219.36.120
正在連接 proxy.hinet.net

61.219.36.250

:80... 連上了。

已送出 Proxy 要求,正在等候回應... 200 OK
長度: 81,898 (80K) [image/jpeg]

100%[====================================>] 81,898       450.47K/s            

19:39:11 (449.55 KB/s) -- 已儲存 ‘DSC02029.jpg.1’ [81898/81898])
在下載一次圖片,如同所設定的透過了 http_proxy。

其實簡易的設定就是如此
export http_proxy=http://代理伺服器:port
這樣方式的設定其實也是可以利用在 ftp 上面
export ftp_proxy=http://代理伺服器:port
若經過的代理伺服器是需要帳號密碼的,那麼也是最一般的方式就可以解決
export http_proxy=http://帳號:密碼@代理伺服器:port

只是透過指令殘留下帳號密碼的資訊其實不是一個好作法,若有人查詢你的歷史紀錄密碼就曝光了,於是我們可以簡單的利用環境變數來建立一個 fuction
增加下列的內容到個人家目錄裡的 .bashrc
function useproxy(){
        echo -n "username:"
        read -e username
        echo -n "password:"
        read -es password
        if [ $username ] && [ $password ]; then
                export http_proxy="http://$username:[email protected]:80"
                export ftp_proxy="http://$username:[email protected]:80"
        else
                export http_proxy="proxy.hinet.net:80"
                export ftp_proxy="proxy.hinet.net:80"
        fi
}
之後來測試一下囉,重新開一個視窗來讓 .bashrc 生效比較快
$ useproxy
username:
password:
$ set

grep proxy

ftp_proxy=proxy.hinet.net:80
http_proxy=proxy.hinet.net:80
若沒有密碼狀況如上,若加上帳號密碼狀況如下
$ useproxy
username:wawa
password:
$ set

grep proxy

ftp_proxy=http://wawa:[email protected]:80
http_proxy=http://wawa:[email protected]:80
當然看環境變數還是可以看到帳號密碼的,只是不會留在歷史紀錄裡。

一切就是這麼簡單而已,但是哪有多少然和我一樣習慣用 command 啊~既然都使用視窗介面當然也會有視窗的設定,但是我還是只告訴你 Ubuntu 裡的 command
$ kcmshell proxy
因為怎麼設定我也懶得去研究,若所有連線都得透過 proxy 那麼這環境還真是令人錯愕。

Text Mode Use Http Proxy On Linux

Text Mode Use Http Proxy On Linux 相關文章


參考內容推薦

How to Protect your Internet Anonymity and Privacy/Your own proxy and VPN on Amazon EC2

It is trivial to setup your own private proxy server on Amazon EC2, and with a little extra work, a VPN server. ... //en.wikibooks.org/w/index.php?title=How_to_Protect_your_Internet_Anonymity_and_Privacy/Your_own_proxy_and_VPN_on_Amazon_EC2&oldid&quot

How To Set A Proxy For The Terminal [Quick Linux Tip] ~ Web Upd8 ...

2010年10月11日 - Here is an example. If you've set up TOR and you want to use it for the terminal, to set a HTTP and HTTPS proxy for the current terminal session ...

apt - Setting proxy from terminal

2012年7月2日 - I have tried setting the proxy via bashrc file but that din work either. ... See https://help.ubuntu.com/community/EnvironmentVariables for details.

10. Using yum with a Proxy Server

Using yum with a Proxy Server By default, yum accesses network repositories with HTTP. All yum HTTP operations use HTTP/1.1, and are compatible with web proxy servers that support this standard. You may also access FTP repositories, and configure ...

HowTo : Use a Proxy on the Linux Command Line

Use the following syntax to configure the proxy for http , https and ftp traffic on the Linux command line : $ export http_proxy="http://proxy-server:port"

How to set proxy environment variable in Unix/Linux

2014年6月3日 - How To Use Proxy Server To Access Internet at Shell Prompt With http_proxy ... export http_proxy=http://proxy-server.mycorp.com:3128/ ... How do I use password protected proxy server using various command line options?

Proxy settings - ArchWiki

... { PROXY_ENV="http_proxy ftp_proxy https_proxy all_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY" for envar in $PROXY_ENV do export $envar=$1 done for envar in "no_proxy NO_PROXY " do export $envar=$2 done } clrProxy ...

Use PuTTY as a secure proxy on Windows

Last month, I wrote about using OpenSSH as a secure Web proxy on UNIX and Linux systems. This time, I'll show you how to do the same thing on Microsoft Windows using PuTTY ...

linux - setting proxy in wget

2012年6月26日 - You can set the default proxies for Wget to use for http, https, and ftp. ... wget uses environment variables somthing like this at command line ...

Linux

... Squid Proxy authentication in a transparent mode You cannot use Squid authentication with a transparently intercepting proxy. Further reading: How do I use Iptables connection tracking feature? ...