Results 1 to 4 of 4

Thread: NAT, traffic shapping problem. <SOLVED>

  1. #1
    Member registered user
    Join Date
    Mar 2004
    Location
    Buenos Aires, Argentina
    Posts
    79

    NAT, traffic shapping problem. <SOLVED>

    Hello people I've found a problem where I need some help. where I see my problem has to be something like don't understand really the difference between my ip adress and my internal ip adress.

    My situation:

    I have two computers connected to a d-link 624 router, one on cable the other on wireless.
    Both go to internet from the router.

    Internet (256kbps)
    |
    Router
    | |
    192.168.0.10 - 192.168.0.11

    On my pc (192.168.0.10) I've dns-cache(pdnsd), samba and proxy(squid) servers for my pc and the other. Making my pc the gatway the configuration on level software is something like this.

    Internet (256kbps)
    |
    Router
    |
    192.168.0.10 (linux)
    |
    192.168.0.11 (XP)

    Finally to correct some problems with bandwidth I set limits with squid, the problem is that the other pc is not always connected so I don't use the total bandwidth when only my pc is online because the limits. Reading some info I finally make this script to take control of the bandwidth

    Code:
    tc qdisc add dev eth0 root handle 1: htb default 20 
    tc class add dev eth0 parent 1: classid 1:1 htb rate 256kbps ceil 256kbps 
    tc class add dev eth0 parent 1:1 classid 1:10 htb rate 128kbps ceil 256kbps  
    tc class add dev eth0 parent 1:1 classid 1:20 htb rate 128kbps ceil 256kbps prio 1 
    
    tc qdisc add dev eth0 parent 1:10 handle 10: sfq 
    tc qdisc add dev eth0 parent 1:20 handle 20: sfq 
    
    iptables -A FORWARD -s 192.168.0.10 -t mangle -j MARK --set-mark 1 
    iptables -A FORWARD -s 192.168.0.11 -t mangle -j MARK --set-mark 2 
    
    tc filter add dev eth0 protocol ip parent 1: handle 1 fw classid 1:10
    tc filter add dev eth0 protocol ip parent 1: handle 2 fw classid 1:20
    In teory This code it's suppose to make my internet connection balanced for the two machines, the two will always have 128kbps for use, but if the other pc itÅ› not using the internet then will have all the bandwith available .

    The code works but only on the second PC (192.168.0.11) operations from my pc(192.168.010) wich must go on the class 1:10 didn't work because it uses the class 1:1. I know it didn't work because my pc is the server but I suppose it has to be a way to control shapping the bandwith on the server or making some corrections on the iptables code.

    What are looking to make is a balanced internet connection, so when my father don't use the computer i have all the bandwith or when i'm using giFT and my father wants to use the www it has bandwidth available.

    I suppose a home network don't need these servers or traffic shapping but I want to learn, so I know how to use the tools that linux has to offer.

  2. #2
    Member registered user
    Join Date
    Mar 2004
    Location
    Buenos Aires, Argentina
    Posts
    79

    It's working !

    The problem was that by default the packets from 192.168.0.10 were going to the class 1:20 and the packets from 192.168.0.11 were going to the same class as I put on the script.

    With these corrections I make it finally work
    Code:
    iptables -A FORWARD -i eth0 -s 192.168.0.11 -t mangle -j MARK --set-mark 1
    iptables -A FORWARD -i eth0 -s 192.168.0.10 -t mangle -j MARK --set-mark 2

  3. #3
    Member registered user
    Join Date
    Mar 2004
    Location
    Buenos Aires, Argentina
    Posts
    79

    Finally! :oops:

    After some testing the finally script for my configuration it's something like this...
    Code:
    tc qdisc add dev eth0 root handle 1: htb default 20
    tc class add dev eth0 parent 1: classid 1:1 htb rate 256kbps ceil 256kbps 
    tc class add dev eth0 parent 1:1 classid 1:10 htb rate 135kbps ceil 256kbps 
    tc class add dev eth0 parent 1:1 classid 1:20 htb rate 110kbps ceil 256kbps prio 1 
    
    tc qdisc add dev eth0 parent 1:10 handle 10: sfq 
    tc qdisc add dev eth0 parent 1:20 handle 20: sfq 
    
    tc filter add dev eth0 protocol ip parent 1: handle 1 fw classid 1:10
    tc filter add dev eth0 protocol ip parent 1: handle 2 fw classid 1:20
    
    iptables -A FORWARD -i eth0 -s 192.168.0.11 -t mangle -j MARK --set-mark 1
    iptables -A FORWARD -i eth0 -s 192.168.0.10 -t mangle -j MARK --set-mark 2
    For controlling I use tc -s -d class show dev eth0
    Code:
    class htb 1:1 root rate 2048Kbit ceil 2048Kbit burst 4159b/8 mpu 0b overhead 0b cburst 4159b/8 mpu 0b overhead 0b level 7 
     Sent 4168796 bytes 10442 pkts (dropped 0, overlimits 0) 
     rate 62840bit 24pps 
     lended: 0 borrowed: 0 giants: 0
     tokens: 10419 ctokens: 10419
    
    class htb 1:10 parent 1:1 leaf 10: prio 0 quantum 13500 rate 1080Kbit ceil 2048Kbit burst 2949b/8 mpu 0b overhead 0b cburst 4159b/8 mpu 0b overhead 0b level 0 
     Sent 324518 bytes 1838 pkts (dropped 0, overlimits 0) 
     rate 2632bit 2pps 
     lended: 1838 borrowed: 0 giants: 0
     tokens: 16160 ctokens: 12393
    
    class htb 1:20 parent 1:1 leaf 20: prio 1 quantum 11000 rate 880000bit ceil 2048Kbit burst 2699b/8 mpu 0b overhead 0b cburst 4159b/8 mpu 0b overhead 0b level 0 
     Sent 3844278 bytes 8604 pkts (dropped 0, overlimits 0) 
     rate 59792bit 21pps 
     lended: 8604 borrowed: 0 giants: 0
     tokens: 13375 ctokens: 10419

  4. #4
    Member registered user
    Join Date
    Mar 2004
    Location
    Buenos Aires, Argentina
    Posts
    79

    HTB.INIT

    With HTB.INIT the things are more simple. This script has 2 pros: simple rules but powerfull and organizated your connections.

    After reading the README(inside the script file) I created 5 files on /etc/sysconfig/htb: eth0, eth0-2.root, eth0-2:10.www, eth0-2:20.extra, eth0-2:30.lan

    eth0 # My only net card on the gateway my pc
    Code:
    DEFAULT=30
    R2Q=10
    DCACHE=no
    eth0-2.root # Max Speed of the net card
    Code:
    RATE=2Mbps
    BURST=8kb
    eth0-2:10.www #Class 2:10 WWW Services: dns, browser, mail, squid....
    Code:
    RATE=20kbps
    CEIL=32kbps
    LEAF=sfq
    PRIO=1
    
    RULE=*:80
    RULE=*:210
    RULE=*:591
    RULE=*:777
    RULE=*:3128
    RULE=*:443
    RULE=*:563
    RULE=*:110
    RULE=*:53
    RULE=*:3128
    eth0-2:20.extra # Services extra WWW: gift (KaZaa, OPenFt, Gnutella, Ares), Torrents
    Code:
    RATE=10kbps
    CEIL=32kbps
    BURST=2kb
    LEAF=sfq
    PRIO=3
    
    RULE=*:1214
    RULE=*:1215
    RULE=*:1216
    RULE=*:6346
    RULE=*:59049
    RULE=*:49166
    eth0-2:30.lan # Communication between my pc and the other for file exchange
    Code:
    RATE=1Mbps
    CEIL=2Mbps
    LEAF=sfq
    PRIO=5
    
    RULE=*:137
    RULE=*:138
    RULE=*:139
    RULE=*:631

    With the command tc -s -d class show dev eth0 it shows how the bandwidth of the netcard is used. only 256kbps for internet conecctions and 2 Mbps for Lan connections.
    Code:
    class htb 1:10 parent 1:2 leaf 10: prio 1 quantum 2000 rate 160000bit ceil 256000bit burst 1799b/8 mpu 0b overhead 0b cburst 1919b/8 mpu 0b overhead 0b level 0 
     Sent 287852 bytes 1417 pkts (dropped 0, overlimits 0) 
     lended: 1404 borrowed: 13 giants: 0
     tokens: 71107 ctokens: 47515
    
    class htb 1:2 root rate 16000Kbit ceil 16000Kbit burst 8Kb/8 mpu 0b overhead 0b cburst 21598b/8 mpu 0b overhead 0b level 7 
     Sent 1551826194 bytes 1080417 pkts (dropped 0, overlimits 0) 
     rate 6673Kbit 582pps 
     lended: 488052 borrowed: 0 giants: 0
     tokens: 3329 ctokens: 8821
    
    class htb 1:20 parent 1:2 leaf 20: prio 3 quantum 1000 rate 80000bit ceil 256000bit burst 2Kb/8 mpu 0b overhead 0b cburst 1919b/8 mpu 0b overhead 0b level 0 
     Sent 100634 bytes 754 pkts (dropped 0, overlimits 0) 
     rate 368bit 
     lended: 727 borrowed: 27 giants: 0
     tokens: 162530 ctokens: 47515
    
    class htb 1:30 parent 1:2 leaf 30: prio 5 quantum 100000 rate 8000Kbit ceil 16000Kbit burst 11599b/8 mpu 0b overhead 0b cburst 21598b/8 mpu 0b overhead 0b level 0 
     Sent 1551437708 bytes 1078246 pkts (dropped 0, overlimits 0) 
     rate 6448Kbit 562pps 
     lended: 590234 borrowed: 488012 giants: 0
     tokens: 9470 ctokens: 8831
    I need more info from other services like the ports that use and all will be setup correctly...I hope this is good info.

