SOCKSサーバ Dante インストール

会社で必要になったのでSOCKSサーバについて調べてみました。
情報量的に一番多そうだった Dante をセットアップしてみました。
https://www.inet.no/dante/

インストール先のOSはこんな感じ。

[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-504.8.1.el6.x86_64 #1 SMP Wed Jan 28 21:11:36 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)

[root@localhost ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:02:e0:9e brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.5/24 brd 192.168.1.255 scope global eth0
    inet6 2408:211:a84:2b00:a00:27ff:fe02:e09e/64 scope global dynamic
       valid_lft 13810sec preferred_lft 12010sec
    inet6 fe80::a00:27ff:fe02:e09e/64 scope link
       valid_lft forever preferred_lft forever


インストール。

# wget インストール
[root@localhost ~]# yum -y install wget

# wget インストール、リポジトリ最新化
[root@localhost ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
[root@localhost ~]# rpm -ivh rpmforge-release-*.rpm
[root@localhost ~]# yum -y update

# dante install
[root@localhost ~]# yum info dante*
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * extras: ftp.iij.ad.jp
 * rpmforge: ftp.riken.jp
 * updates: ftp.iij.ad.jp
利用可能なパッケージ
名前                : dante
アーキテクチャ      : x86_64
バージョン          : 1.4.0
リリース            : 1.el6.rf
容量                : 766 k
リポジトリー        : rpmforge
要約                : Free Socks v4/v5 client implementation
URL                 : http://www.inet.no/dante/
ライセンス          : BSD-type
説明                : Dante is a free implementation of the proxy protocols
                    : socks version 4, socks version 5 (rfc1928) and msproxy. It
                    : can be used as a firewall between networks. It is being
                    : developed by Inferno Nettverk A/S, a Norwegian consulting
                    : company. Commercial support is available.
                    :
                    : This package contains the dynamic libraries required to
                    : "socksify" existing applications to become socks clients.

名前                : dante-devel
アーキテクチャ      : x86_64
バージョン          : 1.4.0
リリース            : 1.el6.rf
容量                : 23 k
リポジトリー        : rpmforge
要約                : Header files, libraries and development documentation for
                    : dante
URL                 : http://www.inet.no/dante/
ライセンス          : BSD-type
説明                : This package contains the header files, static libraries
                    : and development documentation for dante. If you like to
                    : develop programs using dante, you will need to install
                    : dante-devel.

名前                : dante-server
アーキテクチャ      : x86_64
バージョン          : 1.4.0
リリース            : 1.el6.rf
容量                : 337 k
リポジトリー        : rpmforge
要約                : free Socks v4/v5 server implementation
URL                 : http://www.inet.no/dante/
ライセンス          : BSD-type
説明                : This package contains the socks proxy daemon and its
                    : documentation. The sockd is the server part of the Dante
                    : socks proxy package and allows socks clients to connect
                    : through it to the network.

[root@localhost ~]# yum -y install dante*


# dante 設定
[root@localhost ~]# vi /etc/sockd.conf
	logoutput: syslog stdout /var/log/sockd.log
	debug: 2

	internal: eth0 port = 1080  
	external: eth0  
	socksmethod: username none  
	clientmethod: none  
	user.privileged: nobody  
	user.unprivileged: nobody  
	client pass {  
	    from: 0.0.0.0/0 port 1-65535 to: 0.0.0.0/0  
	}  
	socks pass {  
	    from: 0.0.0.0/0 to: 0.0.0.0/0  
	    protocol: tcp udp  
	}  

[root@localhost ~]# vi /etc/socks.conf
    route {  
     from: 0.0.0.0/0 to: 0.0.0.0/0 via: direct  
     proxyprotocol: socks_v5  
    }  

# dante restart
[root@localhost ~]# chkconfig | grep sockd
sockd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost ~]# service sockd
使い方: /etc/init.d/sockd {start|stop|restart|condrestart|status}
[root@localhost ~]# service sockd status
sockd は停止しています
[root@localhost ~]# service sockd restart
Dante Socks server (sockd) を停止中:                       [失敗]
Dante Socks server (sockd) を起動中:                       [  OK  ]

[root@localhost ~]# service sockd status
sockd (pid 1556 1555 1554 1553 1552 1551 1550 1549 1548 1547 1546 1545 1544 1543 1542 1541 1540 1539 1538 1536) を実行中...
[root@localhost ~]# netstat -tanp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1015/sshd
tcp        0      0 192.168.1.5:1080            0.0.0.0:*                   LISTEN      1536/sockd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1092/master
tcp        0     52 192.168.1.5:22              192.168.1.3:49719           ESTABLISHED 1152/sshd
tcp        0      0 :::22                       :::*                        LISTEN      1015/sshd
tcp        0      0 fe80::a00:27ff:fe02:e0:1080 :::*                        LISTEN      1536/sockd
tcp        0      0 2408:211:a84:2b00:a00::1080 :::*                        LISTEN      1536/sockd
tcp        0      0 ::1:25                      :::*                        LISTEN      1092/master

# iptable stop
[root@localhost ~]# service iptables stop
iptables: チェインをポリシー ACCEPT へ設定中filter         [  OK  ]
iptables: ファイアウォールルールを消去中:                  [  OK  ]
iptables: モジュールを取り外し中:                          [  OK  ]

これで終了。簡単。
さて、試しに curl で SOCKS接続してみます。

[root@localhost ~]# curl --socks4 192.168.1.5:1080 http://google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.jp/?gfe_rd=cr&amp;ei=UArxVOfmFYPS8ge8y4HgCA">here</A>.
</BODY></HTML>

完璧。


以下情報を参考にしました。感謝。
http://d.zinrai.info/blog/html/2014/06/13/centos65_socks_proxy_dante.html
http://memo-off.blogspot.jp/2014/06/centossocks4socks5-proxy.html
http://www.momo-i.org/chapter8/dante.html
http://centossrv.com/rpmforge.shtml