Turn an old PC into a network bandwidth and latency simulator

With a second network interface card (NIC), we can turn an old PC into a dedicated box to simulate lower bandwidth, latency, packet loss, and packet corruption you might experience at remote sites. This is immensely useful for training or testing without requiring real travel. Many servers come with multiple built-in NICs, but most desktop PCs only come with a single NIC so you may need to install a second NIC via expansion card (internal) or USB-to-ethernet adapter.

COMPUTER <–> SIMULATOR <–> NETWORK

This is an example configuration, though you could easily have a switch on the back side and have multiple computers on the simulated up-link. In this configuration, the computers/devices would be sharing the bandwidth limit.

Step 1

Install Debian Linux on the PC without GUI (ie Server only) as the GUI network tools seemed to interfere with my ability to configure the NICs and bridge properly. I used Debian 8.5 at the time of this writing.

Step 2

Verify that the PC recognizes both NICs.

Run the following command, and verify you see two NICs (typically the first two would be “eth0″and “eth1”). NOTE: the dollar sign ($) represents that this is a command that should be run in the Linux shell (BASH, etc), and you should type (or copy/paste) the command starting after the dollar sign.

$ /sbin/ifconfig | grep eth

You should see something like the output below, but with different hardware (MAC) addresses. If you do not see at least two NICs listed, your second network card or adapter may not be recognized or supported out of the box and you may have to do further research to get it working or choose different hardware.

$ /sbin/ifconfig | grep eth
eth0 Link encap:Ethernet HWaddr f8:b1:56:be:c9:d6
eth1 Link encap:Ethernet HWaddr 00:23:57:6c:03:95

Step 3

Install updates and required software packages.

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install bridge-utils ethtool git

Step 4

Configure the network to bridge the two NICs.

With your favorite text editor (vi, nano, etc), edit /etc/network/interfaces as follows:

auto lo
iface lo inet loopback

auto eth0
auto eth1

auto br0
iface br0 inet dhcp
    bridge_ports eth0 eth1
    bridge_maxwait 0

iface br0 inet6 auto

Restart the network

$ sudo systemctl restart networking

Verify network configuration and connectivity. The below command should show eth0 and eth1 without an IP, and (typically) br0 with an IP.

$ /sbin/ifconfig

If you still see an IP on eth0 or eth1, run the following command (replacing ETHX with eth0 or eth1).

sudo ifconfig ETHX 0.0.0.0

Also verify you still have external connectivity via your bridge via ping, ssh, or similar.

Step 5

Install SimSat to make configuration easier. Behind the scenes, SimSat simply converts your configuration into arguments for the Traffic Control (tc) command.

$ cd /usr/local && sudo git clone https://github.com/akhepcat/SimSat.git

Step 6

Configure and verify configuration of SimSat.

The below command will display your bridge, and which NICs are a part of this bridge. Your output should be similar. If you don’t see both NICs listed under “Current bridge interface(s):” but do see one or both under “Available interface(s):”, run “sudo /usr/local/SimSat/BridgeMgr add” as required until you get the correct output.

$ sudo /usr/local/SimSat/BridgeMgr status

Current bridge(s): 1 – br0
Current bridge interface(s): 2 – eth0 eth1
Available interface(s): 0 –

To configure SimSat itself, you will need to edit the script at /usr/local/SimSat/SimSat with your preferred editor. You should only need to change lines 6-9 as required. NOTE: The delays and loss are in each direction for each NIC. Traffic will come in one NIC to the bridge, then out the bridge through the other NIC, so DELAY, LOSS, and CORRUPT are each cumulative. Example: If you want to emulate a 600 ms delay, you would configure the script to use 300ms (300ms in to the bridge, and another 300ms out of the bridge equals 600ms total to pass through the bridge).

DELAY="delay 10ms 10ms distribution normal" # delay across both interfaces is 600ms +/1 20ms with "delay 300ms 10ms" default
LOSS="loss 0.000001% 25%"
CORRUPT="corrupt 0.000001%"
RATE="1000mbit"

To switch from a generic bridge running at full speed to the simulated speed/etc, you would run the following command.

$ sudo /usr/local/SimSat/SimSat start

NOTE: You may see errors like below. In my testing, this error can be safely ignored and does not seem to affect functionality.

RTNETLINK answers: Invalid argument
We have an error talking to the kernel

To stop the simulation and return to running a generic bridge at full speed, run the following command:

$ sudo /usr/local/SimSat/SimSat stop

NOTE: To change settings “live”, you must change the configurations in the file, run the stop command, then run the start command. Running the start command while still active does not always update properly.

Step 7

Optional – Configure persistence

If you want to keep this as a dedicated box/appliance, you will want to add the following line to /etc/rc.local right before the “exit 0” line.

/usr/local/SimSat/SimSat start