Prototyping for Habitat: Difference between revisions
(Created page with "==Raspberry Installation== → https://pzwiki.wdka.nl/mediadesign/The_Ultimate_RPi_Installation_Guide <br> 1. Download an OS image file * RASPBIAN: https://www.raspberrypi.org...") |
|||
(19 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[File:pongiepi.jpeg|right]] | |||
==Raspberry Installation== | ==Raspberry Installation== | ||
Raspberry Pi documentation → https://www.raspberrypi.com/documentation/computers/configuration.html<br><br> | |||
I followed this guide: | |||
→ https://pzwiki.wdka.nl/mediadesign/The_Ultimate_RPi_Installation_Guide <br> | → https://pzwiki.wdka.nl/mediadesign/The_Ultimate_RPi_Installation_Guide <br> | ||
1. Download an OS image file | 1. '''Download an OS image file''' | ||
* RASPBIAN: https://www.raspberrypi.org/software/operating-systems/ | * RASPBIAN: https://www.raspberrypi.org/software/operating-systems/ | ||
2. Put image on SD Card | 2. '''Put image on SD Card''' | ||
* Open terminal | * Open terminal | ||
Line 15: | Line 21: | ||
sudo dd bs=4m if=/path/to/your/image.img of=/dev/rdisk<number> | sudo dd bs=4m if=/path/to/your/image.img of=/dev/rdisk<number> | ||
3. Enable SSH on the Pi | 3. '''Enable SSH on the Pi''' | ||
With a screen + keyboard | ''With a screen + keyboard'' | ||
* Connect the Pi to a screen and keyboard. | * Connect the Pi to a screen and keyboard. | ||
* Run: sudo raspi-config | * Run: <code>sudo raspi-config</code> | ||
* Select Interfacing Options | * Select <code>Interfacing Options</code> | ||
* Navigate to and select SSH | * Navigate to and select <code>SSH</code> | ||
* Choose Yes | * Choose <code>Yes</code> | ||
* Select Ok | * Select <code>Ok</code> | ||
* Choose Finish | * Choose <code>Finish</code> | ||
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 <code>/etc/hosts</code> 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 <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><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 | |||
------------------------------------------------------------------------------------------------- | |||
------------------------------------------------------------------------------------------------- | |||
------------------------------------------------------------------------------------------------- | |||
------------------------------------------------------------------------------------------------- | |||
------------------------------------------------------------------------------------------------- | |||
------------------------------------------------------------------------------------------------- | |||
===Configure the DHCP and DNS services for the wireless network=== | |||
The DHCP and DNS services are provided by dnsmasq. The default configuration file serves as a template for all possible configuration options, whereas we only need a few. It is easier to start from an empty file. | |||
Rename the default configuration file and edit a new one: | |||
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig | |||
sudo nano /etc/dnsmasq.conf | |||
Add the following to the file and save it: | |||
interface=wlan0 # Listening interface | |||
dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h | |||
# Pool of IP addresses served via DHCP | |||
domain=wlan # Local wireless DNS domain | |||
address=/gw.wlan/192.168.4.1 | |||
# Alias for this router | |||
===Ensure Wireless Operation=== | |||
To ensure WiFi radio is not blocked on your Raspberry Pi, execute the following command: | |||
sudo rfkill unblock wlan | |||
===Configure the AP Software=== | |||
Create the hostapd configuration file, located at /etc/hostapd/hostapd.conf, to add the various parameters for your new wireless network. | |||
sudo nano /etc/hostapd/hostapd.conf | |||
Add: | |||
country_code=NL | |||
interface=wlan0 | |||
ssid='''habitat''' | |||
hw_mode=g | |||
channel=7 | |||
macaddr_acl=0 | |||
auth_algs=1 | |||
ignore_broadcast_ssid=0 | |||
wpa=2 | |||
wpa_passphrase='''my-pswd''' | |||
wpa_key_mgmt=WPA-PSK | |||
wpa_pairwise=TKIP | |||
rsn_pairwise=CCMP | |||
===Reboot=== | |||
sudo systemctl reboot |
Latest revision as of 15:57, 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
Configure the DHCP and DNS services for the wireless network
The DHCP and DNS services are provided by dnsmasq. The default configuration file serves as a template for all possible configuration options, whereas we only need a few. It is easier to start from an empty file.
Rename the default configuration file and edit a new one:
sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.orig sudo nano /etc/dnsmasq.conf
Add the following to the file and save it:
interface=wlan0 # Listening interface dhcp-range=192.168.4.2,192.168.4.20,255.255.255.0,24h # Pool of IP addresses served via DHCP domain=wlan # Local wireless DNS domain address=/gw.wlan/192.168.4.1 # Alias for this router
Ensure Wireless Operation
To ensure WiFi radio is not blocked on your Raspberry Pi, execute the following command:
sudo rfkill unblock wlan
Configure the AP Software
Create the hostapd configuration file, located at /etc/hostapd/hostapd.conf, to add the various parameters for your new wireless network.
sudo nano /etc/hostapd/hostapd.conf
Add:
country_code=NL interface=wlan0 ssid=habitat hw_mode=g channel=7 macaddr_acl=0 auth_algs=1 ignore_broadcast_ssid=0 wpa=2 wpa_passphrase=my-pswd wpa_key_mgmt=WPA-PSK wpa_pairwise=TKIP rsn_pairwise=CCMP
Reboot
sudo systemctl reboot