Skip to content


การ block torrent อย่างง่าย

พอดีวันนี้ว่างๆ เลยเอาของที่มีอยู่แล้วมาใส่ไว้ใน wiki เพื่อจะได้เป็นความรู้ไว้ใช้ต่อไปในอนาคต วันนี้จึงมานำเสนอการ block torrent เพราะ มีอยู่ช่วงนึงที่บ้านแชร์ไฟล์กันกระจาย ไม่มีระเบียบ บางช่วงจึงทำงานไม่ได้เพราะเนตช้า ก็เลยหาทางวิธีทำการบล็อกโดยไม่ต้องลงทุนอะไร ถึงแม้จะมีช่องโหว่อยู่ก็ตาม แต่ก็ยังดีกว่าไม่ได้จัดการอะไรเลย
ที่ว่าไม่ต้องลงทุนเพราะใช้ตัวจัดการเป็น computer PC ธรรมดา ที่ปกติก็เปิดไว้สำหรับ share file อยู่แล้วก็เลยเอามาทำเป็น routing server (ไม่รู้เรียกถูกหรือเปล่า) ซะเลย โดยทำตามลิงค์ข้างล่างนี้ครับ

จาก WikiBall

เนื้อหา



Network Infrastructor

  1. Gateway router : adsl เราเตอร์ทั่วไป กำหนด ip เป็น 192.168.0.2 (เป็นอย่างอื่นได้ 192.168.0.X แต่ต้องตั้งค่าอื่นให้ตรงตามนี้ด้วย) ซึ่ง adsl router แต่ละรุ่นจะมีวิธีตั่งค่า gateway ที่แตกต่างกัน
  2. Routing server : เนื่องจากคุณสมบัติของ Gateway ถึงแม้จะมันเรียกกันว่า router ก็ตาม แต่ไม่มีคุณสมบัติในการ route หาเส้นทางแต่อย่างใด ดังนั้นจึงจำเป็นต้องใช้ PC หรือเครื่องคอมพิวเตอร์อื่นในการทำการหาเส้นทางแทน ไม่จำเป็นต้องแรง เพราะของผมที่ใช้งานอยู่ก็ PIII ram 128MB ก็ใช้ได้ แต่ควรมี UPS ซักหน่อยเพื่อความเสถียร
  3. Client : เครื่อง PC หรือ Notebook ของผู้ใช้งาน


Program Installation and Configuration


Routing Server

ติดตั้งโปรแกรมสำคัญในเรื่อง Routing server ซึ่งในที่นี้จะใช้ OS เป็น Ubunutu(Linux) ซึ่งจะใช้ Linux ตัวอื่นก็ไม่ผิด แต่อาจมี configuration file ของบางโปรแกรมอยู่ไม่ตรงกัน


Network Interface configuration

$ sudo vim /etc/network/interfaces

ตั้งค่าเป็น

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
#auto eth0
#iface eth0 inet dhcp

auto eth0
iface eth0 inet static
        address 192.168.0.1
        netmask 255.255.255.0
        network 192.168.0.0
        gateway 192.168.0.2

auto eth0:1
iface eth0:1 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        network 192.168.1.0
        #firewall configuration
        pre-up sh /etc/network/firewall/firewall.sh


Network Firewall

สร้าง diretory ชื่อ firewall ใน /etc/network/ หรือที่ไหนก็ได้แต่อย่าลืมเปลี่ยนบรรทัดสุดท้านใน interfaces ให้ตรงด้วย

/etc/network$ sudo mkdir firewall
/etc/network$ cd firewall
/etc/network/firewall$ sudo vim torrent-block.iptables
# Generated by iptables-save v1.4.0 on Sat Jan 10 23:19:36 2009
*filter
:INPUT ACCEPT [1148:92586]
:FORWARD DROP [1106:549432]
:OUTPUT ACCEPT [835:103625]

# open icmp packet
-A FORWARD -i eth0 -p icmp -j ACCEPT
-A FORWARD -i eth0:1 -p icmp -j ACCEPT 