Similar Threads

  1. Printing problem (Solved)
    By antsu in forum General Support
    Replies: 0
    Last Post: 05-08-2008, 08:33 PM
  2. Boot Problem Solved!!!
    By MichaeW in forum Hardware & Booting
    Replies: 0
    Last Post: 11-20-2007, 04:17 AM
  3. 5.0.1 DVD knx-installer problem [solved]
    By Ueberbach in forum Hdd Install / Debian / Apt
    Replies: 1
    Last Post: 08-01-2006, 08:44 AM
  4. Memory Problem running UML/MLN [SOLVED]
    By svenaron in forum Customising & Remastering
    Replies: 1
    Last Post: 08-23-2005, 09:18 PM
  5. Shutdown Problem with 3.4/5-10:Please Help!(SOLVED)
    By bongski55 in forum General Support
    Replies: 0
    Last Post: 05-21-2004, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Seagate ST500DM009 BarraCuda 500 GB 3.5

Seagate ST500DM009 BarraCuda 500 GB 3.5" SATA III Desktop Hard Drive

$14.99



Dell EMC WD-HITACHI H5H72101CLAR10T0 10TB 7.2K SAS 12Gb/s SED 3.5in A POH 0-50k picture

Dell EMC WD-HITACHI H5H72101CLAR10T0 10TB 7.2K SAS 12Gb/s SED 3.5in A POH 0-50k

