vine-users ML アーカイブ



[vine-users:077936] BitTorrent 使用時のIPTables の設定例 (was Re: Re: BitTrrentのポート番号は

  • From: Hisaaki SHIBATA <shibata@xxxxxxxx>
  • Subject: [vine-users:077936] BitTorrent 使用時のIPTables の設定例 (was Re: Re: BitTrrentのポート番号は
  • Date: Mon, 31 Dec 2007 23:11:01 +0900
柴田(ひ)@福岡です。

	#スペルミスもあったので、勝手ながらSubjectを書き換えました。

http://btfaq.com/serve/cache/25.html
にズバリの回答があるようです。

全文を読むと分かると思いますけど、
該当ポートをクライアント(この場合はNAT内のWin-PC)にフォワードしないと
性能が出ないみたいですね。

該当部分を引用します。

If you are using a linux box as your firewall machine, and are using iptables as your NAT/firewall, here's how you can enable portforwarding to a specific machine for BitTorrent. Either append to your iptable configuration script or put this in a file of its own. This was written in bash, but should work for ash, zsh or plain old bourne shell too (not csh however).
---- start shellscript ----

#!/bin/bash
#bittracker portforwarding
BTFORWARDADDR=192.168.1.3
BTPORTS="6890 6891 6892 6893 6894 6895 6896 6897 6898 6899"
for pt in $BTPORTS; do
  /sbin/iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport $pt -j DNAT --to-destination $BTFORWARDADDR:$pt
  /sbin/iptables -A FORWARD -s $BTFORWARDADDR -p tcp --dport $pt -j ACCEPT
done
 

---- end shellscript ----
What this does is for each port in the BTPORTS string, establish a prerouting forward to send it directly to the machine listed in BTFORWARDADDR instead of mangling it through NAT. Also, in the event you have a default setting of DENY or REJECT for your forwarding rules, it allows forwarding from the BTFORWARDADDR machine on each of the BTPORTS out to the net.

 In addition to the syntax illustrated here, iptables supports the specification of a range of ports using the syntax --dport $START:$END so the whole 6881-6999 range used in BT 3.2+ can be NAT'ed. For example...
=== start script === 
#!/bin/bash BTFORWARDADDR=192.168.2.20 PORTSTART=6881 PORTEND=6999

  /sbin/iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport $PORTSTART:$PORTEND -j DNAT --to-destination $BTFORWARDADDR
  /sbin/iptables -A FORWARD -s $BTFORWARDADDR -p tcp --dport $PORTSTART:$PORTEND -j ACCEPT

=== end script ===
This assumes that the host to which these ports will be forwarded, BTFORWARDADDR, will be using the same range i.e. no port redirection is required. 

> 中司と申します。
> 
> BitTrrent のポート番号は、6881 - 6889 と
> 認識しているのですが、うまくGWの設定ができないです。
> cableインターネットを使用しているのですが、
> GWをかえさずに実行すると下りで150kB/s程度
> GWを介入させて実行すると下りで  3kB/s程度
> です。
> 使用しているソフトはWin用で、BitComet 0.97 です。
> 
> 
> (1)当方のGWの設定は、
> #!/bin/bash
> 
> HOME='192.168.0.0/24'       #ローカルネットワークアドレス
> IPTABLES='/sbin/iptables'
> 
> #IPフォワードの停止
> echo 0 > /proc/sys/net/ipv4/ip_forward
> #全てのルールを削除する
> $IPTABLES -F
> 
> #すべてのアクセスを拒否する
> $IPTABLES -P INPUT   DROP
> $IPTABLES -P FORWARD DROP
> $IPTABLES -P OUTPUT  DROP
> 
> ### ループバックアドレスに関するアクセスを全て許可 ###
>  $IPTABLES -A INPUT  -i lo -j ACCEPT
>  $IPTABLES -A OUTPUT -o lo -j ACCEPT
> 
> # for localnet (ローカルネット)
> #    eth0(内部)からのアクセスはすべて許可(ACCEPT)
>  $IPTABLES -A INPUT  -i eth0 -j ACCEPT
>  $IPTABLES -A OUTPUT -o eth0 -j ACCEPT
> 
> # for ping(imcp)
> #自端末からの入力を許可
>  $IPTABLES -A INPUT   -i lo   -p icmp -j ACCEPT
>  $IPTABLES -A INPUT   -i eth0 -p icmp -j ACCEPT
>  $IPTABLES -A FORWARD -i eth0 -p icmp -j ACCEPT
> 
> ### DNSサーバからの外部DNS問い合わせを許可 ###
>  $IPTABLES -A OUTPUT         -p udp --dport 53 -j ACCEPT
>  $IPTABLES -A OUTPUT         -p tcp -m state --state NEW --dport 53 -j ACCEPT
> 
> # for output
> # (localから外部)ntp による接続を許可
>  $IPTABLES -A OUTPUT  -p udp --dport 123  -j ACCEPT
> # for www      www の閲覧も許可(ACCEPT)
>  $IPTABLES -A OUTPUT  -p tcp --dport  80  -j ACCEPT #http
>  $IPTABLES -A OUTPUT  -p tcp --dport 443  -j ACCEPT #https
> # for ftp
>  $IPTABLES -A OUTPUT  -p tcp --dport  20  -j ACCEPT
>  $IPTABLES -A OUTPUT  -p tcp --dport  21  -j ACCEPT
> # for masquerade
> #     IP マスカレードの定義
> #
> #$IPTABLES -t nat -A POSTROUTING -o eth0 -j MASQUERADE
>  $IPTABLES -t nat -A POSTROUTING -s 192.168.0.0/255.255.255.0 -j MASQUERADE
> # for www      www の閲覧も許可(ACCEPT)
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  80  -j ACCEPT    #http
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport 443  -j ACCEPT    #https
> # for ftp
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  20  -j ACCEPT    #http
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  21  -j ACCEPT    #https
> # for POP      メールの受信許可
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport 110  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport 143  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport 993  -j ACCEPT
> # for SMTP     メールの送信許可
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  25  -j ACCEPT
> # for DNS
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  53 -j ACCEPT
> # for ntpdate
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport 123  -j ACCEPT
> # for WWW-Go
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport 10001  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport 10005  -j ACCEPT
> # for BitTrrent
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  6881  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  6882  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  6883  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  6884  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  6885  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  6886  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  6887  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  6888  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport  6889  -j ACCEPT
> # for BitTrrent
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  6881  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  6882  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  6883  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  6884  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  6885  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  6886  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  6887  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  6888  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport  6889  -j ACCEPT
> 
>  $IPTABLES -A FORWARD  -i eth0 -p tcp --dport 13302  -j ACCEPT
>  $IPTABLES -A FORWARD  -i eth0 -p udp --dport 13302  -j ACCEPT
> #
> #-----------------------------------------------------------------------
> #次に、既にconnectionが張られている通信を許可します。
> # for establish
> #     接続が確立したパケットは許可
>  $IPTABLES -A INPUT   -m state --state ESTABLISHED,RELATED -j ACCEPT
>  $IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
> 
> #  logging
>  $IPTABLES -A INPUT   -j LOG -m limit --limit 5/minute --log-prefix "Dropping[inp]: "
>  $IPTABLES -A OUTPUT  -j LOG -m limit --limit 5/minute --log-prefix "Dropping[out]: "
>  $IPTABLES -A FORWARD -j LOG -m limit --limit 5/minute --log-prefix "Dropping[for]: "
> 
> /sbin/iptables-save > /etc/sysconfig/iptables
> echo 1 > /proc/sys/net/ipv4/ip_forward
> 
> 
> (2)iptables -L の結果は、
> # iptables -L
> Chain INPUT (policy DROP)
> target     prot opt source               destination
> ACCEPT     all  --  anywhere             anywhere
> ACCEPT     all  --  anywhere             anywhere
> ACCEPT     icmp --  anywhere             anywhere
> ACCEPT     icmp --  anywhere             anywhere
> ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
> LOG        all  --  anywhere             anywhere            limit: avg 5/min burst 5 LOG level warning prefix `Dropping[inp]: '
> 
> Chain FORWARD (policy DROP)
> target     prot opt source               destination
> ACCEPT     icmp --  anywhere             anywhere
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ftp-data
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ftp
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:pop3
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:imap
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:imaps
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:smtp
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:ntp
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:10001
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:10005
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6881
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6882
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6883
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6884
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6885
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6886
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6887
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6888
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6889
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:6881
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:6882
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:6883
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:6884
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:6885
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:6886
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:6887
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:6888
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:6889
> ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
> LOG        all  --  anywhere             anywhere            limit: avg 5/min burst 5 LOG level warning prefix `Dropping[for]: '
> 
> Chain OUTPUT (policy DROP)
> target     prot opt source               destination
> ACCEPT     all  --  anywhere             anywhere
> ACCEPT     all  --  anywhere             anywhere
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
> ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:domain
> ACCEPT     udp  --  anywhere             anywhere            udp dpt:ntp
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:http
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:https
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ftp-data
> ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ftp
> LOG        all  --  anywhere             anywhere            limit: avg 5/min burst 5 LOG level warning prefix `Dropping[out]: '
> 
> です。

-- 
 WWWWW  shibata@xxxxxxxx
 |O-O|  柴田 尚明@福岡市  また「ひげ」はえました。
0(mmm)0 本店   http://his.luky.org/
   ~    姪浜店 http://hoop.euqset.org/        IRC: #luky