Simulating WAN links used were once a difficult process. I would load FreeBSD with a dummynet driver and play with the settings to tweak where I needed it for the activity. OpenBSD with ALTQ made this a step simpler with the ease of bridging adapters. On a recent project for Spec Ops Technology, I needed to simulate a WAN with latency, loss, and randomness.

I decided I needed to dig more into the netem work included in most recent linux distributions. Netem has matured to the point of being a very potent utility for setting up quick testbeds. Additionally with most any modern Linux distro you are online in minutes. I will post a very quick script to get you online:

#!/bin/bash

export iface0=eth0

export iface1=enp0s29u1u1 (eth1 on most installations)

ifconfig $iface0 0.0.0.0 up

ifconfig $iface1 0.0.0.0 up

brctladdbr br0

brctlsetfd br0 0

brctladdif br0 $iface0

brctladdif br0 $iface1

ifconfig br0 up

 

for f in /proc/sys/net/bridge/bridge-*; do echo 0 > $f; done

 

tc qdisc add dev $iface0 root netem delay 100ms 10ms 25% loss 0.2%

tc qdisc add dev $iface1 root netem delay 100ms 10ms 25% loss 0.2%

 

As you can see two adapters and root gives you an easy setup. An explanation of the script are below:

  • IFace0 and IFace1 are your two adapters you wish to bridge. These are commonly ETH0 and ETH1 depending on your distro. NOTE: Archlinux and Gentoo may not auto-populate these udev renaming rules
  • brctlsetfd br0 0 configures forwarding delay to 0
  • tc qdisc lines define 100ms delay with +/- 10ms in 25% of the packets with 0.2% packet loss. You can change these parameters on the fly by using the tc qdisc change in place of add

There you have it! Very simple, quick, and built-in to your linux desktop. There are a plethora of options so be sure to checkout the netem link below for more parameters:

http://www.linuxfoundation.org/collaborate/workgroups/networking/netem

Tagged with:
 

Comments are closed.

Set your Twitter account name in your settings to use the TwitterBar Section.