用socks 代理 wget

最近配置了tsocks,解決了我的代理設置問題,也遇到了些配置相關的問題,本文主要簡單介紹一下tsock的安裝、配置、使用的方法。

 

關於tsocks:

http://tsocks.sourceforge.net/

SOCKS servers are a form of proxy that are commonly used in firewalled LAN environments to allow access between networks, and often to the Internet. The problem is that most applications don't know how to gain access through SOCKS servers. This means that network based applications that don't understand SOCKS are very limited in networks they can reach. An example of this is simple 'telnet'. If you're on a network firewalled from the internet with a SOCKS server for outside access, telnet can't use this server and thus can't telnet out to the Internet. 
tsocks' role is to allow these non SOCKS aware applications (e.g telnet, ssh, ftp etc) to use SOCKS without any modification. It does this by intercepting the calls that applications make to establish network connections and negotating them through a SOCKS server as necessary.

toscks可以應用程序不經過任何修改就可以輕鬆地使用已有socks代理,本人主要遇到的問題是ssh, telnet, git使用代理不是那麼方便設置,用socks可以解決我的問題。

另外,tsocks是一個開源免費的項目,使用GPL License

 

下載和安裝tsocks:

1.       rpm包安裝:可以到http://pkgs.org/搜索tsocks,找到自己對應發行版的rpm

2.       Ubuntu等可以apt-get install tsocks來下載並安裝

3.       源碼安裝:可以到這裏下載http://tsocks.sourceforge.net/download.php 並自己編譯安裝

BTW,我用的RHEL6u1系統,採用的是RPM安裝方式)

 

配置tosck.conf

一般來說,tsocks的配置文件在/etc/tsocks.confrpm包安裝好之後一般都會有這個文件,如果沒有,也可以自己創建一個。可能Ubuntu等一些發行版,配置文件有所不同。

將我的配置文件/etc/tsocks.conf分享一下吧:

# This is the configuration for libtsocks (transparent socks)

# Lines beginning with # and blank lines are ignored

#

# This sample configuration shows the simplest (and most common) use of

# tsocks. This is a basic LAN, this machine can access anything on the

# local ethernet (192.168.0.*) but anything else has to use the SOCKS version

# 4 server on the firewall. Further details can be found in the man pages,

# tsocks(8) and tsocks.conf(5) and a more complex example is presented in

# tsocks.conf.complex.example

 

# We can access 10.*.*.* directly

local = 10.0.0.0/255.0.0.0

 

# Otherwise we use the server

server = proxy.xxx.com  #your proxy domain or IP address

server_type = 5    #to use socks V5

server_port = 1080  #the port of your porxy

 

使用tsocks:

tsocks [application [applications arguments]]

tsocks [on|off]

舉幾個實例吧:

tsocks firefox   #之後再firefox上瀏覽網頁就會默認使用tsocks配置的代理

tsocks git clone git://github.com/avikivity/kvm.git #使用proxygit,這就是我用的原因

 

source tsocks on  #設置當前shelltsocks,該命令可能遇到一個小bug在下面有講到

tsocks show     #查看當前Shelltsocks設置,tsocks: This shell is socksified.

do_something    #這裏就能默認使用tsocks的代理去do something了,前面已經設置了

source tsocks off  #關閉當前shelltsocks代理設置

tsocks show     #再次查看,tsocks: This shell is NOT socksified.

 

 

遇到的問題及解決方案:

13:01:17 libtsocks(2432): SOCKS server proxy-shz.intel.com (10.239.120.36) is not on a local subnet!
設置的代理沒有與/etc/tsocks.conf文件中的local設置的網絡在同一個子網中。

3:03:26 libtsocks(2451): The SOCKS server (proxy.ABCD.com) listed in the configuration file which needs to be used for this connection is invalid
配置文件的問題,我也忘了是啥時出現的錯誤了,但我碰到過的。
13:02:50 libtsocks(2441): Error 110 attempting to connect to SOCKS server (Connection timed out)
這個很明顯了,就是你設置的proxy連接不上(可能是本來就連不上,或者沒在同一個局域網內),請檢查和確認配置。

ERROR: ld.so: object '/lib64/libtsocks.so' from LD_PRELOAD cannot be preloaded: ignored.
鬱悶壞了,是因爲有一次我在rhel5u5上安裝了一個rhel6tsock rpm包,解決辦法是到http://pkgs.org/找到一個tsocks for rhel5rpm包,安裝即可。

 

[root@kvm-build ~]# source /usr/bin/tsocks on

basename: invalid option -- 'b'

Try `basename --help' for more information.

看到這樣的錯誤,有可能是你的tsocks有點小bug,不過不影響使用的,接着你用tsocks show來看,一樣可以看到提示說socks設置成功的,tsocks: This shell is socksified.

我的rhel5rhel6中的tsocks都遇到這樣的錯誤信息,你可以簡單地修改一下/usr/bin/tsocks文件,將其中的basename的一行修改一下即可:

修改前:PRG="$(basename $0)"

修改爲:PRG="$(basename -- $0)"

這是由於這個tsocks寫後,coreutils工具做了些改動,其中basename工具需要用”--“來表示options的結束(爲了保持新老版本的兼容)。這個問題在Bug-coreutils mailing list中討論過了的,見:http://www.mail-archive.com/[email protected]/msg09912.html


替代工具機參考文檔:

一個與tsocks有類似功能的工具: socat   (我暫時沒怎麼用)

見:http://freshmeat.net/projects/socat/

tsocks.conf配置文件:http://linux.die.net/man/5/tsocks.conf

tsocks的使用:http://www.21andy.com/blog/20100212/1678.html 
另外的人遇到的tsocks問題:http://notes.benv.junerules.com/socks-opera-and-brute-force/



安裝tsocks見 http://pkgs.org/centos-6/epel-x86_64/tsocks-1.8-0.5.beta5.el6.x86_64.rpm.html
原文地址:http://renyongjie668.blog.163.com/blog/static/16005312011824112410588/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章