DHCP issues

This commit is contained in:
Chris Frankland-Wright 2025-08-30 23:48:24 +01:00
parent 32e785bd88
commit 8903d6d006

View file

@ -261,8 +261,9 @@ if [ "$PKG_MANAGER" == "apt" ]; then
echo "✅ nodogsplash installed successfully." echo "✅ nodogsplash installed successfully."
# Disable the standalone hostapd service to let NetworkManager manage it. # Disable the standalone hostapd service to let NetworkManager manage it.
sudo systemctl disable hostapd # We are now using the classic hostapd service, so unmask it.
sudo systemctl mask hostapd sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl enable nodogsplash sudo systemctl enable nodogsplash
else else
echo "This script is designed for Debian-based systems like Raspberry Pi OS." echo "This script is designed for Debian-based systems like Raspberry Pi OS."
@ -274,41 +275,46 @@ fi
sudo systemctl stop hostapd || true sudo systemctl stop hostapd || true
sudo systemctl stop dnsmasq || true sudo systemctl stop dnsmasq || true
# Ensure NetworkManager is managing wlan0 by removing any conflicting configurations. # --- Configure networking for AP mode ---
# This is the critical fix for the "No suitable device" error.
echo "Ensuring NetworkManager is managing wlan0..."
sudo rm -f /etc/NetworkManager/conf.d/99-unmanaged-wlan0.conf
# Prevent NetworkManager from running its own dnsmasq instance or managing resolv.conf. # Tell NetworkManager to ignore wlan0 completely to prevent conflicts.
# This allows our standalone dnsmasq service to function without conflict. echo "Configuring NetworkManager to ignore wlan0..."
echo "Configuring NetworkManager to not manage DNS..." sudo tee /etc/NetworkManager/conf.d/99-unmanaged-wlan0.conf > /dev/null <<EOF
sudo tee /etc/NetworkManager/conf.d/99-disable-dns.conf > /dev/null <<EOF [keyfile]
[main] unmanaged-devices=interface-name:wlan0
dns=none
EOF EOF
# Also remove the DNS disabling config as it's no longer relevant for this method
sudo rm -f /etc/NetworkManager/conf.d/99-disable-dns.conf
sudo systemctl reload NetworkManager sudo systemctl reload NetworkManager
# Configure static IP for wlan0 using NetworkManager (nmcli) # Configure a static IP for wlan0 using dhcpcd.
echo "Configuring static IP for wlan0 using NetworkManager..." echo "Configuring static IP for wlan0 via dhcpcd..."
# Ensure dhcpcd is installed
sudo apt install -y dhcpcd5
# Add our static IP config, being careful not to overwrite existing settings
sudo tee -a /etc/dhcpcd.conf > /dev/null <<EOF
# Define the connection name # Static IP configuration for Hachi Time AP
CON_NAME="Fetch-Hachi-AP" interface wlan0
static ip_address=10.0.252.1/24
nohook wpa_supplicant
EOF
# If a connection with this name already exists, delete it to ensure a clean slate. # Configure hostapd for the Access Point
if nmcli c show --active | grep -q "$CON_NAME"; then echo "Configuring hostapd..."
sudo nmcli c down "$CON_NAME" || true sudo tee /etc/hostapd/hostapd.conf > /dev/null <<EOF
fi interface=wlan0
if nmcli c show | grep -q "$CON_NAME"; then driver=nl80211
echo "Deleting existing '$CON_NAME' connection profile..." ssid=Fetch-Hachi
sudo nmcli c delete "$CON_NAME" || true hw_mode=g
fi channel=7
wmm_enabled=0
# Create a new connection profile for the Access Point with a static IP. macaddr_acl=0
echo "Creating new '$CON_NAME' connection profile..." auth_algs=1
sudo nmcli c add type wifi ifname wlan0 con-name "$CON_NAME" autoconnect yes ssid "Fetch-Hachi" ignore_broadcast_ssid=0
sudo nmcli c modify "$CON_NAME" 802-11-wireless.mode ap 802-11-wireless.band bg EOF
sudo nmcli c modify "$CON_NAME" ipv4.method manual ipv4.addresses 10.0.252.1/24 # Point the hostapd service to the new config file.
sudo sed -i 's|#DAEMON_CONF=""|DAEMON_CONF="/etc/hostapd/hostapd.conf"|' /etc/default/hostapd
# Configure dnsmasq for DHCP # Configure dnsmasq for DHCP
echo "Configuring dnsmasq..." echo "Configuring dnsmasq..."
@ -344,8 +350,10 @@ EOF
# Restart services in the correct order and add delays to prevent race conditions # Restart services in the correct order and add delays to prevent race conditions
echo "Restarting services..." echo "Restarting services..."
# Bring up the new AP connection using nmcli # Restart dhcpcd to apply the static IP
sudo nmcli c up "$CON_NAME" sudo systemctl restart dhcpcd
# Restart hostapd to create the access point
sudo systemctl restart hostapd
# Wait for the interface to come up and get the IP address # Wait for the interface to come up and get the IP address
echo "Waiting for wlan0 to be configured..." echo "Waiting for wlan0 to be configured..."
@ -382,7 +390,7 @@ if [ "$IP_CHECK" == "10.0.252.1" ]; then
fi fi
else else
echo "❌ Error: wlan0 failed to get the static IP 10.0.252.1. Found: '$IP_CHECK'." echo "❌ Error: wlan0 failed to get the static IP 10.0.252.1. Found: '$IP_CHECK'."
echo "Please check 'sudo nmcli c show \"$CON_NAME\"' and 'ip addr show wlan0'." echo "Please check 'sudo systemctl status hostapd' and 'sudo systemctl status dhcpcd'."
exit 1 exit 1
fi fi