Local hotspot

Set up a local hotspot

In order to work as an access point, the Raspberry Pi will need to have access point software installed, along with DHCP server software to provide connecting devices with a network address. Ensure that your Raspberry Pi is using an up-to-date version of Raspbian (dated 2017 or later).

Install the required software (dnsmasq and hostapd) with this command:

sudo apt update
sudo apt upgrade
sudo apt install dnsmasq hostapd

Configuring a static IP

To configure the static IP address, open the dhcpcd configuration file with the following command:

sudo nano /etc/dhcpcd.conf

Go to the end of the file and edit it so that it looks like the following:

interface wlan0
static ip_address=
nohook wpa_supplicant

Now restart the dhcpcd daemon:

sudo systemctl restart dhcpcd

Configuring the DHCP server (dnsmasq)

The DHCP service is provided by dnsmasq. By default, the configuration file contains a lot of information that is not needed, and it is easier to start from scratch. Rename this configuration file, and edit a new one:

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo nano /etc/dnsmasq.conf

Type or copy the following information into the dnsmasq configuration file and save it:

interface=wlan0 # Use the require wireless interface - usually wlan0

Reload dnsmasq to use the updated configuration:

sudo systemctl reload dnsmasq

Configuring the access point host software (hostapd)

sudo nano /etc/hostapd/hostapd.conf

add the following text into the file


We now need to tell the system where to find this configuration file.

sudo nano /etc/default/hostapd

Find the line with #DAEMON_CONF, and replace it with this:


Start it up

Now enable and start hostapd:

sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd

Add routing and masquerade

Edit /etc/sysctl.conf

sudo nano /etc/sysctl.conf

and uncomment this line:


Add a masquerade for outbound traffic on eth0:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Save the iptables rule.

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

Edit /etc/rc.local and add this just above "exit 0" to install these rules on boot.

sudo nano /etc/rc.local

Add the following line aboce Exit 0

iptables-restore < /etc/iptables.ipv4.nat

Using a wireless device, search for networks. The network SSID you specified in the hostapd configuration should now be present, and it should be accessible with the specified password.

If SSH is enabled on the Raspberry Pi access point, it should be possible to connect to it from another Linux box (or a system with SSH connectivity present) as follows, assuming the pi account is present:

By this point, the Raspberry Pi is acting as an access point, and other devices can associate with it. Associated devices can access the Raspberry Pi access point via its IP address for operations such as rsync, scp, or ssh.

Update the SSID and password

The following script updates the SSID name to the last 8 digits of the mac addres. The PASSWD is updated to a random 8 digit number.

SSID=pytobot:$(ifconfig eth0 | grep -Eo ..\(\:..\){5} | tail -c 9)
echo $SSID
PASSWD=$((10000000 + RANDOM % 9999999))
echo $PASSWD
sudo sed -i "s/SSIDNAME/$SSID/g" /etc/hostapd/hostapd.conf
sudo sed -i "s/PASSWORD/$PASSWD/g" /etc/hostapd/hostapd.conf
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
sudo systemctl start hostapd

​Execute script from startup

TODO: At this moment the script will search for SSIDNAME and PASSWD in the config file. The first time on startup the SSIDNAME and PASSWD will be changed to the MACADDR and random PASSWD, But after that its not possible to change it anymore. That is not a problem as long the SD card stays in the same controller with the same MACADDR.


Local hostspot- Raspberry Pi[SOURCE]