{"id":866,"date":"2013-08-01T12:25:51","date_gmt":"2013-08-01T12:25:51","guid":{"rendered":"https:\/\/raspberry-projects.com\/pi\/?p=866"},"modified":"2019-05-08T20:03:07","modified_gmt":"2019-05-08T20:03:07","slug":"wifi-access-point","status":"publish","type":"post","link":"https:\/\/raspberry-projects.com\/pi\/software_utilities\/wifi-access-point","title":{"rendered":"WiFi Access Point"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Setting up your RPi as a WiFi access point<\/h4>\n\n\n\n<p><a href=\"http:\/\/learn.adafruit.com\/setting-up-a-raspberry-pi-as-a-wifi-access-point\/overview\">http:\/\/learn.adafruit.com\/setting-up-a-raspberry-pi-as-a-wifi-access-point\/overview<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Configuring Raspberry Pi 3 WiFi As An Access Point<\/h3>\n\n\n\n<p>The below is based on this excellent guide here on the Frillips blog:&nbsp;<a href=\"https:\/\/frillip.com\/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd\/\">https:\/\/frillip.com\/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd\/<\/a><br>You should follow that guide, we&#8217;ve just duplicated here for our needs in case it ever vanishes.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Installing The Required Packages<\/h5>\n\n\n\n<p>hostapd<\/p>\n\n\n\n<p>Let you to use the built in WiFi as an access point.<\/p>\n\n\n\n<p>dnsmasq<\/p>\n\n\n\n<p>A&nbsp;combined DHCP and DNS server that&#8217;s easy to configure (less heavyweight than&nbsp;isc-dhcp-server and bind9)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get install dnsmasq hostapd<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Configuring Raspbian DHCP<\/h5>\n\n\n\n<p>In Raspian&nbsp;interface configuration is handled by dhcpcd. We need to tell it to ignore wlan0, as we will be configuring it with a static IP address elsewhere.<\/p>\n\n\n\n<p>Open up the dhcpcd configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/dhcpcd.conf<\/code><\/pre>\n\n\n\n<p>Add the following to the bottom of the file (but above any interface lines you may have added):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#DISABLE WLAN0 FROM DHCPCD AS WE ARE USING IT AS A WIFI ACCESS POINT\ndenyinterfaces wlan0 <\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Set WLAN0 static IP Address<\/h5>\n\n\n\n<p>Open up the interface configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/network\/interfaces<\/code><\/pre>\n\n\n\n<p>Edit the wlan0 section so that it looks like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>allow-hotplug wlan0\niface wlan0 inet static\n    wireless-mode Master\n    address 192.168.0.1\n    netmask 255.255.255.0\n    network 192.168.0.0\n    broadcast 192.168.0.255\n#    wpa-conf \/etc\/wpa_supplicant\/wpa_supplicant.conf<\/code><\/pre>\n\n\n\n<p><strong><em>N.B. Make sure the subnet is different from the subnet you are using on your eth0 connection if you are connecting via SSH, otherwise you&#8217;ll loose your connection on eth0!!<\/em><\/strong><\/p>\n\n\n\n<p>Restart dhcpcd and then reload the configuration for wlan0 with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo service dhcpcd restart\n\nsudo ifdown wlan0; sudo ifup wlan0<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Configure Hostapd<\/h5>\n\n\n\n<p>Create a new configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/hostapd\/hostapd.conf<\/code><\/pre>\n\n\n\n<p>Copy this&nbsp;into the file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>interface=wlan0\n\n# Use the nl80211 driver with the brcmfmac driver\ndriver=nl80211\n\n# The name to use for the network\nssid=RPi-AP\n\n# Use the 2.4GHz band\nhw_mode=g\n\n# Use channel 6\nchannel=6\n\n# Enable 802.11n\nieee80211n=1\n\n# Enable WMM\nwmm_enabled=1\n\n# Enable 40MHz channels with 20ns guard interval\nht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]\n\n# Accept all MAC addresses\nmacaddr_acl=0\n\n# Use WPA authentication\nauth_algs=1\n\n# Broadcast the network name\nignore_broadcast_ssid=0\n\n# Use WPA2\nwpa=2\n\n# Use a pre-shared key\nwpa_key_mgmt=WPA-PSK\n\n# The WPA2 passphrase (password)\nwpa_passphrase=raspberry\n\n# Use AES, instead of TKIP\nrsn_pairwise=CCMP<\/code><\/pre>\n\n\n\n<p>Save and exit.<\/p>\n\n\n\n<p>To verify its working by entering this and checking you see network &#8220;RPi3-AP&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo \/usr\/sbin\/hostapd \/etc\/hostapd\/hostapd.conf<\/code><\/pre>\n\n\n\n<p>Use Ctrl+C to stop it.<\/p>\n\n\n\n<p>If you tried&nbsp;connecting to it, you would&nbsp;see some output from the Pi, but you won&#8217;t receive an&nbsp;IP address until dnsmasq&nbsp;is set up.<\/p>\n\n\n\n<p>We need to tell hostapd where to look for the config file when it starts up on boot. Open up the default configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/default\/hostapd<\/code><\/pre>\n\n\n\n<p>find the line<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#DAEMON_CONF=\"\"<\/code><\/pre>\n\n\n\n<p>and replace it with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DAEMON_CONF=\"\/etc\/hostapd\/hostapd.conf\"<\/code><\/pre>\n\n\n\n<p>Note: &#8220;_CONF&#8221;, NOT &#8220;#DAEMON_OPTS&#8221;!!! &nbsp;REMOVE THE &#8216;#&#8217; AT THE START OF THE LINE!!!!<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Configure DNSMASQ<\/h5>\n\n\n\n<p>The default dnsmasq config file contains lots of information on how to use it, but the majority of it is largely redundant for our purposes. So to simplify things we move it and then create&nbsp;a new one:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mv \/etc\/dnsmasq.conf \/etc\/dnsmasq.conf.orig\nsudo nano \/etc\/dnsmasq.conf<\/code><\/pre>\n\n\n\n<p>Copy in the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Use interface wlan0\ninterface=wlan0\n\n# Explicitly specify the address to listen on\nlisten-address=192.168.0.1\n\n# Bind to the interface to make sure we aren't sending things elsewhere\nbind-interfaces\n\n# Forward DNS requests to Google DNS\nserver=8.8.8.8\n\n# Don't forward short names\ndomain-needed\n\n# Never forward addresses in the non-routed address spaces.\nbogus-priv\n\n# Assign IP addresses between 192.168.0.5 and 192.168.0.250 with a 12 hour lease time\ndhcp-range=192.168.0.5,192.168.0.250,12h<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Set Up IPv4 Forwarding<\/h5>\n\n\n\n<p>We need to enable packet forwarding. Open up the sysctl.conf file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/sysctl.conf<\/code><\/pre>\n\n\n\n<p>Remove the # from the beginning of the line containing:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>net.ipv4.ip_forward=1<\/code><\/pre>\n\n\n\n<p>Save and exit. &nbsp;This will enable it on the next reboot. &nbsp;You can&nbsp;activate it immediately with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sh -c \"echo 1 > \/proc\/sys\/net\/ipv4\/ip_forward\"<\/code><\/pre>\n\n\n\n<p>To share our eth0&nbsp;internet connection to devices connected over WiFi we need to configure&nbsp;a NAT between our wlan0 interface and our eth0 interface. Use&nbsp;the following commands:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\nsudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT\nsudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT<\/code><\/pre>\n\n\n\n<p>We need these rules to be applied every time we reboot so run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo sh -c \"iptables-save > \/etc\/iptables.ipv4.nat\"<\/code><\/pre>\n\n\n\n<p>to save the rules to the file \/etc\/iptables.ipv4.nat. We need to run this after each reboot, so open the rc.local file with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo nano \/etc\/rc.local<\/code><\/pre>\n\n\n\n<p>Just above the line exit 0, add the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Special for using wlan0 as an access point\niptables-restore &lt; \/etc\/iptables.ipv4.nat <\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Start The Services<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo service hostapd start\nsudo service dnsmasq start<\/code><\/pre>\n\n\n\n<p>You should now see a new WiFi network with SSID &#8220;RPi-AP&#8221;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Issues Found<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">WiFi access point DHCP server no longer working<\/h5>\n\n\n\n<p>Issue encountered after updating all packages on Raspbian Jesse<br> Can connect to the WiFi access point but when I look at the IP settings of my computer the DHCP server on the RPi has not functioned and issued correct settings.  Using the command &#8220;service dnsmasq status&#8221; I get this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u25cf dnsmasq.service - dnsmasq - A lightweight DHCP and caching DNS server\n   Loaded: loaded (\/lib\/systemd\/system\/dnsmasq.service; enabled)\n  Drop-In: \/run\/systemd\/generator\/dnsmasq.service.d\n           \u2514\u250050-dnsmasq-$named.conf, 50-insserv.conf-$named.conf\n   Active: failed (Result: exit-code) since Wed 2019-05-08 08:28:20 UTC; 11h ago\n  Process: 705 ExecStart=\/etc\/init.d\/dnsmasq systemd-exec (code=exited, status=1\/FAILURE)\n  Process: 657 ExecStartPre=\/usr\/sbin\/dnsmasq --test (code=exited, status=0\/SUCCESS)\npi@raspberrypi:~ $<\/code><\/pre>\n\n\n\n<p>Solution found on this page<br><a href=\"https:\/\/discourse.pi-hole.net\/t\/dnsmasq-not-working-after-last-ftl-update\/3537\/33\">https:\/\/discourse.pi-hole.net\/t\/dnsmasq-not-working-after-last-ftl-update\/3537\/33<\/a><\/p>\n\n\n\n<p>is to issue the following command to remove dns-root-data:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt-get --purge remove dns-root-data<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Setting up your RPi as a WiFi access point http:\/\/learn.adafruit.com\/setting-up-a-raspberry-pi-as-a-wifi-access-point\/overview Configuring Raspberry Pi 3 WiFi As An Access Point The below is based on this excellent guide here on the Frillips blog:&nbsp;https:\/\/frillip.com\/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd\/You should follow that guide, we&#8217;ve just duplicated here for our needs in case it ever vanishes. Installing The Required Packages hostapd Let you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-866","post","type-post","status-publish","format-standard","hentry","category-software_utilities"],"_links":{"self":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/866","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/comments?post=866"}],"version-history":[{"count":28,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/866\/revisions"}],"predecessor-version":[{"id":3059,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/posts\/866\/revisions\/3059"}],"wp:attachment":[{"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/media?parent=866"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/categories?post=866"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raspberry-projects.com\/pi\/wp-json\/wp\/v2\/tags?post=866"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}