Raspberry Pi‎ > ‎

Setting up Pi as a Wifi Hotspot

Notes taken from:

Install the required software
sudo apt-get install hostapd udhcpd

Configure dhcp. Edit /etc/udhcpd.conf

start      #default:
end       #default:

interface       wlan0           #default: eth0

remaining       yes             #default: yes

opt     dns
option  subnet
opt     router
#opt    wins
#option dns   # appened to above DNS servers for a total of 3
#option domain  local
option  lease   864000          # 10 days of seconds

Edit the file /etc/default/udhcpd
# Comment the following line to enable

# Options to pass to busybox' udhcpd.
# -S    Log to syslog
# -f    run in foreground


Edit the /etc/network/interfaces 
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0

iface wlan0 inet static

Configure HostAPD - create file /etc/hostapd/hostapd.conf and add the following content

Edit the file - /etc/default/hostapd
# Defaults for hostapd initscript
# See /usr/share/doc/hostapd/README.Debian for information about alternative
# methods of managing hostapd.
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz

# Additional daemon options to be appended to hostapd command:-
#       -d   show more debug messages (-dd for even more)
#       -K   include key data in debug messages
#       -t   include timestamps in some debug messages
# Note that -B (daemon mode) and -P (pidfile) options are automatically
# configured by the init.d script and must not be added to DAEMON_OPTS.

Edit /etc/sysctl.conf and add the following line to the end of the file

Run the following commands
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Save the settings
sudo iptables-save > /etc/iptables.ipv4.nat

Add the following to /etc/network/interfaces
up iptables-restore < /etc/iptables.ipv4.nat

Run the following command to start the access point
sudo service hostapd start
sudo service udhcpd start

Update the Pi to run these commands from boot
sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable