Raspberry Pi: Difference between revisions
Jump to navigation
Jump to search
(8 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== References == |
|||
* Buy Raspberry pi at [https://www.modmypi.com/shop modmypi.com]. |
|||
;Install Raspbian |
|||
* Use etcher to write Raspbian image on disk. |
|||
* Boot image as is. Do not expand image! This will be done at first boot. |
|||
;Find the pi |
|||
<source lang=bash> |
|||
ping raspberrypi.local |
|||
</source> |
|||
;Enable SSH |
|||
* Mount SD card |
|||
* Create a file {{file|ssh}} on boot partition [https://raspberrypi.stackexchange.com/questions/40689/cannot-connect-to-raspbian-jessie-lite-but-to-raspbian-jessie]: |
|||
<source lang=bash> |
|||
touch /media/*/boot/ssh |
|||
</source> |
|||
;1st login |
|||
* User <code>pi</code>. |
|||
* Password <code>raspberry</code>. |
|||
* Sudo access without password. |
|||
;Configure |
|||
<source lang=bash> |
|||
sudo raspi-config |
|||
</source> |
|||
;Repositories |
|||
* http://legacy.raspbian.org/raspbian/ — Packages of old releases (Jessie...) |
|||
== Network == |
== Network == |
||
=== Detect all Raspberry Pi on local network === |
=== Detect all Raspberry Pi on local network === |
||
Line 26: | Line 54: | ||
sudo nmap -sP 172.19.2.0/23 | awk '/^Nmap/{ip=$NF}/00:0F:13/{print ip}' |
sudo nmap -sP 172.19.2.0/23 | awk '/^Nmap/{ip=$NF}/00:0F:13/{print ip}' |
||
</source> |
</source> |
||
=== Setup WiFi === |
|||
Reference: |
|||
* [https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md Setting WiFi up via the command line] |
|||
The quickest way is to use raspi-config tool |
|||
<source lang="bash"> |
|||
sudo raspi-config |
|||
</source> |
|||
Otherwise, setting up WiFi is quite easy. |
|||
* First get the WiFi network details: |
|||
<source lang="bash"> |
|||
sudo iwlist wlan0 scan |
|||
# wlan0 Scan completed : |
|||
# Cell 01 - Address: A1:B2:C3:D4:E5:F6 |
|||
# Channel:6 |
|||
# Frequency:2.437 GHz (Channel 6) |
|||
# Quality=69/70 Signal level=-41 dBm |
|||
# Encryption key:off |
|||
# ESSID:"testing" |
|||
# Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s |
|||
# 24 Mb/s; 36 Mb/s; 54 Mb/s |
|||
# Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s |
|||
</source> |
|||
* Create a new <code>network</code> entry in {{file|/etc/wpa_supplicant/wpa_supplicant.conf}} |
|||
<source lang="text"> |
|||
network={ |
|||
ssid="testing" |
|||
psk="testingPassword" |
|||
} |
|||
</source> |
|||
:Better yet, use <code>wpa_passphrase</code> to generate an encrypted PSK: |
|||
<source lang="bash"> |
|||
wpa_passphrase testing >> sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null |
|||
sudo vi /etc/wpa_supplicant/wpa_supplicant.conf |
|||
# network={ |
|||
# ssid="testing" |
|||
# #psk="testingPassword" <-- REMOVE THIS LINE!!! |
|||
# psk=131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531 |
|||
# } |
|||
</source> |
|||
:Remove the password from the output produced by <code>wpa_passphrase</code> for extra security. |
|||
* On Raspberry Pi 3 Model B+, set the country code in {{file|/etc/wpa_supplicant/wpa_supplicant.conf}} |
|||
<source lang="text"> |
|||
country=BE |
|||
</source> |
|||
* Reconfigure the interface |
|||
<source lang="bash"> |
|||
sudo wpa_cli -i wlan0 reconfigure |
|||
</source> |
|||
* Check interface configuration |
|||
<source lang="bash"> |
|||
ip addr show dev wlan0 |
|||
</source> |
|||
It is also possible to |
|||
* Configure multiple WiFi networks. |
|||
* Set a priority, eg. <code>priority=1</code>. |
|||
=== Setup Pi as WiFi HotSpot (router) === |
=== Setup Pi as WiFi HotSpot (router) === |
||
Line 37: | Line 125: | ||
=== Setup Pi as WiFi HotSpot (bridge) === |
=== Setup Pi as WiFi HotSpot (bridge) === |
||
(Updated for Debian Jessie - Raspberry Pi 3+ - See history for old method) |
|||
References: |
|||
* http://www.daveconroy.com/turn-your-raspberry-pi-into-a-wifi-hotspot-with-edimax-nano-usb-ew-7811un-rtl8188cus-chipset/ |
|||
;References |
|||
* https://david.meziere.eu/fr/reseau/le-point-dacces-wifi-bridge/ (main reference) |
|||
* http://antoine-schellenberger.com/linux/2014/12/14/tips_hostapd_bridge.html |
|||
* https://www.cyberciti.biz/faq/debian-ubuntu-linux-setting-wireless-access-point/ |
|||
* https://doc.ubuntu-fr.org/hostapd |
|||
* https://wireless.wiki.kernel.org/en/users/documentation/hostapd |
|||
;Install necessary packages |
|||
<source lang="bash"> |
|||
sudo apt install hostapd hostap-utils bridge-utils |
|||
</source> |
|||
;Configure eth0 / wlan0 / br0 interfaces |
|||
* Content of {{file|/etc/network/interfaces}} |
|||
<source lang="bash"> |
|||
# interfaces(5) file used by ifup(8) and ifdown(8) |
|||
# Please note that this file is written to be used with dhcpcd |
|||
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' |
|||
# Include files from /etc/network/interfaces.d: |
|||
source-directory /etc/network/interfaces.d |
|||
allow-auto lo |
|||
iface lo inet loopback |
|||
</source> |
|||
* Content of {{file|/etc/network/interfaces.d/eth0}} |
|||
<source lang="bash"> |
|||
# interfaces(5) file used by ifup(8) and ifdown(8) |
|||
allow-hotplug eth0 |
|||
iface eth0 inet dhcp |
|||
</source> |
|||
* Content of {{file|/etc/network/interfaces.d/wlan0}} |
|||
<source lang="bash"> |
|||
# interfaces(5) file used by ifup(8) and ifdown(8) |
|||
allow-hotplug wlan0 |
|||
iface wlan0 inet manual |
|||
</source> |
|||
* Content of {{file|/etc/network/interfaces.d/br0}} |
|||
<source lang="bash"> |
|||
# interfaces(5) file used by ifup(8) and ifdown(8) |
|||
allow-auto br0 |
|||
iface br0 inet dhcp |
|||
bridge_fd 1 |
|||
bridge_hello 3 |
|||
bridge_maxage 10 |
|||
bridge_stp off |
|||
bridge_ports eth0 wlan0 |
|||
</source> |
|||
* Restart network |
|||
<source lang="bash"> |
|||
sudo service networking restart # or |
|||
sudo systemctl restart networking |
|||
# Check new interfaces |
|||
ifconfig # or |
|||
ip addr |
|||
</source> |
|||
; Configure hostapd |
|||
* Enable conf file, {{file|/etc/default/hostapd}}: |
|||
<source lang="diff"> |
|||
-#DAEMON_CONF="" |
|||
+DAEMON_CONF="/etc/hostapd/hostapd.conf" |
|||
</source> |
|||
* Copy default configuration file |
|||
<source lang="bash"> |
|||
sudo cp /usr/share/doc/hostapd/examples/hostapd.conf.gz /etc/hostapd/ |
|||
cd /etc/hostapd/ |
|||
sudo gunzip hostapd.conf.gz |
|||
</source> |
|||
* Set the following variables |
|||
<source lang="bash"> |
|||
interface=wlan0 |
|||
bridge=br0 |
|||
ssid=<SSIDHERE> |
|||
country_code=BE |
|||
channel=4 |
|||
ignore_broadcast_ssid=1 # SSID will not be broadcasted |
|||
wpa=2 |
|||
wpa_passphrase=<PASSPHRASE_HERE> |
|||
wpa_key_mgmt=WPA-PSK |
|||
wpa_pairwise=CCMP |
|||
rsn_pairwise=CCMP |
|||
</source> |
|||
* Enable ipv4 forwarding |
|||
<source lang="bash"> |
|||
sudo sysctl -w net.ipv4.ip_forward=1 |
|||
sudo vi /etc/sysctl.conf |
|||
# net.ipv4.ip_forward=1 |
|||
</source> |
|||
* Restart hostapd |
|||
<source lang="bash"> |
|||
sudo systemctl restart hostapd |
|||
</source> |
|||
=== Disable HDMI CEC / Anynet+ === |
|||
Add to {{file|/boot/config.txt}} [https://www.raspberrypi.org/forums/viewtopic.php?t=26302]: |
|||
hdmi_ignore_cec=1 |
|||
== Troubleshoot == |
== Troubleshoot == |
Latest revision as of 11:28, 29 April 2022
References
- Buy Raspberry pi at modmypi.com.
- Install Raspbian
- Use etcher to write Raspbian image on disk.
- Boot image as is. Do not expand image! This will be done at first boot.
- Find the pi
ping raspberrypi.local
- Enable SSH
- Mount SD card
- Create a file ssh on boot partition [1]:
touch /media/*/boot/ssh
- 1st login
- User
pi
. - Password
raspberry
. - Sudo access without password.
- Configure
sudo raspi-config
- Repositories
- http://legacy.raspbian.org/raspbian/ — Packages of old releases (Jessie...)
Network
Detect all Raspberry Pi on local network
From [2].
sudo nmap -sP 192.168.1.0/24 | awk '/^Nmap/{ip=$NF}/B8:27:EB/{print ip}'
where 192.168.1.*
will be your local network mask.
We can also simply look for string Raspberry
since nmap
correctly identifies pi mac address:
sudo nmap -sP 192.168.1.0/24 | grep -B2 Raspberry
where 192.168.1.*
will be your local network mask.
- Raspberry in BRIDGE mode
- Methods above fail if Raspberry is setup to bridge wlan0-eth0 connections. In that case, the visible MAC address is the one of the wlan0 interface. It can be detected because the address will be reported twice:
sudo nmap -sP 172.19.2.0/23|sort|uniq -d
# Host is up (0.18s latency).
# MAC Address: 00:0F:13:05:46:C2 (Nisca) <-- MAC address of the Pi in bridge mode
# MAC Address: 80:86:F2:99:56:B5 (Intel Corporate)
- Now we can repeat the request above to get the IP address:
sudo nmap -sP 172.19.2.0/23 | awk '/^Nmap/{ip=$NF}/00:0F:13/{print ip}'
Setup WiFi
Reference:
The quickest way is to use raspi-config tool
sudo raspi-config
Otherwise, setting up WiFi is quite easy.
- First get the WiFi network details:
sudo iwlist wlan0 scan
# wlan0 Scan completed :
# Cell 01 - Address: A1:B2:C3:D4:E5:F6
# Channel:6
# Frequency:2.437 GHz (Channel 6)
# Quality=69/70 Signal level=-41 dBm
# Encryption key:off
# ESSID:"testing"
# Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
# 24 Mb/s; 36 Mb/s; 54 Mb/s
# Bit Rates:6 Mb/s; 9 Mb/s; 12 Mb/s; 48 Mb/s
- Create a new
network
entry in /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="testing"
psk="testingPassword"
}
- Better yet, use
wpa_passphrase
to generate an encrypted PSK:
wpa_passphrase testing >> sudo tee -a /etc/wpa_supplicant/wpa_supplicant.conf > /dev/null
sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
# network={
# ssid="testing"
# #psk="testingPassword" <-- REMOVE THIS LINE!!!
# psk=131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531
# }
- Remove the password from the output produced by
wpa_passphrase
for extra security.
- On Raspberry Pi 3 Model B+, set the country code in /etc/wpa_supplicant/wpa_supplicant.conf
country=BE
- Reconfigure the interface
sudo wpa_cli -i wlan0 reconfigure
- Check interface configuration
ip addr show dev wlan0
It is also possible to
- Configure multiple WiFi networks.
- Set a priority, eg.
priority=1
.
Setup Pi as WiFi HotSpot (router)
This setup the Pi has a WiFi access point (AP) in router mode (NAT).
References:
- https://learn.adafruit.com/downloads/pdf/setting-up-a-raspberry-pi-as-a-wifi-access-point.pdf — THIS METHOD WORKS
- https://learn.adafruit.com/setting-up-a-raspberry-pi-as-a-wifi-access-point/overview
- http://blog.sip2serve.com/post/48420162196/howto-setup-rtl8188cus-on-rpi-as-an-access-point
- http://blog.sip2serve.com/post/48899893167/rtl8188-access-point-install-script
Setup Pi as WiFi HotSpot (bridge)
(Updated for Debian Jessie - Raspberry Pi 3+ - See history for old method)
- References
- https://david.meziere.eu/fr/reseau/le-point-dacces-wifi-bridge/ (main reference)
- http://antoine-schellenberger.com/linux/2014/12/14/tips_hostapd_bridge.html
- https://www.cyberciti.biz/faq/debian-ubuntu-linux-setting-wireless-access-point/
- https://doc.ubuntu-fr.org/hostapd
- https://wireless.wiki.kernel.org/en/users/documentation/hostapd
- Install necessary packages
sudo apt install hostapd hostap-utils bridge-utils
- Configure eth0 / wlan0 / br0 interfaces
- Content of /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
allow-auto lo
iface lo inet loopback
- Content of /etc/network/interfaces.d/eth0
# interfaces(5) file used by ifup(8) and ifdown(8)
allow-hotplug eth0
iface eth0 inet dhcp
- Content of /etc/network/interfaces.d/wlan0
# interfaces(5) file used by ifup(8) and ifdown(8)
allow-hotplug wlan0
iface wlan0 inet manual
- Content of /etc/network/interfaces.d/br0
# interfaces(5) file used by ifup(8) and ifdown(8)
allow-auto br0
iface br0 inet dhcp
bridge_fd 1
bridge_hello 3
bridge_maxage 10
bridge_stp off
bridge_ports eth0 wlan0
- Restart network
sudo service networking restart # or
sudo systemctl restart networking
# Check new interfaces
ifconfig # or
ip addr
- Configure hostapd
- Enable conf file, /etc/default/hostapd:
-#DAEMON_CONF=""
+DAEMON_CONF="/etc/hostapd/hostapd.conf"
- Copy default configuration file
sudo cp /usr/share/doc/hostapd/examples/hostapd.conf.gz /etc/hostapd/
cd /etc/hostapd/
sudo gunzip hostapd.conf.gz
- Set the following variables
interface=wlan0
bridge=br0
ssid=<SSIDHERE>
country_code=BE
channel=4
ignore_broadcast_ssid=1 # SSID will not be broadcasted
wpa=2
wpa_passphrase=<PASSPHRASE_HERE>
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
- Enable ipv4 forwarding
sudo sysctl -w net.ipv4.ip_forward=1
sudo vi /etc/sysctl.conf
# net.ipv4.ip_forward=1
- Restart hostapd
sudo systemctl restart hostapd
Disable HDMI CEC / Anynet+
Add to /boot/config.txt [3]:
hdmi_ignore_cec=1
Troubleshoot
403 Forbidden when apt-get upgrade
From [4]:
Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main libc-dev-bin armhf 2.13-38+rpi2+deb7u8
403 Forbidden
Err http://mirrordirector.raspbian.org/raspbian/ wheezy/main libc6-dev armhf 2.13-38+rpi2+deb7u8
403 Forbidden
Edit /etc/apt/apt.conf:
-deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
+#deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
+deb http://archive.raspbian.org/raspbian wheezy main contrib non-free
+deb-src http://archive.raspbian.org/raspbian wheezy main contrib non-free