3

I want to block all P2P (including bittorrent) traffic going through my Ubuntu Server. I have tried :

  1. Blocking certain strings, but it's not effective or user friendly
  2. Blocking IPs that resolve to trackers, but it's impossible to keep pace with them so I need a more effective solution

What other options are there?

Oli
  • 299,936
Vitalik Jimbei
  • 379
  • 2
  • 7
  • 19

2 Answers2

-1
iptables -I FORWARD -p tcp -m iprange --src-range 192.168.1.2-192.168.1.100 --dport 1000:65010 -m time --timestart 05:00 --timestop 23:59 --weekdays Mon,Tue,Wed,Thu,Fri,Sat,Sun -j DROP
iptables -I FORWARD -p udp -m iprange --src-range 192.168.1.2-192.168.1.100 --dport 1000:65010 -m time --timestart 05:00 --timestop 23:59 --weekdays Mon,Tue,Wed,Thu,Fri,Sat,Sun -j DROP
  • 2
    Thank you for answer. If possible, you could elaborate a little more on it, so people can understand why they're doing what they're doing and how they can adapt this answer to their specific needs. Just edit your answer to do that. – Henning Kockerbeck Nov 18 '16 at 23:20
  • 5
    why the timestamp and why the weekdays ? – Vitalik Jimbei Nov 21 '16 at 12:20
-2

Block torrents using iptables

Log Torrent

iptables -N LOGDROP > /dev/null 2> /dev/null
iptables -F LOGDROP
iptables -A LOGDROP -j LOG --log-prefix "LOGDROP "
iptables -A LOGDROP -j DROP

Block Torrent

iptables -A FORWARD -m string --algo bm --string "BitTorrent" -j LOGDROP
iptables -A FORWARD -m string --algo bm --string "BitTorrent protocol" -j LOGDROP
iptables -A FORWARD -m string --algo bm --string "peer_id=" -j LOGDROP
iptables -A FORWARD -m string --algo bm --string ".torrent" -j LOGDROP
iptables -A FORWARD -m string --algo bm --string "announce.php?passkey=" -j LOGDROP
iptables -A FORWARD -m string --algo bm --string "torrent" -j LOGDROP
iptables -A FORWARD -m string --algo bm --string "announce" -j LOGDROP
iptables -A FORWARD -m string --algo bm --string "info_hash" -j LOGDROP

Block DHT keyword

iptables -A FORWARD -m string --string "get_peers" --algo bm -j LOGDROP
iptables -A FORWARD -m string --string "announce_peer" --algo bm -j LOGDROP
iptables -A FORWARD -m string --string "find_node" --algo bm -j LOGDROP

References

How to Block BitTorrent traffic on your Linux firewall

How to Block Bittorrent Traffic with IPtables

  • 2
    -1 You're now blocking every (unencrypted) web site, e-mail, etc., that contains the word "torrent" or "announce". Equally, if an encryption/compression/base64 filter incidentally produces one of these byte sequences, the connection transferring its output is dropped. – David Foerster Dec 10 '15 at 22:46
  • not full solution. most torrents use encrypted ssl traffic, not able to track all of it. it's a hit and miss

    for those facing this issue i advise xtables adddons

    – Vitalik Jimbei Dec 18 '15 at 08:54