Question: 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?

Answer: 
```
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
```
**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](http://www.unixmen.com/how-to-block-bittorrent-traffic-on-your-linux-firewall/)

[How to Block Bittorrent Traffic with IPtables](http://briansnelson.com/How_to_Block_Bittorrent_Traffic_with_IPtables)