LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Controlling BitTorrent on a specific IP (https://www.linuxquestions.org/questions/linux-networking-3/controlling-bittorrent-on-a-specific-ip-542695/)

Smelly_Kat 04-02-2007 12:21 PM

Controlling BitTorrent on a specific IP
 
Hello,
I'm having trouble controlling p2p usage [mostly BitTorrent] over my network - one of my flatmates, who has no concept of QoS or bandwidth limiting is torrenting all the time now. This is causing problems despite my all my traffic shaping. The problem is with one specific user - I'd rather not apply any restrictions to any other users at the moment. To fix the problem I'd like to block everything and allow only specific services [ssh, SSL, http, etc] on that IP. I tried this [adapted from another thread] on my own computer...

Code:

#!/bin/bash

iptables --flush
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
iptables -A OUTPUT -p udp -o eth0 --dport 53 --sport 1024:65535 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m multiport --dport 22,25,80,81,110,143,443,465,563,993,995,1863 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m multiport --dport 53,6667,1080,8080 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

This works perfectly on my own computer! So now I'd like to add this script to my server with a specified IP and test it. Only trouble is, I've tried specifying my IP and it blocks all connectivity on my computer [obviously, I'd like to test this on my computer before applying it to anybody else].

This is what I tried

Code:

iptables -A INPUT -s 10.0.0.5 -j DROP
iptables -A FORWARD -s 10.0.0.5 -j DROP
iptables -A OUTPUT -s 10.0.0.5 -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -p udp -o eth0 --dport 53 --sport 1024:65535 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m multiport --dport 22,25,80,81,110,143,443,465,563,993,995,1863 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m multiport --dport 53,6667,1080,8080 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

I also tried moving the first 3 lines at the end and found they blocked nothing.

Could anyone give me some idea as to what I should try next.

Thanks!
Kat

acid_kewpie 04-02-2007 12:31 PM

well...

1) sounds like a caring sharing household!

2) what is your network topology? you can only affect traffic if it passes through your machine as a route or bridge. if it's all your desktops and an adsl router, then you're out of luck.

Smelly_Kat 04-02-2007 12:38 PM

I torrent a lot myself so like to keep things limited! :)

OK network topology...

Linux Router, eth0 --> Modem --> Internet
eth1 --> LAN [10.0.0.x]
eth2 --> WLAN [10.0.1.x]

So I'd like to control all traffic on eth0.

acid_kewpie 04-02-2007 01:28 PM

sorry, you've tried this on your own machine only? well when it's on a router, you'd use the FORWARD chain only and it should work fine to my (less than ideal iptables) knowledge.

Smelly_Kat 04-02-2007 01:59 PM

I've tried the first script on my machine and the 2nd on my server.

I suspected I might need the FORWARD chain only - I'll give it a go when nobody else is using the net!

Thanks for your help. :)

Smelly_Kat 04-02-2007 03:11 PM

Well after trying that on my own IP I haven't had much luck - I can still torrent! Here is the first part of my network setup script.. [I won't post all of it because it is rather long]

Code:

#!/bin/bash
#init Network Setup Script
echo "Setup Initialized..."

echo "Flushing existing chains..."
# Delete and flush. Default table is "filter". Others like "nat" must be explicitly stated.
iptables --flush
iptables --table nat --flush
iptables --delete-chain
iptables --table nat --delete-chain

iptables -I FORWARD -i eth0 -s 10.0.0.76 -j REJECT
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT -p udp -o eth0 --dport 53 --sport 1024:65535 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m multiport --dport 22,25,80,81,110,143,443,465,563,993,995,1863 -j ACCEPT
iptables -A OUTPUT -o eth0 -p tcp -m multiport --dport 53,6667,1100,6669,1080,8080 -j ACCEPT
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT

# Accept everything on loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

echo "Setting up IP FORWARDing"
# Set up IP FORWARDing and Masquerading
iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE
iptables --append FORWARD --in-interface eth1 -j ACCEPT
iptables --append FORWARD --in-interface eth2 -j ACCEPT

echo 1 > /proc/sys/net/ipv4/ip_forward



All times are GMT -5. The time now is 11:40 PM.