Repository navigation
Raspberry Pi 2 Node Setup
This document provides step-by-step instructions on configuring a Raspberry Pi 2 into a Wi-Fi access point running a LDLN node. All setup is done remotely, no monitor, keyboard or mouse is required.
This list assumes you're using a Mac, something like OS X 10.8+. Using Windows or Linux shouldn't be a big difference.
A lot of these instructions are weird with the newest version of Rasbian based on Debian Stretch. Notes below where it should be slightly different.
- OS X Computer with Ethernet port
- Micro SD card reader
- Raspberry Pi 2
- Wi-FI USB dongle (tested with RTL8192 and RT5370, which require different hostapd builds!)
- Ethernet cable
- Micro-USB power cable
TODO
- Download a fresh Rasbian image: https://downloads.raspberrypi.org/raspbian_lite_latest (note this wiki was previously written using http://downloads.raspberrypi.org/raspbian_latest but since then the lite version has been released)
- Download ApplePi-Baker: http://www.tweaking4all.com/downloads/raspberrypi/ApplePi-Baker.zip -- This will allow you to flash the image easily, there's a few different ways, this is the easiest
- Flash the image to the card using the
IMG Recipesection of the ApplePi-Baker UI, do NOT use theNOOBS Recipesection
There a few ways to connect your computer to the Pi.
-
Once card is flashed and mounted on the machine open the
cmdline.txtfile on the card -
Add
ip=192.168.2.1to the end of the list of commands (pay attention to newlines, as these commands are sensitive to where line breaks occur!) -
Save the file clicking
yesto any weird warnings that pop up -
Since ssh is disabled by default, you must also create a file called
sshin the same directory on the card. The contents of this file does not matter, but it must exist in order for ssh to be toggled on. The system will remove this file on first boot. (see here for details) -
Assemble the Pi with the newly flashed card and Wi-Fi dongle
-
Connect the Ethernet cable to your computer and the Pi
-
Set your computer's Ethernet device to a static IP of 192.168.2.2
-
Plug in and boot up the Pi
-
On your computer open up the terminal
-
SSH into the Pi with username
piand passwordraspberryssh pi@192.168.2.1
Note: If you are having issues here, double-check your physical setup. It is surprisingly common to have a loose USB cable or ethernet adapter, and to become increasingly frustrated while myopically not understanding why software config isn't solving your hardware problem. ;)
You only need to do this if you Pi is not already connected to the internet via ethernet
-
sudo nano /etc/network/interfaces
-
Replace the content of the file with the following (replacing the appropriate SSID and password):
auto lo iface lo inet loopback allow-hotplug eth0 iface eth0 inet dhcp allow-hotplug wlan0 iface wlan0 inet dhcp wpa-ssid "YOUR_SSID" wpa-psk "YOUR_PASSWORD" -
sudo ifdown wlan0
-
sudo ifup wlan0 --- If you cannot get an IP address assigned check the SSID and password again, this seems to be the main problem
-
confirm you can see the wider Internet --- ping www.google.com
Reason This is useful if you're tethering your laptop through a bluetooth or wired internet connection.
Method
- Connect mac to internet via some way that's not direct ethernet or Wi-Fi
- Turn on Wi-Fi internet sharing in System Preferences -> Sharing, make the network settings something pretty simple
- SSH to the Pi through ethernet using the steps above
- Set up the /etc/interface/networking file to connect to the Wi-Fi network your computer is creating
- Follow the steps laied out.
If you can plug your Pi directly into a router with internet access, use this method
Reason Simpler setup and easier testing because you don't need to direct connect through your computer
Method
- Instead of connecting ethernet to your computer and the Pi, connect the Pi directly to an available ethernet port on your router
- Examine your router's DHCP table to determine which address the Pi has been assigned
- SSH in through the Pi's IP
Potential Issues
- Public or workplace networks may firewall each individual device and you won't be able to SSH between the devices
- If you don't have access to the DHCP logs you can't tell which IP the Pi has been assigned (unless you can plug in a monitor and log in directly)
With all of the attention being paid to IoT (and how the "S" in that acronym stands for "security" hehe), it is in our best interest to change the default password. After ssh'ing into the pi:
- sudo raspi-config
- navigate to
Change User Password - enter and confirm a new password
- Choose
Finishfrom the main menu, and reboot if you are done with all config
If you have many devices connected to a network, it can be useful (but still optional) to change the hostname to something meaningful. After ssh'ing into the pi:
- sudo raspi-config
- navigate to
Hostname - enter a hostname (e.g. LDLN_Base_Station_1)
- Choose
Finishfrom the main menu, and reboot if you are done with all config
The default boot options are not exactly optimized for LDLN. To update these, ssh into the pi, then:
- sudo raspi-config
- navigate to
Boot Options- navigate to
Desktop/CLI- choose
Console Autologin
- choose
- navigate to
- navigate to
Boot Options- navigate to
Wait for Network at Boot- choose
No
- choose
- navigate to
- Choose
Finishfrom the main menu, and reboot if you are done with all config
Fulfill all unused portion of the disk:
- sudo raspi-config
- Navigate to
Advanced Options- Navigate to
Expand Filesystem
- Navigate to
- Choose
Finishfrom the main menu, and reboot if you are done with all config
OR Set a custom partition size: https://raspberrypi.stackexchange.com/questions/499/how-can-i-resize-my-root-partition
You might want to consider setting a custom size if you are creating a base image.
Debian Stretched decided to make network device names dependent on MAC addresses. This is dumb unless you're running large servers with a lot of ethernet interfaces. Since everything breaks otherwise we change it back here.
- sudo nano /boot/cmdline.txt
- add
net.ifnames=0to the end of the top line - sudo reboot now
- sudo apt-get update (note if you're having issues with the mirror servers, see this post on how to update your apt-get servers to something more reliable; namely, change the url in
/etc/apt/sources.listto one of these and add Google's DNS servers to/etc/resolv.conf) - sudo apt-get install isc-dhcp-server libnss-mdns libssl-dev openssl
Follow only one of the three following blocks of instructions (a, b, or c) depending on your dongle.
Adopted from this: https://frillip.com/using-your-raspberry-pi-3-as-a-wifi-access-point-with-hostapd/
- sudo apt-get install hostapd
- sudo nano /etc/dhcpcd.conf
- Add to the bottom of the file (but ABOVE any 'INTERFACE' line):
denyinterfaces wlan0
- Download hostapd: wget https://github.com/jenssegers/RTL8188-hostapd/archive/v1.1.tar.gz
- See all releases: https://github.com/jenssegers/RTL8188-hostapd/releases
- tar -zxvf v1.1.tar.gz
- cd RTL8188-hostapd-1.1/hostapd
- sudo apt-get install libnl-3-dev libnl-genl-3-dev
- Look for the latest build of hostapd at http://w1.fi/hostapd/ (which is 2.6 at the time of writing)
- wget http://w1.fi/releases/hostapd-x.y.z.tar.gz
- tar -xzvf hostapd-x.y.z.tar.gz
- cd hostapd-x.y.z/hostapd
- cp defconfig .config
- vi .config
- uncomment
#CONFIG_DRIVER_NL80211=y - uncomment
#CONFIG_LIBNL32=y
- sudo make
- sudo make install
-
sudo nano /etc/init.d/hostapdto make sureDAEMON_SBINis pointing to the correct binary (e.g. your make installed installation may have gone to/usr/local/bin/hostapdrather than the default of/usr/sbin, which will affect the daemon starting on boot!)
Useful tip for debugging hostapd config: http://unix.stackexchange.com/a/123515 Useful walkthroughs for working with additional dongles that don't fit the instructions above: https://wireless.wiki.kernel.org/en/users/Documentation/hostapd and http://askubuntu.com/questions/617973/fatal-error-netlink-genl-genl-h-no-such-file-or-directory/617991
sudo nano /etc/default/hostapd
Put in:
RUN_DAEMON="yes"
DAEMON_CONF="/etc/hostapd/hostapd.conf"
DAEMON_OPTS="-dd"
sudo update-rc.d hostapd defaults
sudo update-rc.d hostapd enable
- Edit the DHCPD config file
- sudo nano /etc/dhcp/dhcpd.conf
- comment out the following two lines --- option domain-name "example.org"; --- option domain-name-servers ns1.example.org, ns2.example.org;
- uncomment the following line --- #authoritative
- at the end of the file add the following
subnet 192.168.0.0 netmask 255.255.255.0 {
range 192.168.0.10 192.168.0.150;
option broadcast-address 192.168.0.255;
option routers 192.168.0.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local-network";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}
-
sudo nano /etc/default/isc-dhcp-server
-
add line to the end of the file
INTERFACESv4="wlan0" -
sudo nano /etc/sysctl.conf
-
uncomment line starting with
#net.ipv4.ip_forward=1
- sudo ifdown wlan0
- sudo nano /etc/network/interfaces
- replace file with the following
auto lo
iface lo inet loopback
iface eth0 inet dhcp
post-up /sbin/iptables-restore < /etc/iptables-up.rules
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.0.1
netmask 255.255.255.0
For Raspberry Pi 3 you may try adding the following lines
network 192.168.0.0
broadcast 192.168.0.255
- sudo nano /etc/hostapd/hostapd.conf
- edit line starting with
ssid=tossid=LDLN - edit line starting with
wpa_passphrase=towpa_passphrase=landline
If the hostapd.conf doesn't exist:
- sudo mkdir /etc/hostapd
- sudo nano /etc/hostapd/hostapd.conf
- replace it with the following
interface=wlan0
driver=nl80211
ssid=LDLN
hw_mode=g
channel=6
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=My_Passphrase
wpa_key_mgmt=WPA-PSK
#wpa_pairwise=TKIP # You better do not use this weak encryption (only used by $
rsn_pairwise=CCMP
For Raspberry Pi 3 it may work to look like this
# This is the name of the WiFi interface we configured above
interface=wlan0
# Use the nl80211 driver with the brcmfmac driver
driver=nl80211
# This is the name of the network
ssid=Pi3-AP
# Use the 2.4GHz band
hw_mode=g
# Use channel 6
channel=6
# Enable 802.11n
ieee80211n=1
# Enable WMM
wmm_enabled=1
# Enable 40MHz channels with 20ns guard interval
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
# Accept all MAC addresses
macaddr_acl=0
# Use WPA authentication
auth_algs=1
# Use WPA2
wpa=2
# The network passphrase
wpa_passphrase=landline
Useful tip for debugging hostapd config: http://unix.stackexchange.com/a/123515
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo ifup wlan0
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
sudo su
iptables-save > /etc/iptables-up.rules
exit
sudo su
iptables-save
exit
sudo apt-get install iptables-persistent
It will then ask you if you want to save current settings, say 'yes'
If you need to resave tables you can do this
sudo netfilter-persistent save
- sudo service isc-dhcp-server start
- sudo service hostapd start
The Wi-Fi network LDLN should now be visible if you look for it
See: https://github.com/LDLN/core/wiki/LDLN-Stack-Installation
sudo nano /etc/init.d/access-point.sh
Put in:
#!/bin/bash
## BEGIN INIT INFO
# Provides: some_name
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start access point daemons at boot time
# Description: Enable service provided by daemon.
## END INIT INFO
# start access point - is this still needed?
# service hostapd start
# bring up the wi-fi, otherwise the dhcp server errors out
ifup wlan0
# bring up ethernet interface
ifup eth0
# start dhcp
service isc-dhcp-server start
-
Make executable and add to startup:
sudo chmod +x /etc/init.d/access-point.sh sudo update-rc.d access-point.sh defaults -
Test to ensure it works:
sudo /etc/init.d/access-point.sh
If you didn't already update the hostname in raspi-config in the earlier steps, you can do it here.
Replace raspberrypi with landline in these files:
sudo nano /etc/hosts
sudo nano /etc/hostname
Commit the changes:
sudo /etc/init.d/hostname.sh
sudo reboot
- Reboot -- sudo shutdown -r now
- Create instruction to download source files, copy them to the Pi and install locally. -- This will be a way to setup from a usb stick or a direct file copy so the Pi never needs to touch the internet itself
http://raspberrypihq.com/how-to-turn-a-raspberry-pi-into-a-wifi-router/