# open forward tcp port
-A FORWARD -p tcp --dport 20 -j ACCEPT
-A FORWARD -p tcp --sport 20 -j ACCEPT
-A FORWARD -p tcp --dport 21 -j ACCEPT
-A FORWARD -p tcp --sport 21 -j ACCEPT
-A FORWARD -p tcp --dport 22 -j ACCEPT
-A FORWARD -p tcp --sport 22 -j ACCEPT
-A FORWARD -p tcp --dport 23 -j ACCEPT
-A FORWARD -p tcp --sport 23 -j ACCEPT
-A FORWARD -p tcp --dport 25 -j ACCEPT
-A FORWARD -p tcp --sport 25 -j ACCEPT
-A FORWARD -p udp --dport 53 -j ACCEPT
-A FORWARD -p udp --sport 53 -j ACCEPT
-A FORWARD -p tcp --dport 53 -j ACCEPT
-A FORWARD -p tcp --sport 53 -j ACCEPT
-A FORWARD -p tcp --dport 80 -j ACCEPT
-A FORWARD -p tcp --sport 80 -j ACCEPT
-A FORWARD -p tcp --dport 443 -j ACCEPT
-A FORWARD -p tcp --sport 443 -j ACCEPT
-A FORWARD -p tcp --dport 88 -j ACCEPT
-A FORWARD -p tcp --sport 88 -j ACCEPT
-A FORWARD -p tcp --dport 135:139 -j ACCEPT
-A FORWARD -p tcp --sport 135:139 -j ACCEPT
-A FORWARD -p tcp --dport 445 -j ACCEPT
-A FORWARD -p tcp --sport 445 -j ACCEPT
-A FORWARD -p tcp -s 192.168.0.0/24 -j ACCEPT
-A FORWARD -p tcp -d 192.168.0.0/24 -j ACCEPT
COMMIT
# Completed on Sat Jan 10 23:19:36 2009

# Generated by iptables-save v1.4.0 on Sat Jan 10 23:19:36 2009
*nat :P REROUTING ACCEPT [166:14287] :P OSTROUTING ACCEPT [3:337]
:OUTPUT ACCEPT [3:337]
-A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT --to-source 192.168.0.1
COMMIT
# Completed on Sat Jan 10 23:19:36 2009


Bash script

สร้าง Bash script อย่างง่ายเพื่อ run command หรือจะเรียกใน shell ตามคำสั่งต่อไปนี้ได้เลย

# Add static static route
# if-UP
route add -net 192.168.0.0 netmask 255.255.255.0 gw 192.168.0.1 dev eth0
route add -net 192.168.1.0 netmask 255.255.255.0 gw 192.168.1.1 dev eth0:1
iptables-restore /etc/network/firewall/torrent-block.iptables


DHCP

เพื่อจะให้เครื่อง server ของเราแจก ip ได้โดยอัตโนมัติ
ติดตั้ง dhcpd3

$ sudo apt-get install dhcp3-server
$ sudo vim /etc/dhcp3/dhcpd.conf

ตั้งค่า

# Sample configuration file for ISC dhcpd for Debian
#
# Attention: If /etc/ltsp/dhcpd.conf exists, that will be used as
# configuration file instead of this file.
#
# $Id: dhcpd.conf,v 1.1.1.1 2002/05/21 00:07:44 peloy Exp $
#

# The ddns-updates-style parameter controls whether or not the server will
# attempt to do a DNS update when a lease is confirmed. We default to the
# behavior of the version 2 packages ('none', since DHCP v2 didn't
# have support for DDNS.)
ddns-update-style none;

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.

#subnet 10.152.187.0 netmask 255.255.255.0 {
#}

# This is a very basic subnet declaration.

# A slightly different configuration for an internal subnet.
subnet 192.168.1.0 netmask 255.255.255.0 {
  range 192.168.1.50 192.168.1.130;
  option domain-name-servers 58.64.124.150;
# option domain-name "internal.example.org";
  option routers 192.168.1.1;
  option broadcast-address 192.168.1.255;
  default-lease-time 600;
  max-lease-time 7200;
}
$ sudo /etc/init.d/dhcp3-server start


ข้อดี ข้อเสีย


ข้อดี

  1. สร้างง่าย
  2. ต้นทุนต่ำ เพราะไม่ต้องลงทุนมาก มีเครื่องเก่าก็เอามาประยุกต์ใช้ได้


ข้อเสีย

  1. ถ้าผู้ใช้มีความรู้มากหน่อย ก็จะสามารถหาช่องทางออกช่องอื่นได้ง่าย เพราะยังดีช่องโหว่อยู่มีเยอะให้ออก

รับข้อมูลจาก (Reference) :

จาก WikiBall : http://wiki.memoball.info/index.php/การบล็อค_torrent_อย่างง่าย

ส่วนใครจะตั้งเวลาปิดเปิด torrent ก็ใช้ crontab รัน script เอาครับ

Posted in Linux, Networking. Tagged with , .

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.