$189.99



Western Digital HUS726T4TAL5204 4TB 7.2K SAS 12Gb/s 3.5

Western Digital HUS726T4TAL5204 4TB 7.2K SAS 12Gb/s 3.5" 512e HDD NetApp X375A

$49.00



WD Ultrastar DC HC530 14TB SATA 6G 3.5

WD Ultrastar DC HC530 14TB SATA 6G 3.5" 7200RPM Enterprise HDD - WUH721414ALE604

$329.99



Toshiba 14TB MG07 MG07ACA14TEY 7.2K RPM SATA 6Gb/s 512e 3.5

Toshiba 14TB MG07 MG07ACA14TEY 7.2K RPM SATA 6Gb/s 512e 3.5" Enterprise HDD

$299.00



Seagate ST28000NM001C 28TB 256MB 7200RPM 3.5

Seagate ST28000NM001C 28TB 256MB 7200RPM 3.5" SATA 6.0Gb/s Enterprise Hard Drive

$669.99



Seagate ST1000VM002 1TB 5900RPM 3.5

Seagate ST1000VM002 1TB 5900RPM 3.5" SATA 6GB/s HDD Video Hard Drive PC DVR

$24.99



1 - Seagate Barracuda 1.5TB 7200RPM 3.5

1 - Seagate Barracuda 1.5TB 7200RPM 3.5" (ST31500341AS) HDD Wiped/Tested

$25.00



Western Digital 1TB 3.5

Western Digital 1TB 3.5" SATA III 7200RPM Desktop Hard Drive

$29.99



Seagate ST8000NM0075 Enterprise Capacity 3.5 HDD 8TB SAS Hard Drive 8TB EXOS picture

Seagate ST8000NM0075 Enterprise Capacity 3.5 HDD 8TB SAS Hard Drive 8TB EXOS

$184.99