Skip to content

Instantly share code, notes, and snippets.

@przemoc przemoc/tc-delaydnsreqs.sh
Last active Apr 16, 2018

Embed
What would you like to do?
Traffic control - Make DNS requests delayed and low priority on Linux
#!/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
@naikrovek

This comment has been minimized.

Copy link

naikrovek commented Sep 15, 2017

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.

@przemoc

This comment has been minimized.

Copy link
Owner Author

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.

@przemoc

This comment has been minimized.

Copy link
Owner Author

przemoc commented Feb 6, 2018

commit a11585efc32ce26b8b51dcc5ba4eb5e9034d2dd3
Author: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date:   2018-02-06 14:59:01 +0100

    tc-delaydnsreqs.sh: Add copyright notice and MIT license notice.

commit 84b514c728bc3bbf49158393dad3d5ba926557ea
Author: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date:   2018-02-06 14:59:47 +0100

    Add SPDX License Identifier.

    The Software Package Data Exchange (SPDX) is a good initiative, it has
    matured over time and deserves accelerated adoption in open-source.

    https://spdx.org/learn
    https://spdx.org/using-spdx
    https://spdx.org/license-list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.