NetHang is a web-based network quality simulation tool that allows you to create and manage network paths between LAN and WAN interfaces. Ideal for use with software routers on Linux platform. It focuses on simulating weak network (poor network) conditions, with built-in scenario models(Edge, 3G, 4G, Wi-Fi, Starlink, etc.) and combinations of parameters such as packet loss, delay, jitter, and bandwidth limitation, etc. It helps you simulate various network conditions and monitor their effects on traffic.
How NetHang looks like:
In simple terms, NetHang needs to run on a Linux-based software router. If you already have such a software router device or are familiar with how to set up the environment, it will be very convenient.
If not, please follow the instructions below step-by-step to build one. Depending on your hardware and network environment, you may encounter different issues, which we can discuss and troubleshoot on GitHub.
A Ubuntu 22.04 LTS server (or desktop) with at least TWO network interface cards (NICs) is required.
To install the required packages, run the following command:
sudo apt update; sudo apt install iproute2 iptables libcap2-bin
Check command paths:
which tc; which iptables
They are typically located in /sbin/tc
and
/sbin/iptables
(or /usr/sbin/tc
and
/usr/sbin/iptables
).
Grant the CAP_NET_ADMIN
capability, which is required for tc and
iptables:
sudo setcap cap_net_admin+ep /usr/sbin/tc; sudo setcap cap_net_admin+ep /usr/sbin/xtables-nft-multi
Verify the permissions:
iptables -L
tc qdisc add dev lo root netem delay 1ms;tc qdisc del dev lo root
If the output are without errors, the permissions are set correctly.
If not, you may need to reboot the machine.
Before proceeding, check whether IP forwarding is currently enabled on your Ubuntu machine:
cat /proc/sys/net/ipv4/ip_forward
If the output is 0, IP forwarding is disabled. If it's 1, it's already enabled.
To enable IP forwarding temporarily (valid until the next reboot), run:
sudo sysctl -w net.ipv4.ip_forward=1
To make the change permanent, edit the /etc/sysctl.conf
file and
uncomment or add the line:
net.ipv4.ip_forward=1
Then, apply the changes:
sudo sysctl -p /etc/sysctl.conf
Identify your network interfaces using the ip command:
ip addr
You should see a list of interfaces like eth0, eth1, etc.
Edit the network configuration files for your interfaces. For example, to
configure eth0 and eth1, you'd edit /etc/network/interfaces
:
sudo vi /etc/network/interfaces
Here's a sample configuration for eth0 and eth1:
# eth0 - Internet-facing interface
auto eth0
iface eth0 inet dhcp
# eth1 - Internal LAN interface
auto eth1
iface eth1 inet static
address 192.168.1.1
netmask 255.255.255.0
Apply the changes to network interfaces:
sudo systemctl restart networking
To enable NAT for outbound traffic from your LAN, use iptables:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Make the change permanent by installing iptables-persistent:
sudo apt update
sudo apt install iptables-persistent
Follow the prompts to save the current rules.
This step is optional. If you want to use DHCP to assign IP addresses to devices on the LAN, you can configure the DHCP server.
If you want your Ubuntu router to assign IP addresses to devices on the LAN, install the DHCP server software:
sudo apt update
sudo apt install isc-dhcp-server
Edit the DHCP server configuration file:
sudo vi /etc/dhcp/dhcpd.conf
Here's a sample configuration:
subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.50;
option routers 192.168.1.1;
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
Start the DHCP server:
sudo systemctl start isc-dhcp-server
To ensure the DHCP server starts at boot:
sudo systemctl enable isc-dhcp-server
You can install NetHang from PyPI using the following command:
pip install nethang
You can also install NetHang from source by cloning the repository and running the following command:
pip install .
Starting NetHang is very simple. Just run the following command:
/path/to/nethang
NetHang will running on port 0.0.0.0:9527 by default. You can access the website by any browser.
You can login with the default username and password: admin
.
Then you can start to use NetHang.
Pre-configured network models that simulate common network conditions.
Configure specific network parameters:
A path represents a connection between your User-Equipment (UE) and the Application Services. Each path can be configured with:
TCP, UDP, or IP
Source and destination IP addresses
Port numbers (for TCP and UDP)
Models are pre-configured network paths that simulate common network conditions.
You can customize the network settings for each path.
The application provides real-time monitoring of network conditions through three charts:
Shows the bit rate for both uplink and downlink traffic.
Displays the number of packets in the queue.
Shows the packet loss rate over time.
More models to choose from.
Debian, OpenWRT, etc.
Support recording statistics to a file or database.
Frame overhead size, Jitter distribution, Packet loss distribution, Rate limit burst size & ceil rate. etc.
NetHang is a tool for simulating network conditions in a controlled environment. It allows you to test your network applications under various network conditions.