{"id":1424,"date":"2019-06-18T17:54:06","date_gmt":"2019-06-18T17:54:06","guid":{"rendered":"http:\/\/bitcows.com\/?p=1424"},"modified":"2024-05-10T18:08:38","modified_gmt":"2024-05-10T18:08:38","slug":"raspberry-pi-router-ap-updated","status":"publish","type":"post","link":"https:\/\/bitcows.com\/?p=1424","title":{"rendered":"Raspberry Pi 3 Model B+ Router (AP) Updated 2019"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/bitcows.com\/wp-content\/uploads\/2019\/06\/icon-570x285.png\" alt=\"\" width=\"570\" height=\"285\" class=\"aligncenter size-column2-1\/2 wp-image-1444\" \/><\/p>\n<h3>Prerequisites<\/h3>\n<ul>\n<li>Raspberry Pi 3 B+ or Raspberry Pi Zero W<\/li>\n<li>Image Raspbian onto your SD card<\/li>\n<li>Set up your Pi with your configuration like Keyboard and wifi.<\/li>\n<\/ul>\n<h2>Lets Update<\/h2>\n<p>First, update your system&#8217;s package list by entering the following command:<\/p>\n<pre class=\"prettyprint\">sudo apt-get update<\/pre>\n<p>Next, upgrade all your installed packages to their latest versions with the command:<\/p>\n<pre class=\"prettyprint\">sudo apt-get dist-upgrade<\/pre>\n<p>Install all the required software in one go with this command:<\/p>\n<pre class=\"prettyprint\">sudo apt install dnsmasq hostapd<\/pre>\n<p><strong>Configuring a static IP<\/strong><br \/>\nWe are configuring a standalone network to act as a server, so the Raspberry Pi needs to have a static IP address assigned to the wireless port. This documentation assumes that we are using the standard 192.168.x.x IP addresses for our wireless network, so we will assign the server the IP address 192.168.4.1. It is also assumed that the wireless device being used is <code>wlan0<\/code>.<\/p>\n<p><strong>To configure the static IP address, edit the dhcpcd configuration file with:<\/strong><\/p>\n<pre class=\"prettyprint\">sudo nano \/etc\/dhcpcd.conf<\/pre>\n<p>Go to the end of the file and edit it so that it looks like the following:<\/p>\n<pre class=\"prettyprint\">interface wlan0\nstatic ip_address=192.168.4.1\/24\nnohook wpa_supplicant<\/pre>\n<p><strong>Now restart the <code>dhcpcd<\/code> daemon:<\/strong><\/p>\n<pre class=\"prettyprint\">sudo systemctl restart dhcpcd<\/pre>\n<p><strong>Configuring the DHCP server (dnsmasq)<\/strong><br \/>\nThe 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:<\/p>\n<pre class=\"prettyprint\">sudo mv \/etc\/dnsmasq.conf \/etc\/dnsmasq.conf.orig\nsudo nano \/etc\/dnsmasq.conf<\/pre>\n<p>Type or copy the following information into the dnsmasq configuration file and save it:<\/p>\n<pre class=\"prettyprint\">interface=wlan0 # Use the require wireless interface - usually wlan0\ndhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h<\/pre>\n<p>So for <code>wlan0<\/code>, we are going to provide IP addresses between <code>192.168.4.2<\/code> and <code>192.168.4.20<\/code>, with a lease time of 24 hours. If you are providing DHCP services for other network devices (e.g. eth0), you could add more sections with the appropriate interface header, with the range of addresses you intend to provide to that interface.<\/p>\n<p><strong>Reload dnsmasq to use the updated configuration:<\/strong><\/p>\n<pre class=\"prettyprint\">sudo systemctl reload dnsmasq<\/pre>\n<p><strong>Configuring the access point host software (hostapd)<\/strong><br \/>\nYou need to edit the hostapd configuration file, located at <code>\/etc\/hostapd\/hostapd.conf<\/code>, to add the various parameters for your wireless network. After initial install, this will be a new\/empty file.<\/p>\n<pre class=\"prettyprint\">sudo nano \/etc\/hostapd\/hostapd.conf<\/pre>\n<p>Add the information below to the configuration file. This configuration assumes we are using channel 7, with a network name of NameOfNetwork, and a password AardvarkBadgerHedgehog. Note that the name and password should not have quotes around them. The passphrase should be between 8 and 64 characters in length.<\/p>\n<p>To use the 5 GHz band, you can change the operations mode from <code>hw_mode=g<\/code> to <code>hw_mode=a<\/code>. Possible values for hw_mode are:<br \/>\n<code>a = IEEE 802.11a (5 GHz)<br \/>\nb = IEEE 802.11b (2.4 GHz)<br \/>\ng = IEEE 802.11g (2.4 GHz)<br \/>\nad = IEEE 802.11ad (60 GHz)<\/code><\/p>\n<pre class=\"prettyprint\">interface=wlan0\ndriver=nl80211\nssid=RaspiRouter\nhw_mode=g\nchannel=6\nwmm_enabled=0\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\nwpa=2\nwpa_passphrase=password123\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP\nrsn_pairwise=CCMP\n#speeds up the downloads\nwme_enabled=1\nieee80211n=1<\/pre>\n<p>We now need to tell the system where to find this configuration file.<\/p>\n<pre class=\"prettyprint\">sudo nano \/etc\/default\/hostapd<\/pre>\n<p>Find the line with <code>#DAEMON_CONF<\/code>, and replace it with this:<\/p>\n<pre class=\"prettyprint\">DAEMON_CONF=\"\/etc\/hostapd\/hostapd.conf\"<\/pre>\n<p>Start it up<br \/>\nNow enable and start hostapd:<\/p>\n<pre class=\"prettyprint\">sudo systemctl unmask hostapd\nsudo systemctl enable hostapd\nsudo systemctl start hostapd<\/pre>\n<p>Add routing and masquerade<br \/>\nEdit <code>\/etc\/sysctl.conf<\/code> and uncomment or add this line:<\/p>\n<pre class=\"prettyprint\">net.ipv4.ip_forward=1<\/pre>\n<p>Add a masquerade for outbound traffic on eth0:<\/p>\n<pre class=\"prettyprint\">sudo iptables -t nat -A  POSTROUTING -o eth0 -j MASQUERADE<\/pre>\n<p><em>See issues below if this fails.<\/em><\/p>\n<p>Save the iptables rule.<\/p>\n<pre class=\"prettyprint\">sudo sh -c \"iptables-save &gt; \/etc\/iptables.ipv4.nat\"<\/pre>\n<p>Edit <code>\/etc\/rc.local<\/code> and add this just above <code>exit 0<\/code> to install these rules on boot.<\/p>\n<pre class=\"prettyprint\">iptables-restore &lt; \/etc\/iptables.ipv4.nat<\/pre>\n<p>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.<\/p>\n<p>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:<\/p>\n<p><code>ssh pi@192.168.4.1<\/code><br \/>\nBy 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 <code>rsync<\/code>, <code>scp<\/code>, or <code>ssh<\/code>.<\/p>\n<h3>Whos connected?<\/h3>\n<p>To find out whos connected to your router install nmap <\/p>\n<pre class=\"prettyprint\">sudo apt install nmap<\/pre>\n<p>NOTE: you will need to be connected to the internet. Best way is to plug into ethernet.<\/p>\n<p>Once its in install you can then type this in and it will list out all connected devices.<\/p>\n<pre class=\"prettyprint\">sudo nmap -sP -PI -PT 192.168.4.1\/24 > list.text<\/pre>\n<p>Example:<br \/>\n<code>Starting Nmap 7.40 ( https:\/\/nmap.org ) at 2019-06-19 08:56 MST<br \/>\nNmap scan report for ShadowBook-Pro (192.168.4.8)<br \/>\nHost is up (-0.090s latency).<br \/>\nMAC Address: F0:18:98:28:1C:1C (Unknown)<br \/>\nNmap scan report for kali (192.168.4.16)<br \/>\nHost is up (-0.15s latency).<br \/>\nMAC Address: 80:1F:02:F6:68:B6 (Edimax Technology)<br \/>\nNmap scan report for 192.168.4.1<br \/>\nHost is up.<br \/>\nNmap done: 256 IP addresses (3 hosts up) scanned in 15.18 seconds<\/code><\/p>\n<p>filter it down to IP&#8217;s only <\/p>\n<pre class=\"prettyprint\">sudo nmap -sP -PI -PT 192.168.4.1\/24 | grep -i Nmap > list.text <\/pre>\n<h3>ISSUES:<\/h3>\n<p>If you have issues with MASQUERADE you should run sudo <code>apt update<\/code> then sudo <code>apt upgrade<\/code> to ensure your kernel has been replaced, then <code>reboot<\/code> and check <code>uname -r<\/code>; it should give a version with a corresponding <code>\/lib\/modules\/<\/code> directory that does exist. The pi kernel can boot without any, however, so to check, try <code>lsmod<\/code>; if there&#8217;s nothing, something is wrong. If there is, you can filter that <code>lsmod | grep -P \"ip|nf<\/code>&#8221; to see the ones that are related to iptables\/netfilter (and anything else that coincidentally contains those letter combinations).<br \/>\nThe base module is actually <code>ip_tables<\/code>, but it should be loaded automatically. The base module for NAT is <code>nf_nat<\/code> but that should be loaded automatically as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Prerequisites Raspberry Pi 3 B+ or Raspberry Pi Zero W Image Raspbian onto your SD card Set up your Pi with your configuration like Keyboard and wifi. Lets Update First, update your system&#8217;s package list by entering the following command: sudo apt-get update Next, upgrade all your installed packages to their latest versions with the&hellip;<\/p>\n<p class=\"more-link\"><a href=\"https:\/\/bitcows.com\/?p=1424\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":1,"featured_media":2299,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[59],"class_list":["post-1424","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-electronics","tag-raspberry-pi"],"_links":{"self":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/1424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1424"}],"version-history":[{"count":1,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/1424\/revisions"}],"predecessor-version":[{"id":2300,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/posts\/1424\/revisions\/2300"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=\/wp\/v2\/media\/2299"}],"wp:attachment":[{"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bitcows.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}