Sunday, 25. June 2017 08:46
Search

Hardware

Virtualisation

Tools and scripts

Compiled things

Games and fun

freiesMagazin

Counter
Sponsored by

Use your Raspberry Pi as access point

2016-10-02 00:21
Twitter article

This script/tutorial is heavily based on the excellent article Setting up a Raspberry Pi as a WiFi access point from Adafruit. Other than Adafruit's howto, this guide shows an automatic way to convert your Raspberry Pi with Raspbian into an access point. All you need (in addition) is a supported USB WiFi stick.

To use the RaPi as access point it should be able to connect to the internet via the Ethernet cable.

Log in via SSH

Use an SSH client to log into your Raspberry Pi

ssh pi@[current IP of you Raspberry Pi]

Store the script on the Raspberry Pi

#Become root
sudo bash

#Create a new file (e.g.)
nano /tmp/ap-config.sh

#Paste the script into it
#Press Ctrl + X and confirm

#Make the script executable
chmod +x /tmp/ap-config.sh

#Run it
/tmp/ap-config.sh

The script (to paste)

You should change the WPA password "Raspberry" to a complicated one of your choice.
#!/bin/bash

#Get the device name of the WiFi device
wifiDev=$(iwconfig 2> /dev/null | grep '^[a-z]' | cut -d' ' -f1)
#Set the WPA encryption password
wpaPassword='Raspberry'

#Check if a WiFi device was found
if [ -z wifiDev ]
then
	echo "ERROR: No WiFi adapter found"
	exit 1
fi

if [ $(lsmod | grep mac80211 -c) -eq 0 ]
then
	echo "ERROR: WiFi adapter does not use mac80211 and cannot be used as access point"
	exit 2
fi

#Install the access point and DHCP server software
apt-get -y install hostapd isc-dhcp-server

#Configure the DHCP server
sed -i -e 's/^option domain-name/#option domain-name/g' -e 's/#authoritative;/authoritative;/'\
/etc/dhcp/dhcpd.conf
#Set the IP range to distribute IPs in cat >> /etc/dhcp/dhcpd.conf << "EOF" subnet 192.168.42.0 netmask 255.255.255.0 { range 192.168.42.10 192.168.42.50; option broadcast-address 192.168.42.255; option routers 192.168.42.1; default-lease-time 600; max-lease-time 7200; option domain-name "local"; option domain-name-servers 8.8.8.8, 8.8.4.4; } EOF #Make it listen to the WiFi device sed -i "s/INTERFACE.*/INTERFACE=\"$wifiDev\"/" /etc/default/isc-dhcp-server /etc/init.d/isc-dhcp-server restart #Give the WiFi device a static IP sed -i -e 's/^iface wlan0/#iface wlan0/' -e 's/^wpa-roam/#wpa-roam/' -e 's/^iface default/#iface default/'\
/etc/network/interfaces
echo "iface $wifiDev inet static address 192.168.42.1 netmask 255.255.255.0 sleep2; pre-up ifconfig $wifiDev 192.168.42.1; iptables-restore /etc/iptables.ipv4.nat" >>\
/etc/network/interfaces
#Set the IP at once ifconfig $wifiDev 192.168.42.1 #Configure the access point software echo "interface=$wifiDev driver=nl80211 ssid=Pi_AP hw_mode=g channel=6 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=$wpaPassword wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP" > /etc/hostapd/hostapd.conf sed -i 's°#DAEMON_CONF.*°DAEMON_CONF="/etc/hostapd/hostapd.conf"°' /etc/default/hostapd #Add IP forwarding echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf echo 1 > /proc/sys/net/ipv4/ip_forward #Enable NAT iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -A FORWARD -i eth0 -o $wifiDev -m state --state RELATED,ESTABLISHED -j ACCEPT iptables -A FORWARD -i $wifiDev -o eth0 -j ACCEPT iptables-save > /etc/iptables.ipv4.nat echo " iptables-restore < /etc/iptables.ipv4.nat" >> /etc/network/interfaces #Activate the access point and the DHCP server daemons at startup update-rc.d hostapd enable update-rc.d isc-dhcp-server enable #Move the WPASupplicant file out of the way mv /usr/share/dbus-1/system-services/fi.epitest.hostap.WPASupplicant.service ~/ #Reboot to see, if all works well reboot

Connect to your new access point

After the Pi is booted you should see a new access point in the access point list of your computer's operating system. When connecting to it with the password you picked, you will get assigned the network settings via DHCP.

<< Previous articles

My other projects

m23 software distribution

m23 is a software distribution and management system for Debian, Ubuntu and Kubuntu. With m23 you can install and administrate hundreds of clients in an easy way!

Visit the m23 project at SourceForge: m23.sf.net.

Grass Roots Democracy Machine (GRDM)

The GRDM, the Grass Roots Democracy Machine is a software development project designed to create a voting system. The aim is to implement the basic goals of anonymous and comprehensible votings into software.

Visit the GRDM project at SourceForge: grassrootsdemoc.sf.net.

khtml2png

khtml2png is a command line program to create screenshots of webpages.

Visit the khtml2png project at SourceForge: khtml2png.sf.net.

based on devalcms
devalcms