Skip to content

Instantly share code, notes, and snippets.

@dantheman213
Created January 18, 2016 02:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dantheman213/8ef83602bff24fdacc46 to your computer and use it in GitHub Desktop.
Save dantheman213/8ef83602bff24fdacc46 to your computer and use it in GitHub Desktop.
Setup Wifi Infrastructure Network on RPi 2
1.
apt-get update
apt-get upgrade
2.
apt-get install hostapd udhcpd
3.
/etc/udhcpd.conf
start 192.168.42.2 # This is the range of IPs that the hostspot will give to client devices.
end 192.168.42.20
interface wlan0 # The device uDHCP listens on.
remaining yes
opt dns 8.8.8.8 4.2.2.2 # The DNS servers client devices will use.
opt subnet 255.255.255.0
opt router 192.168.42.1 # The Pi's IP address on wlan0 which we will set up shortly.
opt lease 864000 # 10 day DHCP lease time in seconds
4.
/etc/default/udhcpd
DHCPD_ENABLED="no" -> #DHCPD_ENABLED="no"
5.
ifconfig wlan0 192.168.42.1
6.
/etc/network/interfaces
iface wlan0 inet dhcp (if present)
->
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
====
allow-hotplug wlan0
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet manual
->
#allow-hotplug wlan0
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet manual
7.
/etc/hostapd/hostapd.conf
interface=wlan0
driver=cfg80211
ssid=linksys
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=1
wpa=2
wpa_passphrase=qwerty123456!##@
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
8.
/etc/default/hostapd
#DAEMON_CONF=""
->
DAEMON_CONF="/etc/hostapd/hostapd.conf"
9.
sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
10.
/etc/sysctl.conf
(append)
net.ipv4.ip_forward=1
11.
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
12.
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
13.
/etc/network/interfaces
(append to bottom)
up iptables-restore < /etc/iptables.ipv4.nat
14.
sudo service hostapd start
sudo service udhcpd start
15.
sudo update-rc.d hostapd enable
sudo update-rc.d udhcpd enable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment