LinuxQuestions.org
Visit Jeremy's Blog.
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-10-2015, 08:35 AM   #1
garett
LQ Newbie
 
Registered: Dec 2014
Posts: 7

Rep: Reputation: Disabled
Traffic control (tc) - how to limit some local IP's?


Hello! Looks like I need your help: I'm trying to limit speed on my Linux gateway (2 network interfaces, local network 192.168.0.0/24 (eth0) & real world (eth1)). There is no squid, just iptables (need to limit all the protocol types, not just port 80). So my action was:
tc qdisc add dev eth0 root tbf rate 1mbit burst 10kb latency 70ms #download speed limit
tc qdisc add dev eth1 root tbf rate 1mbit burst 10kb latency 70ms #upload speed limit

All is OK, speed has been changed from 100 Mbit/s to 1 Mbit/s. But - I should limit just 2 workstations with static IP's. How can I limit them to 1 Mbps except others? Thanks :-)
 
Old 04-10-2015, 02:22 PM   #2
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,850

Rep: Reputation: 161Reputation: 161
You can bind tc and iptable together, using iptable to indicate these two static IPs.
 
Old 04-10-2015, 02:43 PM   #3
garett
LQ Newbie
 
Registered: Dec 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Smile

Quote:
Originally Posted by nini09 View Post
You can bind tc and iptable together, using iptable to indicate these two static IPs.
Can you give me simple example, please?
 
Old 04-13-2015, 02:43 PM   #4
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,850

Rep: Reputation: 161Reputation: 161
iptables has a method called fwmark, which can be used to add a mark to packages, a mark that can survive routing across interfaces.

First, this makes packages marked with 6, to be processed by the 1:30 class

tc filter add dev eth0 protocol ip parent 1: prio 1 handle 6 fw flowid 1:30

This sets that mark 6, using iptables

iptables -A PREROUTING -t mangle -s 192.168.0.1 -j MARK --set-mark 6
 
Old 04-28-2015, 10:09 AM   #5
garett
LQ Newbie
 
Registered: Dec 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by nini09 View Post
iptables has a method called fwmark, which can be used to add a mark to packages, a mark that can survive routing across interfaces.

First, this makes packages marked with 6, to be processed by the 1:30 class

tc filter add dev eth0 protocol ip parent 1: prio 1 handle 6 fw flowid 1:30

This sets that mark 6, using iptables

iptables -A PREROUTING -t mangle -s 192.168.0.1 -j MARK --set-mark 6
I'm sorry for a silly question :-) but -
here is my current iptables-script:

*filter
-A FORWARD -s 192.168.0.0/24 -i eth0 -o eth1 -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
COMMIT
*nat
-A PREROUTING -d real_IP/32 -i eth1 -p tcp -m tcp --dport 3389 -j DNAT --to-destination 192.168.0.50:3389
-A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE
COMMIT
So there is only one workstation behind my NAT (test network), 3389 - is a port for Remote Control. So I'm trying to add your example:

*filter
-A FORWARD -s 192.168.0.0/24 -i eth0 -o eth1 -j ACCEPT
-A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
COMMIT
*nat
-A PREROUTING -t mangle -s 192.168.0.50 -j MARK --set-mark 6
-A PREROUTING -d real_IP/32 -i eth1 -p tcp -m tcp --dport 3389 -j DNAT --to-destination 192.168.0.50:3389
-A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE
COMMIT
But this scheme is not working. 192.168.0.50 is my workstation IP-address.

Last edited by garett; 04-28-2015 at 10:26 AM.
 
Old 04-29-2015, 02:35 PM   #6
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,850

Rep: Reputation: 161Reputation: 161
What's your tc setting?
 
Old 04-30-2015, 03:00 AM   #7
garett
LQ Newbie
 
Registered: Dec 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by nini09 View Post
What's your tc setting?
There is a script /etc/init.d/tc.sh:

#!/bin/bash

/sbin/tc qdisc del dev eth0 root
/sbin/tc qdisc add dev eth0 root tbf rate 1mbit burst 10kb latency 70ms

I added this script to autorun using command: update-rc.d tc.sh defaults
 
Old 04-30-2015, 02:45 PM   #8
nini09
Senior Member
 
Registered: Apr 2009
Posts: 1,850

Rep: Reputation: 161Reputation: 161
Read the link, http://lartc.org/howto/lartc.cookboo...nat.intro.html, to write correct tc script.
 
  


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
redirect local traffic to another local IP. ?iptables jschwalbe Linux - Networking 4 07-30-2014 02:38 PM
Traffic Shaping VoiP using TC (Traffic Control) is this working? Nemus Linux - Networking 0 05-16-2011 01:45 PM
Should traffic control root qdsic & child class limit traffic? Washington Ratso Linux - Networking 0 02-23-2011 07:16 PM
tc traffic control tc traffic control Linux QoS control tool(noob help) inv|s|ble Linux - General 1 07-26-2007 11:12 AM

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

All times are GMT -5. The time now is 08:16 PM.

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