Skip to content

Instantly share code, notes, and snippets.

@Cdaprod
Created January 25, 2024 22:46
Show Gist options
  • Save Cdaprod/c3eb1a65246625349c4ceed6e4e4135b to your computer and use it in GitHub Desktop.
Save Cdaprod/c3eb1a65246625349c4ceed6e4e4135b to your computer and use it in GitHub Desktop.
To make your Raspberry Pi Zero 2 W broadcast a `hostapd` network upon powering on, you'll need to install and configure `hostapd` and `dnsmasq`, and set up a static IP for the wireless interface. Here's a detailed guide on how to achieve this:

To make your Raspberry Pi Zero 2 W broadcast a hostapd network upon powering on, you'll need to install and configure hostapd and dnsmasq, and set up a static IP for the wireless interface. Here's a detailed guide on how to achieve this:

Task Creation Chain

  1. Install Necessary Packages: Install hostapd and dnsmasq.
  2. Configure Static IP for WLAN: Set a static IP for the wireless interface.
  3. Configure Hostapd: Set up the access point details.
  4. Configure Dnsmasq: Set up the DHCP server.
  5. Enable Services on Boot: Ensure hostapd and dnsmasq start on boot.

Task Prioritization Chain

  1. Install Necessary Packages
  2. Configure Static IP for WLAN
  3. Configure Hostapd
  4. Configure Dnsmasq
  5. Enable Services on Boot

Execution Chain

1. Install Necessary Packages

  • Commands:
    sudo apt update
    sudo apt install hostapd dnsmasq
    sudo systemctl stop hostapd
    sudo systemctl stop dnsmasq

2. Configure Static IP for WLAN

  • Edit dhcpcd Configuration:
    • Open /etc/dhcpcd.conf and add the following:
      interface wlan0
      static ip_address=192.168.50.1/24
      nohook wpa_supplicant
    • Restart the dhcpcd service:
      sudo service dhcpcd restart

3. Configure Hostapd

  • Create Hostapd Configuration:

    • Create /etc/hostapd/hostapd.conf with the following contents (adjust SSID and passphrase):
      interface=wlan0
      driver=nl80211
      ssid=YourNetworkSSID
      hw_mode=g
      channel=7
      wmm_enabled=0
      macaddr_acl=0
      auth_algs=1
      ignore_broadcast_ssid=0
      wpa=2
      wpa_passphrase=YourPassword
      wpa_key_mgmt=WPA-PSK
      wpa_pairwise=TKIP
      rsn_pairwise=CCMP
  • Point to the Configuration File:

    • Edit /etc/default/hostapd and add:
      DAEMON_CONF="/etc/hostapd/hostapd.conf"

4. Configure Dnsmasq

  • Backup Existing Dnsmasq Configuration:

    • sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
  • Create New Configuration:

    • Edit /etc/dnsmasq.conf with:
      interface=wlan0
      dhcp-range=192.168.50.2,192.168.50.20,255.255.255.0,24h

5. Enable Services on Boot

  • Commands:
    sudo systemctl unmask hostapd
    sudo systemctl enable hostapd
    sudo systemctl start hostapd
    sudo systemctl start dnsmasq

Post-Setup

  • Reboot the Raspberry Pi to ensure all configurations take effect.
  • Test the WiFi Network by connecting a device to the SSID you configured.

Troubleshooting

  • Check Hostapd Status: If the network isn't broadcasting, check the status of hostapd using sudo systemctl status hostapd.
  • Logs and Debugging: Consult logs in /var/log/syslog for detailed error messages.

Documentation and File Paths

  • Hostapd Configuration: /etc/hostapd/hostapd.conf
  • Dnsmasq Configuration: /etc/dnsmasq.conf
  • Network Interface Configuration: /etc/dhcpcd.conf
  • Documentation Path: /raspberrypi/hostapd_setup/hostapd_network_setup.md

This setup will turn your Raspberry Pi Zero 2 W into a wireless access point that broadcasts a network when powered on. Remember to replace YourNetworkSSID and YourPassword with your desired network name and password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment