Skip to content

Instantly share code, notes, and snippets.

@XtendedGreg
Last active February 8, 2024 06:26
Show Gist options
  • Save XtendedGreg/5ef72d27c0dd1dbf1f2e2125092e7369 to your computer and use it in GitHub Desktop.
Save XtendedGreg/5ef72d27c0dd1dbf1f2e2125092e7369 to your computer and use it in GitHub Desktop.
Creating an Access Point on Raspberry Pi running Alpine Linux

Creating an Access Point on Raspberry Pi running Alpine Linux

By: XtendedGreg as seen on https://youtube.com/live/Uagq3oZrk6k

Introduction

Creating an access point with Alpine Linux on a Raspberry Pi can be an excellent project, as it allows you to extend your network or even create a new wireless network in a location where only wired internet is available. Below is a procedure to help you set up your Raspberry Pi as an access point using Alpine Linux. This guide assumes you have basic knowledge of Linux commands and networking.

Equipment Needed

  • Raspberry Pi (any model with Wi-Fi capability, e.g., Raspberry Pi 3/4/5)
  • MicroSD card (8 GB or more recommended)
  • Power supply for Raspberry Pi
  • Ethernet cable (if you want to share a wired connection)
  • Another computer to access the Raspberry Pi remotely

Step 1: Install Alpine Linux on Raspberry Pi

  • Download Alpine Linux: Go to the Alpine Linux website and download the Raspberry Pi version .tar.gz file that is compatible with your Raspberry Pi model.
  • Prepare the SD Card: Extract the contents of the downloaded .tar.gz file to the root of your SD Card
  • Initial Setup: Insert the SD card into your Raspberry Pi, connect it to your network via an Ethernet cable (if available), and power it on. Run setup-alpine and perform the initial configuration, but do not configure the wlan0 inteface yet.

Step 2: Install Necessary Packages

  • Connect to Raspberry Pi: SSH into your Raspberry Pi from another computer using its IP address.
  • Update and Upgrade: Ensure your Alpine Linux is up to date by running:
apk update && apk upgrade
  • Install Access Point and DHCP Server Software: You'll need hostapd for the access point and dnsmasq for DHCP and DNS services.
apk add hostapd dnsmasq wireless-tools wpa_supplicant iptables

Step 3: Configure the Access Point

  • Configure hostapd: Create or edit /etc/hostapd/hostapd.conf and configure your network settings. Here's an example configuration:
interface=wlan0
driver=hostapd
ssid=MyAccessPoint
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
  • Adjust ssid and wpa_passphrase to your liking.
  • Enable hostapd: Make hostapd start automatically at boot.
rc-update add hostapd default

Step 4: Configure dnsmasq

  • Configure dnsmasq: Edit /etc/dnsmasq.conf and add the following to set up the DHCP range and the default gateway. Replace 192.168.1.1 with the IP address of your Raspberry Pi in the network you're creating.
interface=wlan0
dhcp-range=192.168.1.10,192.168.1.100,255.255.255.0,24h
dhcp-option=option:router,192.168.1.1
  • Enable dnsmasq: Make dnsmasq start automatically at boot.
rc-update add dnsmasq default

Step 5: Network Configuration

Assign a Static IP: Configure wlan0 with a static IP address in /etc/network/interfaces or the equivalent at the bottom of the network configuration file in Alpine Linux.

auto wlan0
iface wlan0 inet static
  address 192.168.1.1
  netmask 255.255.255.0
  • Enable NAT (if sharing an internet connection): Enable IP forwarding and configure iptables to masquerade traffic.
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  • Replace eth0 with the interface that has internet access if different.
  • Enable iptables: Make iptables start automatically at boot.
rc-update add iptables default
  • Make current iptables entries persistent
rc-service iptables save

Step 6: Finalize and Test

  • Save to LBU
lbu commit -d
  • Reboot: Reboot your Raspberry Pi to apply all changes.
reboot
  • Test the Connection: On a Wi-Fi enabled device, search for the SSID you configured, connect using the password, and verify you have network access.
  • Note: If unable to access the internet from client machines, rerun the following command which should resolve it.
echo 1 > /proc/sys/net/ipv4/ip_forward

Step 7: Secure and Customize

  • Secure your Raspberry Pi: Change default passwords, update regularly, and consider firewall rules.
  • Customize: You can further customize your access point, such as setting up a captive portal or adding a VPN.

Conclusion

You've now set up a Raspberry Pi as an access point using Alpine Linux. This setup can be used for a wide range of applications, from extending your home network to providing internet access in new areas. Remember, the configurations can vary based on your specific needs and network setup, so feel free to adjust as necessary.

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