LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 04-02-2007, 12:21 PM   #1
Smelly_Kat
LQ Newbie
 
Registered: Apr 2007
Distribution: Gentoo, Ubuntu
Posts: 4

Rep: Reputation: 0
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
 
Old 04-02-2007, 12:31 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 04-02-2007, 12:38 PM   #3
Smelly_Kat
LQ Newbie
 
Registered: Apr 2007
Distribution: Gentoo, Ubuntu
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 04-02-2007, 01:28 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.

Last edited by acid_kewpie; 04-02-2007 at 01:32 PM.
 
Old 04-02-2007, 01:59 PM   #5
Smelly_Kat
LQ Newbie
 
Registered: Apr 2007
Distribution: Gentoo, Ubuntu
Posts: 4

Original Poster
Rep: Reputation: 0
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.
 
Old 04-02-2007, 03:11 PM   #6
Smelly_Kat
LQ Newbie
 
Registered: Apr 2007
Distribution: Gentoo, Ubuntu
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
limit specific proces to a specific user Tux-Slack Linux - Software 3 02-23-2007 11:38 PM
Bouncing specific domain with specific message dlublink Linux - Software 1 08-21-2006 02:29 PM
How to make a specific command(s) work for specific users or group only naren_0101bits Linux - General 3 08-28-2005 05:22 PM
How to make a specific command(s) work in a specific shell only naren_0101bits Linux - Newbie 3 08-28-2005 01:24 PM
Searching a specific directory for a specific extension? RoaCh Of DisCor Linux - Newbie 3 08-13-2005 03:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 05:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration