Skip to content

Instantly share code, notes, and snippets.

@Areontar
Forked from mefellows/tools.md
Created September 28, 2020 19:09
Show Gist options
  • Save Areontar/bfdad44c423b255fa4008de6f494aef7 to your computer and use it in GitHub Desktop.
Save Areontar/bfdad44c423b255fa4008de6f494aef7 to your computer and use it in GitHub Desktop.
Networking Tools - Cheat Sheet

*nix Networking Tools Cheat Sheet

## Network Performance

iperf (all)

Setup the server:

iperf -s

Run the client against the server for 7 seconds:

iperf -c localhost -t 7

You should get a throughput in (GMk)bits/sec

## Packet and Firewall filtering

### pfctl + dnctl (MacOSX Yosemite+)

List Rules

sudo dnctl list
sudo pfctl -sa -v -v

#### Shape traffic

(cat /etc/pf.conf && echo "dummynet-anchor \"mop\"" && echo "anchor \"mop\"") | sudo pfctl -f -
echo "dummynet in quick proto tcp from any to any port 5001 pipe 1" | sudo pfctl -a mop -f -
sudo dnctl pipe 1 config bw 1Mbit/s

Observe traffic is now shaped to 100Mbit/s:

iperf  -s -D # Run as Daemon (-D)
iperf -c localhost -t 5 

Client connecting to localhost, TCP port 5001 TCP window size: 144 KByte (default)

[ 5] local 127.0.0.1 port 59573 connected with 127.0.0.1 port 5001 [ ID] Interval Transfer Bandwidth [ 5] 0.0- 5.0 sec 60.5 MBytes 101 Mbits/sec

#### Delay

Delays packet transmission by 20ms:

sudo dnctl pipe 1 config delay 20

#### Simulate Packet Loss

Drop 35% of packets on the pipe:

sudo dnctl pipe 1 config plr 0.35

No error

sudo dnctl pipe 1 config plr .35
sudo dnctl pipe 1 config noerror

Don't report the error back to the sender - simulate loss at a remote router

#### Undo

To undo whatever mess you've created back to the default...

sudo dnctl -q flush
sudo pfctl -f /etc/pf.conf

### ipfw (FreeBSD/OpenBSD)

### iptables (Linux)

## Links

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