A lightweight virtual router/firewall for small labs, built with iptables and ISC-DHCP-Server on Debian 12 “bookworm”.
It routes between a DHCP-fed WAN (eth0) and a static-IP LAN (eth1, 192.168.50.0/24).
- IPv4 routing & NAT (MASQUERADE)
- Stateful firewall with sensible defaults
- Basic hardening – SYN-cookies, rp-filter, …
- Rate-limited SSH exposure on both WAN & LAN
- Port-forward:
WAN:2222 → 192.168.50.254:22 - DHCP server (12 h leases, 192.168.50.1-243)
- Optional extras – fail2ban, unattended-upgrades
| File | Purpose |
|---|---|
/etc/network/interfaces |
Interface definitions (WAN = DHCP, LAN = static) |
/etc/sysctl.d/99-router.conf |
Kernel routing & hardening tweaks |
/usr/local/sbin/fw.sh |
Complete iptables ruleset (run once, then persisted) |
/etc/iptables/rules.v4 |
Saved rules loaded by netfilter-persistent |
/etc/dhcp/dhcpd.conf |
DHCP scope & options |
/etc/default/isc-dhcp-server |
Tells DHCP daemon to bind to eth1 |
/etc/fail2ban/jail.local |
(Optional) local overrides |
maintenance.md |
Routine tasks & health checks |
sudo apt update
sudo DEBIAN_FRONTEND=noninteractive apt install -y \
iptables iptables-persistent isc-dhcp-server \
rsyslog logrotate fail2ban unattended-upgrades \
net-tools iproute2 dnsutils curl vim less
sudo cp interfaces /etc/network/interfaces
sudo cp 99-router.conf /etc/sysctl.d/
sudo cp fw.sh /usr/local/sbin/fw.sh && sudo chmod +x /usr/local/sbin/fw.sh
sudo cp dhcpd.conf /etc/dhcp/dhcpd.conf
sudo cp isc-dhcp-server /etc/default/isc-dhcp-server
sudo sysctl --system
sudo /usr/local/sbin/fw.sh
sudo sh -c 'iptables-save > /etc/iptables/rules.v4'
sudo systemctl enable --now netfilter-persistent isc-dhcp-server fail2ban
- LAN host should obtain
192.168.50.x(1-243) with gateway/DNS192.168.50.254. ping 1.1.1.1anddig debian.orgfrom the LAN should succeed.- From outside,
ssh -p 2222 <WAN_IP>should land on the router’s local SSH. - Check counters:
sudo iptables -nvL --line-numbers.
| Symptom | Fix |
|---|---|
| LAN client gets no DHCP | sudo journalctl -u isc-dhcp-server – ensure eth1 up & scope correct. |
| No internet on LAN | iptables -t nat -L POSTROUTING -nv – is MASQUERADE rule present? |
| SSH brute-force spam in logs | Verify fail2ban running: sudo fail2ban-client status sshd. |
| Over-flowing conntrack table | Tune nf_conntrack_max in 99-router.conf (see maintenance.md). |
Happy routing!