Transform a Debian PC or Raspberry Pi into a fully functional Wi-Fi router with DHCP, DNS, and NAT capabilities.
- Automatic interface detection: Finds Wi-Fi adapters supporting AP mode and connected Ethernet interfaces
- Complete router functionality: Hostapd (access point), dnsmasq (DHCP/DNS), iptables (NAT/forwarding)
- Persistent or temporary mode: Choose between one-time setup or automatic startup on boot
- Systemd service integration: Single service manages all components in correct order
- Resource optimization: Optional TTY-only mode to disable GUI and save resources
- Easy cleanup: Remove all configurations and restore original state
- Debian/Ubuntu/Raspberry Pi OS (systemd-based)
- Root privileges
- Ethernet connection with internet access (WAN)
- Wi-Fi adapter supporting AP mode (nl80211 driver)
- NetworkManager installed
iw list | grep -A 10 "Supported interface modes"
# Look for "AP" in the output# Clone repository
git clone https://github.com/StenguyzCSGO/Debian-to-router.git
cd Debian-to-router
# Make executable
chmod +x router.sh
# Run as root
sudo ./router.shThe script will prompt you for:
- Wi-Fi network name (SSID): Your access point name
- Password: Minimum 8 characters, WPA2-PSK encryption
- Persistent mode: Enable automatic startup on boot
- TTY mode (if persistent): Disable graphical interface to save resources
After successful setup, the script is installed as:
sudo router-modeMonitor services:
systemctl status router-mode.service
systemctl status hostapd dnsmasq
journalctl -u router-mode -fsudo router-mode
# Answer 'y' to cleanup promptThis removes all configurations, restores NetworkManager control, resets iptables, and re-enables GUI if disabled.
| Setting | Value |
|---|---|
| LAN Gateway | 192.168.50.1 |
| LAN Subnet | 192.168.50.0/24 |
| DHCP Range | 192.168.50.50 - 192.168.50.150 |
| DNS Servers | 1.1.1.1, 8.8.8.8 |
| Wi-Fi Channel | 7 (2.4 GHz) |
| Encryption | WPA2-PSK |
- Script copies itself to
/usr/local/sbin/router-mode - Creates
router-mode.servicesystemd unit - Service starts after network and NetworkManager
- Configuration saved to
/etc/router-mode/config - On boot: loads config, detects interfaces, starts hostapd/dnsmasq
- Wi-Fi interface configured with static IP (192.168.50.1/24)
- NetworkManager releases control of Wi-Fi interface
- IPv4 forwarding enabled via sysctl
- NAT configured with iptables MASQUERADE
- Hostapd creates WPA2 access point
- Dnsmasq provides DHCP and DNS forwarding
/usr/local/sbin/router-mode # Installed script
/etc/router-mode/config # Saved configuration
/etc/systemd/system/router-mode.service # Systemd service
/etc/hostapd/hostapd.conf # Access point config
/etc/dnsmasq.d/router.conf # DHCP/DNS config
/etc/NetworkManager/conf.d/ROUTER_MODE.conf
/etc/network/interfaces.d/ROUTER_MODE.conf
/etc/sysctl.d/99-router-ipforward.conf
When enabled, the system boots to text console (TTY) instead of graphical interface:
Switch between TTY consoles:
Ctrl+Alt+F1toF6: Access TTY1-6Alt+F1toF6: Switch TTY (when already in console)
Temporarily start GUI:
sudo systemctl start gdm3 # or lightdm/sddmPermanently re-enable GUI:
sudo systemctl set-default graphical.target
sudo rebootService won't start:
journalctl -u router-mode -n 50
systemctl status hostapd --no-pagerWi-Fi adapter not detected:
iw list # Check AP mode support
nmcli device # Verify interface detectionNo internet on connected devices:
# Check NAT rules
sudo iptables -t nat -L -n -v
# Check IP forwarding
cat /proc/sys/net/ipv4/ip_forward # Should be 1
# Verify WAN interface has internet
ping -I eth0 8.8.8.8Interface blocked:
rfkill list
rfkill unblock wifi- Use strong WPA2 passwords (minimum 8 characters)
- Configuration file
/etc/router-mode/configis chmod 600 (root only) - Consider firewall rules for production deployments
- Default configuration accepts all forwarded traffic (adjust iptables for restrictions)
Edit /etc/hostapd/hostapd.conf for:
- Channel selection (
channel=7) - Wi-Fi band (
hw_mode=gfor 2.4GHz,hw_mode=afor 5GHz) - Country code (
country_code=US) - Hidden SSID (
ignore_broadcast_ssid=1)
Edit /etc/dnsmasq.d/router.conf for:
- DHCP lease time (
12h) - DNS servers (
server=1.1.1.1) - Static IP assignments
- Custom domain name
Restart services after changes:
sudo systemctl restart router-mode.serviceMIT License - See LICENSE file for details
Pull requests welcome. For major changes, please open an issue first.