Prioritising network traffic on specific network interfaces

I run debian 9.4 (stretch) on my primary laptop right now (turns out every year can be "the year of the linux laptop" if you just get stuck in!!).

One thing that had been bugging me over a few months earlier this year was woeful WiFi performance while in the office. I eventually fixed it with the following script in /etc/NetworkManager/dispatcher.d/02wlan_power

!/bin/sh
IF=$1
STATUS=$2
IFACES=$(iwconfig 2> /dev/null | grep "802.11" | awk '{print $1}')
for iface in $IFACES; do
    if [ "${IF}" = "${iface}" ] && [ "${STATUS}" = "up" ]; then
        iwconfig ${iface} power off
        logger "${iface}: turning off powersave mode to prevent constant reconnections"
    fi
done

The second thing that had been bugging me was that this was happening even when I was at my desk (which has a cat5e connection to my docking station). Fortunately, I found a few minutes today to learn about ifmetric, which allows you to prioritise which interface your traffic flows over.

I added the following snippet to /etc/network/interfaces:

iface eth-dock0 inet dhcp
  up ifmetric eth-dock0 10 

iface eth-laptop0 inet dhcp
  up ifmetric eth-laptop0 30 

iface wifi0 inet dhcp

  up ifmetric wifi0 50

so now my traffic is routed over the best available path based on the circumstances.

Enjoy!

Comments

Popular posts from this blog

Want to export all *your* facebook data? you now can...

Writing valid/standard code