Prototyping for Habitat: Difference between revisions

From XPUB & Lens-Based wiki
Line 69: Line 69:
  hostname.local
  hostname.local
  hostname.lan
  hostname.lan
==Set Up the Raspberry Pi as a local Wi-Fi Access point==
===Install AP and Management Software===
1. In order to work as an access point
sudo apt install hostapd
2. Enable the wireless access point service and set it to start when your Raspberry Pi boots:
sudo systemctl unmask hostapd
sudo systemctl enable hostapd
3. To provide network management services (DNS, DHCP) to wireless clients:
sudo apt install dnsmasq
4. To help saving firewall rules and restoring them when the Raspberry Pi boots:
sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent
===Set up the Network Router===
The Raspberry Pi will run and manage a standalone wireless network. It will also route between the wireless and Ethernet networks, providing internet access to wireless clients. If you prefer, you can choose to skip the routing by skipping the section "Enable routing and IP masquerading" below, and run the wireless network in complete isolation.
1. To configure the static IP address, edit the configuration file for <code>dhcpcd</code> with:
sudo nano /etc/dhcpcd.conf
Go to the end of the file and add the following:
interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant
---Even if not necessary, my Raspberry Pi worked only after running the codes in this section--- <br>
3. Enable Routing and IP Masquerading
This section configures the Raspberry Pi to let wireless clients access computers on the main (Ethernet) network, and from there the internet.
sudo nano /etc/sysctl.d/routed-ap.conf
Add:
# Enable IPv4 routing
net.ipv4.ip_forward=1
4. Enabling routing to allow hosts from network <code>192.168.4.0/24 </code> to reach the LAN and the main router towards the internet.
Run
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Then
sudo netfilter-persistent save
-------------------------------------------------------------------------------------------------

Revision as of 15:48, 18 November 2021

Raspberry Installation

Raspberry Pi documentation → https://www.raspberrypi.com/documentation/computers/configuration.html

I followed this guide: → https://pzwiki.wdka.nl/mediadesign/The_Ultimate_RPi_Installation_Guide
1. Download an OS image file

2. Put image on SD Card

  • Open terminal
  • Find the disk that you are going to write to
diskutil list
  • Find the disk /dev/disk<number>
  • You need to unmount the SD Card before imaging
sudo diskutil unmountDisk /dev/disk<number>
  • Then to image the disk with your image put in the following command
sudo dd bs=4m if=/path/to/your/image.img of=/dev/rdisk<number>

3. Enable SSH on the Pi

With a screen + keyboard

  • Connect the Pi to a screen and keyboard.
  • Run: sudo raspi-config
  • Select Interfacing Options
  • Navigate to and select SSH
  • Choose Yes
  • Select Ok
  • Choose Finish


4. put the SD card back in the Pi and boot it up


5. Login into the Pi, using the ip address of the pi, or using the hostname of the machine.

ssh root@192.168.1.73
ssh pi@192.168.2.15
ssh pi@raspberrypi.local

6. Change the hostname (the name of the Pi)

You can change this name, by editing these two files:

sudo nano /etc/hostname
sudo nano /etc/hosts

Change /etc/hosts into:

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters
127.0.1.1       habitat

Reboot the Pi after you made these changes!

7. Reach your Pi using its hostname

You can use the hostname to ssh into the Pi, if you are in the same local network as your Pi:

ssh username@hostname.local

You can use this hostname also in the browser, to access the webserver on the Pi. Try to visit:

hostname.local
hostname.lan


Set Up the Raspberry Pi as a local Wi-Fi Access point

Install AP and Management Software

1. In order to work as an access point

sudo apt install hostapd

2. Enable the wireless access point service and set it to start when your Raspberry Pi boots:

sudo systemctl unmask hostapd
sudo systemctl enable hostapd

3. To provide network management services (DNS, DHCP) to wireless clients:

sudo apt install dnsmasq

4. To help saving firewall rules and restoring them when the Raspberry Pi boots:

sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent

Set up the Network Router

The Raspberry Pi will run and manage a standalone wireless network. It will also route between the wireless and Ethernet networks, providing internet access to wireless clients. If you prefer, you can choose to skip the routing by skipping the section "Enable routing and IP masquerading" below, and run the wireless network in complete isolation.

1. To configure the static IP address, edit the configuration file for dhcpcd with:

sudo nano /etc/dhcpcd.conf

Go to the end of the file and add the following:

interface wlan0
static ip_address=192.168.4.1/24
nohook wpa_supplicant

---Even if not necessary, my Raspberry Pi worked only after running the codes in this section---
3. Enable Routing and IP Masquerading This section configures the Raspberry Pi to let wireless clients access computers on the main (Ethernet) network, and from there the internet.

sudo nano /etc/sysctl.d/routed-ap.conf

Add:

# Enable IPv4 routing
net.ipv4.ip_forward=1

4. Enabling routing to allow hosts from network 192.168.4.0/24 to reach the LAN and the main router towards the internet.

Run

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Then

sudo netfilter-persistent save