Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Traffic control - Make DNS requests delayed and low priority on Linux
#!/bin/sh
## Traffic control - Make DNS requests delayed and low priority on Linux.
## Author: Przemyslaw Pawelczyk
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

I haven't used this, but right away this seems like a great way to demonstrate just how influential DNS performance can be to a web browsing overall. I've had difficulty explaining just how many DNS requests are made per page load, and conveying just how important DNS performance can be. This would be a wonderful way to demonstrate it. Starred.

Owner

przemoc commented Sep 24, 2017

@naikrovek Yeah, slow or malfunctioning DNS can literally kill your web experience. It was meant to help test/debug software that may expect DNS replies within short timeframe, which is not always the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment