Skip to content

This is a web-based tool for simulating network quality. Ideal for use with software routers on Linux platform. It focuses on simulating weak network (poor network) conditions, with built-in scenario models(3G, 4G, Wi-Fi, Starlink, etc.) and combinations of parameters such as packet loss, delay, jitter, and bandwidth limitation, etc.

License

Notifications You must be signed in to change notification settings

stephenyin/NetHang

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

60 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

NetHang Logo

Network Quality Simulation Tool

Tests


πŸ“– Overview

NetHang is a web-based tool designed to simulate network quality, focusing on the diversity of last-mile network conditions. For modern internet applications and services with high real-time requirements, NetHang offers a stable, reentrant, customizable, and easily extensible network quality simulation system, helping to achieve low-latency and high-quality internet services.

πŸŽ₯ Video Tutorial


🎯 What Makes NetHang Different?

Unlike traditional network impairment tools that target backbone network quality between servers and switches, NetHang is optimized for:

  • Simulating network quality from user equipment (UE) to servers, typically traversing:
    • UE ↔ LAN (Wi-Fi or Wired) ↔ Routers ↔ ISP edge nodes ↔ APP servers
    • UE ↔ Cellular ↔ ISP edge nodes ↔ APP servers
    • UE ↔ Air interface ↔ Satellite ↔ APP servers
Add Path
  • The current network model is built and simplified based on existing network quality data modeling, while also supporting users to easily customize the network models they need for testing in YAML format. The following image shows the StarLink network simulation (Queuing changes every 20s - 30s caused by Satellite handover):
StarLink Simulation
  • NetHang clearly displays the differences in data traffic before and after simulation, as well as the state of the simulation conditions.
Manipulate Charts

✨ Features

Traffic Control & Shaping

  • βœ… Configurable traffic rules and models
  • βœ… Traffic rate limiting and shaping
  • βœ… Throttle queue depth control
Throttle Settings

Latency & Jitter Simulation

  • βœ… Network latency and latency variation (Jitter) simulation
  • βœ… Jitter simulation with and without reordering allowed
Latency Settings Latency Settings

Packet Loss Simulation

  • βœ… Packet loss with random and burst support
Loss Settings

Real-time Monitoring

  • βœ… Support for both uplink and downlink traffic control
  • βœ… Real-time traffic statistics display

πŸ“‹ Requirements

  • Python 3.8 or higher
  • Linux system with tc and iptables support
  • Root privileges for traffic control operations
  • Ubuntu 22.04 LTS (or similar Linux distribution)
  • At least TWO network interface cards (NICs)

βš™οΈ System Configuration

Before installing NetHang, you need to configure your Linux system as a software router. Follow the steps below to set up the required dependencies and network settings.

πŸ“¦ Dependencies and Permissions

Install the required packages:

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 is without errors, the permissions are set correctly. If not, you may need to reboot the machine.

πŸ”„ Enabling IP Forwarding

Step 1: Check Current IP Forwarding Status

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.

Step 2: Enable IP Forwarding

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

🌐 Configuring Network Interfaces

Step 1: List Network Interfaces

Identify your network interfaces using the ip command:

ip addr

You should see a list of interfaces like eth0, eth1, etc.

Step 2: Configure Network Interfaces

Edit the network configuration files for your interfaces. For example, to configure eth0 and eth1, 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

Step 3: Apply Network Configuration Changes

Apply the changes to network interfaces:

sudo systemctl restart networking

πŸ”€ Configuring NAT (Network Address Translation)

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.

πŸ“‘ Setting Up DHCP Server (Optional)

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.

Step 1: Install 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

Step 2: Configure 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;
}

Step 3: Start DHCP Server

Start the DHCP server:

sudo systemctl start isc-dhcp-server

Step 4: Enable DHCP Server at Boot

To ensure the DHCP server starts at boot:

sudo systemctl enable isc-dhcp-server

πŸš€ Installation

From PyPI (Recommended)

You can install NetHang from PyPI using the following command:

pip install nethang

From Source (For Developers)

You can also install NetHang from source by cloning the repository and running the following command:

git clone https://github.com/stephenyin/NetHang.git
cd NetHang
pip install .

πŸ“„ License

MIT License

Copyright (c) 2025 NetHang Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and adhere to the existing coding style.


πŸ‘₯ Authors

NetHang Contributors


πŸ™ Acknowledgments

  • Thanks to all contributors who have helped with the project
  • Inspired by various network traffic control tools and utilities

Made with ❀️ by the NetHang community

About

This is a web-based tool for simulating network quality. Ideal for use with software routers on Linux platform. It focuses on simulating weak network (poor network) conditions, with built-in scenario models(3G, 4G, Wi-Fi, Starlink, etc.) and combinations of parameters such as packet loss, delay, jitter, and bandwidth limitation, etc.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published