Skip to content

Commit fce8684

Browse files
committed
docs: update readme and add development
1 parent 9c8560b commit fce8684

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

DEVELOPMENT.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Development
2+
3+
This doc will guide you through testing ``dhcpd`` safely without impacting your main network. Deploying a DHCP server on your main network can cause conflicts with existing DHCP services (like the one provided by your router).
4+
5+
We'll set up an isolated test environment using linux network namespaces and virtual Ethernet interfaces.
6+
7+
8+
## Guide
9+
10+
create network namespaces for client and server
11+
12+
```bash
13+
sudo ip netns add server_ns
14+
sudo ip netns add client_ns
15+
```
16+
17+
create virtual ethernet pair to connect server and client namespace
18+
19+
```bash
20+
sudo ip link add veth-server type veth peer name veth-client
21+
```
22+
23+
assign interfaces to namespaces
24+
```bash
25+
sudo ip link set veth-server netns server_ns
26+
sudo ip link set veth-client netns client_ns
27+
```
28+
29+
configure server namespace
30+
31+
```bash
32+
sudo ip netns exec server_ns ip addr add 192.168.100.1/24 dev veth-server
33+
sudo ip netns exec server_ns ip link set dev veth-server up
34+
sudo ip netns exec server_ns ip link set dev lo up
35+
sudo ip netns exec server_ns ip route add 255.255.255.255 dev veth-server
36+
37+
```
38+
39+
40+
configure client namespace
41+
```bash
42+
sudo ip netns exec client_ns ip link set dev veth-client up
43+
sudo ip netns exec client_ns ip link set dev lo up
44+
```
45+
46+
update config to listen on ``veth server``
47+
48+
conf.yaml:
49+
```yaml
50+
server:
51+
ip_start: 192.168.100.10
52+
ip_end: 192.168.100.255
53+
subnet_mask: 255.255.255.0
54+
lease_time: 600
55+
gateway: 192.168.1.10
56+
server_ip: 192.168.1.10
57+
port: 67
58+
dns_servers:
59+
- 8.8.8.8
60+
- 8.8.4.4
61+
interface: en0
62+
lease_db_path: leases.db
63+
cleanup_expired_interval: 120
64+
logging:
65+
level: info
66+
metrics:
67+
enabled: true
68+
listen_address: '0.0.0.0:9100'
69+
```
70+
71+
run dhcpd in server namespace
72+
73+
```bash
74+
sudo ip netns exec server_ns ./dhcpd
75+
```
76+
ensure it's running and listening on ``veth-server``, you should see an output similar to this:
77+
78+
```
79+
INFO[2025-01-03T10:07:47+01:00] [INIT] Set to cleanup expired leases every 120 seconds
80+
INFO[2025-01-03T10:07:47+01:00] [INIT] Metrics server listening on :9100
81+
INFO[2025-01-03T10:07:47+01:00] [INIT] DHCP server listening on 0.0.0.0:67 (interface: veth-server, IP: 192.168.100.10)
82+
```
83+
84+
85+
run dhcp client in client namespace
86+
87+
```bash
88+
sudo ip netns exec client_ns dhclient -v veth-client
89+
```
90+
91+
verify ip assignment
92+
```bash
93+
sudo ip netns exec client_ns ip addr show dev veth-client
94+
```
95+
96+
you should see an IP assigned within the range specified in ``conf.yaml``
97+
98+
```bash
99+
3: veth-client@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
100+
link/ether ba:ad:c0:ff:ee:01 brd ff:ff:ff:ff:ff:ff
101+
inet 192.168.100.10/24 brd 192.168.100.255 scope global dynamic veth-client
102+
valid_lft 86396sec preferred_lft 86396sec
103+
```
104+
105+
cleanup
106+
107+
```bash
108+
sudo ip netns del server_ns
109+
sudo ip netns del client_ns
110+
sudo ip link delete veth-server
111+
```

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ bound to 192.168.100.92 -- renewal in 261 seconds.
5858
`dhcpd` also provides server and lease metrics, accessible at `:9100/metrics`. Additionally, a sample Grafana dashboard [JSON](https://github.com/umegbewe/dhcpd/blob/699c7546e35768876f2b3d40d43bfb46b5d5f612/grafana/%20dashboard.json) is available for visualizing these metrics."
5959

6060

61-
6261
<img src="https://github.com/umegbewe/dhcpd/blob/main/grafana/screenshot.png">
6362

6463
## Future work

0 commit comments

Comments
 (0)