Traffic Control With Wondershaper While Still Letting Your LAN Speeds Stay Super Fast

Wondershaper is pretty nice and easy traffic shaping tool for linux.  It’s been around for a while (and has its critics), but I find it to be a great tool.

It’s so useful for a pretty straightforward reason:  I can use a lot of bandwidth if I’m not careful, particularly upstream.  And while I’ve got pretty good speeds at my place now, I don’t want to totally annoy friends when I’m over at their house.  My amour still checks to see if I’m on the internet whenever her Roku starts buffering…

So that’s where we get to Wondershaper.  It helps limit and prioritize the bandwidth traffic coming to and from your computer so that the “tubes” don’t get congested.

Yes, it takes a little time to set up, but there are some excellent guides to walk you through it.  (If you can’t see the link, it’s https://bit.ly/1kU0AHn.)  Most of the legwork needed will also help you set up properly Quality of Service settings on your router;  the cool thing here is that Wondershaper will help make those QoS settings work even better since your computer isn’t trying to shove more through the router.1

Except for one small thing.  For most people in the US, the bandwidth on your local network far exceeds the speeds you have to the internet.  Here’s the wireless network standard speeds (most wired networks are 100Mbps)

802.11b – 11 Mbps (2.4GHz)
802.11a – 54 Mbps (5 GHz)
802.11g – 54 Mbps (2.4GHz)
802.11n – 150Mbps – 600 Mbps (2.4GHz and 5 GHz)
802.11ac – 1300 Mbps (5 GHz)

I just tested my internet speeds, and it’s 7.88Mbps down (and 0.89Mbps up)… so there’s no way that I could download from the internet faster than even an old wireless standard could handle.

Wondershaper doesn’t know that.

As Wondershaper is currently written (at least in Debian and Ubuntu) it doesn’t differentiate between traffic out to the internet and between two computers on the same network.  So it made things really slow when I was trying to copy my music to another computer.

I managed to find where roobinatube had figured this out back in 2011.  By just adding a few lines of code, Wondershaper completely ignore LAN traffic and while still doing its job with internet-bound traffic. Let me walk you through what to do:

1.  Find out what your LAN’s private IP address space is.  (You can find out with the ip route command from iproute2.)  Most people’s are 192.168.. or 10...*, where the asterisks can be any number from 0 to 255.

Here’s an example output:

default via 192.168.0.0 dev eth0
192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.129

192.168.0.0 would be the router in this example, which the computer is connected to by the eth0 (or ethernet) connection. The /24 on the second line tells us that only the last number changes in our LAN.

2.  Find where the Wondershaper script is on your system.

which wondershaper
  1. Open Wondershaper in your favorite text editor. (I’m using where Wondershaper is installed on my system here.) You’ll probably need superuser permissions, so
sudo nano /usr/sbin/wondershaper
gksudo gedit /usr/sbin/wondershaper
kdesudo geany /usr/sbin/wondershaper

Here’s the fun part:

  1. Modification One.

Find these lines in the program.

# Set the following values to somewhat less than your actual download
# and uplink speed. In kilobits. Also set the device that is to be shaped.
DOWNLINK=$2
UPLINK=$3
DEV=$1

Add these lines below making sure that you change the subnet. (Example: If your subnet from above is 192.168.2.0/24, then the value for LAN_SUBNET is 192.168.2.0…) And yes, I recommend leaving the comment so when you’ve forgotten what you did and find it again it saves you time.

# added to exclude LAN https://ideatrash.net/2014/07/making-wondershaper-play-nice-on-lan.html
LAN_SPEED=”100000″
LAN_SUBNET=”192.168.0.0″
  1. Modification Two. Now find these lines:
/sbin/tc class add dev $DEV parent 1:1 classid 1:30 cbq rate $((8*$UPLINK/10))kbit
allot 1600 prio 2 avpkt 1000

And add a blank line and then add this:

# added to exclude LAN https://ideatrash.net/2014/07/making-wondershaper-play-nice-on-lan.html
#put lan traffic into lan class
/sbin/tc filter add dev $DEV parent 1:0 protocol ip prio 1 u32
match ip src $LAN_SUBNET/24
match ip dst $LAN_SUBNET/24
flowid 1:3
  1. Modification Three. And finally, find this line (it should be just under a part that says “downlink”):
/sbin/tc qdisc add dev $DEV handle ffff: ingress

And then add this immediately below it

# added to exclude LAN https://ideatrash.net/2014/07/making-wondershaper-play-nice-on-lan.html
tc filter add dev $DEV parent ffff: prio 1 u32
match ip src $LAN_SUBNET/24
match ip dst $LAN_SUBNET/24
flowid :1

Your bandwidth will flow more smoothly – both within your LAN and out to the world at large.

1 If you have a laptop, you might have realized that the settings for Wondershaper won’t be the same at every location. We’ll hit that with my network control script later this week.