Skip to content

Commit 0a5f5d0

Browse files
committed
Add System Configuration part in README.md
1 parent 6f29262 commit 0a5f5d0

1 file changed

Lines changed: 181 additions & 0 deletions

File tree

README.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,187 @@ Unlike traditional network impairment tools that target backbone network quality
9292
- Python **3.8** or higher
9393
- Linux system with `tc` and `iptables` support
9494
- Root privileges for traffic control operations
95+
- Ubuntu 22.04 LTS (or similar Linux distribution)
96+
- At least **TWO** network interface cards (NICs)
97+
98+
---
99+
100+
## ⚙️ System Configuration
101+
102+
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.
103+
104+
### 📦 Dependencies and Permissions
105+
106+
Install the required packages:
107+
108+
```bash
109+
sudo apt update
110+
sudo apt install iproute2 iptables libcap2-bin
111+
```
112+
113+
Check command paths:
114+
115+
```bash
116+
which tc
117+
which iptables
118+
```
119+
120+
They are typically located in `/sbin/tc` and `/sbin/iptables` (or `/usr/sbin/tc` and `/usr/sbin/iptables`).
121+
122+
Grant the `CAP_NET_ADMIN` capability, which is required for `tc` and `iptables`:
123+
124+
```bash
125+
sudo setcap cap_net_admin+ep /usr/sbin/tc
126+
sudo setcap cap_net_admin+ep /usr/sbin/xtables-nft-multi
127+
```
128+
129+
Verify the permissions:
130+
131+
```bash
132+
iptables -L
133+
tc qdisc add dev lo root netem delay 1ms
134+
tc qdisc del dev lo root
135+
```
136+
137+
If the output is without errors, the permissions are set correctly. If not, you may need to reboot the machine.
138+
139+
### 🔄 Enabling IP Forwarding
140+
141+
**Step 1: Check Current IP Forwarding Status**
142+
143+
Before proceeding, check whether IP forwarding is currently enabled on your Ubuntu machine:
144+
145+
```bash
146+
cat /proc/sys/net/ipv4/ip_forward
147+
```
148+
149+
If the output is `0`, IP forwarding is disabled. If it's `1`, it's already enabled.
150+
151+
**Step 2: Enable IP Forwarding**
152+
153+
To enable IP forwarding temporarily (valid until the next reboot), run:
154+
155+
```bash
156+
sudo sysctl -w net.ipv4.ip_forward=1
157+
```
158+
159+
To make the change permanent, edit the `/etc/sysctl.conf` file and uncomment or add the line:
160+
161+
```bash
162+
net.ipv4.ip_forward=1
163+
```
164+
165+
Then, apply the changes:
166+
167+
```bash
168+
sudo sysctl -p /etc/sysctl.conf
169+
```
170+
171+
### 🌐 Configuring Network Interfaces
172+
173+
**Step 1: List Network Interfaces**
174+
175+
Identify your network interfaces using the `ip` command:
176+
177+
```bash
178+
ip addr
179+
```
180+
181+
You should see a list of interfaces like `eth0`, `eth1`, etc.
182+
183+
**Step 2: Configure Network Interfaces**
184+
185+
Edit the network configuration files for your interfaces. For example, to configure `eth0` and `eth1`, edit `/etc/network/interfaces`:
186+
187+
```bash
188+
sudo vi /etc/network/interfaces
189+
```
190+
191+
Here's a sample configuration for `eth0` and `eth1`:
192+
193+
```bash
194+
# eth0 - Internet-facing interface
195+
auto eth0
196+
iface eth0 inet dhcp
197+
198+
# eth1 - Internal LAN interface
199+
auto eth1
200+
iface eth1 inet static
201+
address 192.168.1.1
202+
netmask 255.255.255.0
203+
```
204+
205+
**Step 3: Apply Network Configuration Changes**
206+
207+
Apply the changes to network interfaces:
208+
209+
```bash
210+
sudo systemctl restart networking
211+
```
212+
213+
### 🔀 Configuring NAT (Network Address Translation)
214+
215+
To enable NAT for outbound traffic from your LAN, use `iptables`:
216+
217+
```bash
218+
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
219+
```
220+
221+
Make the change permanent by installing `iptables-persistent`:
222+
223+
```bash
224+
sudo apt update
225+
sudo apt install iptables-persistent
226+
```
227+
228+
Follow the prompts to save the current rules.
229+
230+
### 📡 Setting Up DHCP Server (Optional)
231+
232+
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.
233+
234+
**Step 1: Install DHCP Server**
235+
236+
If you want your Ubuntu router to assign IP addresses to devices on the LAN, install the DHCP server software:
237+
238+
```bash
239+
sudo apt update
240+
sudo apt install isc-dhcp-server
241+
```
242+
243+
**Step 2: Configure DHCP Server**
244+
245+
Edit the DHCP server configuration file:
246+
247+
```bash
248+
sudo vi /etc/dhcp/dhcpd.conf
249+
```
250+
251+
Here's a sample configuration:
252+
253+
```bash
254+
subnet 192.168.1.0 netmask 255.255.255.0 {
255+
range 192.168.1.10 192.168.1.50;
256+
option routers 192.168.1.1;
257+
option domain-name-servers 8.8.8.8, 8.8.4.4;
258+
}
259+
```
260+
261+
**Step 3: Start DHCP Server**
262+
263+
Start the DHCP server:
264+
265+
```bash
266+
sudo systemctl start isc-dhcp-server
267+
```
268+
269+
**Step 4: Enable DHCP Server at Boot**
270+
271+
To ensure the DHCP server starts at boot:
272+
273+
```bash
274+
sudo systemctl enable isc-dhcp-server
275+
```
95276

96277
---
97278

0 commit comments

Comments
 (0)