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           192.168.2.2     #default: 192.168.0.20
end             192.168.2.20    #default: 192.168.0.254

interface       wlan0           #default: eth0

remaining       yes             #default: yes

opt     dns     192.168.10.2 192.168.10.10
option  subnet  255.255.255.0
opt     router  192.168.2.1
#opt    wins    192.168.10.10
#option dns     129.219.13.81   # 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
#DHCPD_ENABLED="no"

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

DHCPD_OPTS="-S"

Edit the /etc/network/interfaces 
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
auto wlan0

iface wlan0 inet static
        address 192.168.2.1
        netmask 255.255.255.0

Configure HostAPD - create file /etc/hostapd/hostapd.conf and add the following content
interface=wlan0
ssid=andrews_car
hw_mode=g
channel=6
auth_algs=1
wmm_enabled=0



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
#
DAEMON_CONF="/etc/hostapd/hostapd.conf"

# 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.
#
#DAEMON_OPTS=""

Edit /etc/sysctl.conf and add the following line to the end of the file
net.ipv4.ip_forward=1

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



Comments