Again, starting writing something … Let’s begin with some easy stuff.
Days ago, I would like to limit my macOS network speed. In Linux, we can use tc
command to do that, but in macOS we will use dnctl
+pfctl
. For tc
usage, checkout with this post
1 |
|
Also remeber to reset this network speed control:1
2
3sudo dnctl -f flush
sudo pfctl -f /etc/pf.conf
sudo dnctl list
Here is a full list of function to be invoked in .bashrc / .bash_profile / .zshrc
: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
27speed_limit() {
local direction=${1-"up"}
# clear
sudo dnctl -f flush
sudo pfctl -f /etc/pf.conf
sudo pfctl -E
(cat /etc/pf.conf &&
echo 'dummynet-anchor "my_anchor"' &&
echo 'anchor "my_anchor"') | sudo pfctl -q -f -
cat <<EOF | sudo pfctl -q -a my_anchor -f -
no dummynet quick on lo0 all
dummynet out proto tcp from any to any pipe 1
EOF
if [[ "$direction" == "up" ]]; then
sudo dnctl -f flush
sudo pfctl -f /etc/pf.conf
sudo pfctl -E
sudo dnctl list
else
sudo dnctl pipe 1 config bw 4096byte/s
sudo pfctl -E
sudo dnctl list
fi
}