Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4762

Networking and servers • Re: Offline hotspot and local webserver

$
0
0
I dont got unlimited data.

anyways. i figured it out. heres a script based on a guide a found with a few touches.

Code:

#!/bin/bash# Update and install required packagesecho "Updating system and installing required packages..."sudo apt updatesudo apt install -y --no-install-recommends hostapd dnsmasq lighttpd# Stop services to allow configurationecho "Stopping hostapd and dnsmasq services..."sudo systemctl stop hostapd || truesudo systemctl stop dnsmasq || true# Configure hostapd (Wi-Fi Access Point)echo "Configuring hostapd..."sudo bash -c 'cat > /etc/hostapd/hostapd.conf' <<EOLinterface=wlan0driver=nl80211ssid=PiFihw_mode=gchannel=7wmm_enabled=0macaddr_acl=0auth_algs=1ignore_broadcast_ssid=0wpa=2wpa_passphrase=passwordwpa_key_mgmt=WPA-PSKrsn_pairwise=CCMPEOLsudo sed -i 's|#DAEMON_CONF=""|DAEMON_CONF="/etc/hostapd/hostapd.conf"|' /etc/default/hostapd# Configure static IP for wlan0echo "Configuring static IP for wlan0..."if ! grep -q "interface wlan0" /etc/dhcpcd.conf; then    sudo bash -c 'cat >> /etc/dhcpcd.conf' <<EOLinterface wlan0static ip_address=192.168.4.1/24nohook wpa_supplicantEOLelse    echo "Static IP for wlan0 is already configured in /etc/dhcpcd.conf."fisudo systemctl restart dhcpcd# Configure dnsmasq (DHCP Service)echo "Configuring dnsmasq..."if [ -f /etc/dnsmasq.conf ]; then    sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.bakfisudo bash -c 'cat > /etc/dnsmasq.conf' <<EOLinterface=wlan0dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24haddress=/my.site/192.168.4.1EOLsudo systemctl restart dnsmasq# Enable IP forwardingecho "Enabling IP forwarding..."sudo sed -i 's|#net.ipv4.ip_forward=1|net.ipv4.ip_forward=1|' /etc/sysctl.conf# Enable and start hostapd and dnsmasq servicesecho "Enabling and starting hostapd and dnsmasq services..."sudo systemctl unmask hostapdsudo systemctl enable hostapdsudo systemctl enable dnsmasqsudo systemctl start hostapdsudo systemctl start dnsmasq# Configure Lighttpd web serverecho "Configuring Lighttpd..."sudo systemctl enable lighttpdsudo systemctl start lighttpd# Create a placeholder webpageif [ ! -d /var/www/html ]; then    echo "Creating web directory..."    sudo mkdir -p /var/www/htmlfiif [ -f /var/www/html/index.html ]; then    echo "Backing up existing index.html..."    sudo mv /var/www/html/index.html /var/www/html/index.html.bakfiecho "Creating placeholder webpage..."sudo bash -c 'cat > /var/www/html/index.html' <<EOL<!DOCTYPE html><html><head>    <title>Welcome to PiFi</title></head><body>    <h1>Welcome to the PiFi Offline Network</h1>    <p>This is a placeholder webpage.</p></body></html>EOL# Final message and rebootecho "Setup complete! Rebooting your Raspberry Pi now..."sudo reboot

Statistics: Posted by davidm8624 — Sat Jan 18, 2025 7:48 pm



Viewing all articles
Browse latest Browse all 4762

Trending Articles