-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelay.sh
More file actions
36 lines (29 loc) · 982 Bytes
/
Copy pathdelay.sh
File metadata and controls
36 lines (29 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$#" -ne 3 ]; then
echo "Usage: $0 <interface> <ip-address> <delay>"
echo "Example: $0 eth0 192.168.1.1 10ms"
echo "--off(-o) - reset delay"
exit 1
fi
if [ "$1" = "-o" ] || [ "$1" = "--off" ]; then
tc qdisc del dev eth0 root
echo "Delay reset"
exit 0
fi
interface="$1"
ip_address="$2"
delay="$3"
if ! ip link show "$interface" &> /dev/null; then
echo "Error: Invalid interface name $interface"
exit 1
fi
if ! ping -c 1 -w 1 "$ip_address" &> /dev/null; then
echo "Error: Invalid IP address $ip_address"
exit 1
fi
tc qdisc del dev "$interface" root
tc qdisc add dev "$interface" root handle 1: htb
tc class add dev "$interface" parent 1: classid 1:1 htb rate 100mbit
tc filter add dev "$interface" parent 1: protocol ip prio 1 u32 flowid 1:1 match ip dst "$ip_address"
tc qdisc add dev "$interface" parent 1:1 handle 10: netem delay "$delay"
echo "For $interface $ip_address set delay to $delay"