Traffic control - Make DNS requests delayed and low priority on Linux

1 min read Original article ↗
#!/bin/sh
# SPDX-License-Identifier: MIT
## Copyright (C) 2017 Przemyslaw Pawelczyk <przemoc@gmail.com>
##
## This script is licensed under the terms of the MIT license.
## https://opensource.org/licenses/MIT
#
# Traffic control - Make DNS requests delayed and low priority on Linux.
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 IFACE [DELAY [JITTER [CORRELATION]]]"
echo
echo "Example: $0 eth1 500ms 100ms"
exit 0
fi
IFACE=$1
shift
ip link show dev $IFACE >/dev/null || exit 1
tc qdisc del dev $IFACE root 2>/dev/null
if [ -z "$*" ] || [ "$1" = "off" ]; then
echo "Traffic control: Set default queueing discipline on $IFACE."
exit 0
fi
echo "Traffic control: Make DNS requests delayed and low priority on $IFACE."
tc qdisc add dev $IFACE root handle 1: \
prio bands 2 priomap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
tc qdisc add dev $IFACE parent 1:2 handle 53: \
netem delay "$@"
tc filter add dev $IFACE parent 1: \
protocol ip prio 1 u32 match ip dport 53 0xffff flowid 1:2