Raspberry Pi: Difference between revisions
Jump to navigation
Jump to search
(3 intermediate revisions by the same user not shown) | |||
Line 23: | Line 23: | ||
sudo raspi-config |
sudo raspi-config |
||
</source> |
</source> |
||
;Repositories |
|||
* http://legacy.raspbian.org/raspbian/ — Packages of old releases (Jessie...) |
|||
== Network == |
== Network == |
||
Line 122: | 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 |
|||
<source lang="diff"> |
|||
* https://david.meziere.eu/fr/reseau/le-point-dacces-wifi-bridge/ (main reference) |
|||
diff --git a/default/hostapd b/default/hostapd |
|||
* http://antoine-schellenberger.com/linux/2014/12/14/tips_hostapd_bridge.html |
|||
index 1e12174..5783c15 100644 |
|||
* https://www.cyberciti.biz/faq/debian-ubuntu-linux-setting-wireless-access-point/ |
|||
--- a/default/hostapd |
|||
* https://doc.ubuntu-fr.org/hostapd |
|||
* https://wireless.wiki.kernel.org/en/users/documentation/hostapd |
|||
@@ -7,7 +7,7 @@ |
|||
# file and hostapd will be started during system boot. An example configuration |
|||
;Install necessary packages |
|||
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz |
|||
<source lang="bash"> |
|||
# |
|||
sudo apt install hostapd hostap-utils bridge-utils |
|||
-#DAEMON_CONF="" |
|||
</source> |
|||
+DAEMON_CONF="/etc/hostapd/hostapd.conf" |
|||
;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 |
|||
# Additional daemon options to be appended to hostapd command:- |
|||
iface br0 inet dhcp |
|||
# -d show more debug messages (-dd for even more) |
|||
bridge_fd 1 |
|||
diff --git a/default/isc-dhcp-server b/default/isc-dhcp-server |
|||
bridge_hello 3 |
|||
index df30daa..ec7fb5a 100644 |
|||
bridge_maxage 10 |
|||
--- a/default/isc-dhcp-server |
|||
bridge_stp off |
|||
+++ b/default/isc-dhcp-server |
|||
bridge_ports eth0 wlan0 |
|||
@@ -18,4 +18,4 @@ |
|||
# On what interfaces should the DHCP server (dhcpd) serve DHCP requests? |
|||
# Separate multiple interfaces with spaces, e.g. "eth0 eth1". |
|||
-INTERFACES="" |
|||
+INTERFACES="wlan0" |
|||
diff --git a/dhcp/dhcpd.conf b/dhcp/dhcpd.conf |
|||
index e4368e7..cff23f9 100644 |
|||
--- a/dhcp/dhcpd.conf |
|||
+++ b/dhcp/dhcpd.conf |
|||
@@ -10,15 +10,15 @@ |
|||
ddns-update-style none; |
|||
# option definitions common to all supported networks... |
|||
-option domain-name "example.org"; |
|||
-option domain-name-servers ns1.example.org, ns2.example.org; |
|||
+#option domain-name "example.org"; |
|||
+#option domain-name-servers ns1.example.org, ns2.example.org; |
|||
default-lease-time 600; |
|||
max-lease-time 7200; |
|||
# If this DHCP server is the official DHCP server for the local |
|||
# network, the authoritative directive should be uncommented. |
|||
-#authoritative; |
|||
+authoritative; |
|||
# Use this to send dhcp log messages to a different log file (you also |
|||
# have to hack syslog.conf to complete the redirection). |
|||
@@ -105,3 +105,17 @@ log-facility local7; |
|||
# range 10.0.29.10 10.0.29.230; |
|||
# } |
|||
#} |
|||
+ |
|||
+subnet 192.168.42.0 netmask 255.255.255.0 { |
|||
+ range 192.168.42.10 192.168.42.50; |
|||
+ option broadcast-address 192.168.42.255; |
|||
+ option routers 192.168.42.1; |
|||
+ default-lease-time 600; |
|||
+ max-lease-time 7200; |
|||
+ option domain-name "local"; |
|||
+ # option domain-name-servers 8.8.8.8, 8.8.4.4; |
|||
+ option domain-name-servers 164.129.147.251, 10.129.252.253; |
|||
+} |
|||
+ |
|||
+ |
|||
+ |
|||
diff --git a/hostapd/hostapd.conf b/hostapd/hostapd.conf |
|||
new file mode 100644 |
|||
index 0000000..1ee2984 |
|||
--- /dev/null |
|||
+++ b/hostapd/hostapd.conf |
|||
@@ -0,0 +1,13 @@ |
|||
+interface=wlan0 |
|||
+driver=rtl871xdrv |
|||
+ssid=TESTMOBILE |
|||
+hw_mode=g |
|||
+channel=8 |
|||
+macaddr_acl=0 |
|||
+auth_algs=1 |
|||
+ignore_broadcast_ssid=1 |
|||
+wpa=2 |
|||
+wpa_passphrase=Framb0ise |
|||
+wpa_key_mgmt=WPA-PSK |
|||
+wpa_pairwise=TKIP |
|||
+rsn_pairwise=CCMP |
|||
diff --git a/iptables.ipv4.nat b/iptables.ipv4.nat |
|||
new file mode 100644 |
|||
index 0000000..3991461 |
|||
--- /dev/null |
|||
+++ b/iptables.ipv4.nat |
|||
@@ -0,0 +1,18 @@ |
|||
+# Generated by iptables-save v1.4.14 on Mon Apr 27 09:39:52 2015 |
|||
+*nat |
|||
+:PREROUTING ACCEPT [7:840] |
|||
+:INPUT ACCEPT [7:840] |
|||
+:OUTPUT ACCEPT [2:133] |
|||
+:POSTROUTING ACCEPT [0:0] |
|||
+-A POSTROUTING -o eth0 -j MASQUERADE |
|||
+COMMIT |
|||
+# Completed on Mon Apr 27 09:39:52 2015 |
|||
+# Generated by iptables-save v1.4.14 on Mon Apr 27 09:39:52 2015 |
|||
+*filter |
|||
+:INPUT ACCEPT [99:8128] |
|||
+:FORWARD ACCEPT [0:0] |
|||
+:OUTPUT ACCEPT [54:6210] |
|||
+-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT |
|||
+-A FORWARD -i wlan0 -o eth0 -j ACCEPT |
|||
+COMMIT |
|||
+# Completed on Mon Apr 27 09:39:52 2015 |
|||
diff --git a/network/interfaces b/network/interfaces |
|||
index 99135c9..a3c1b53 100644 |
|||
--- a/network/interfaces |
|||
+++ b/network/interfaces |
|||
@@ -3,13 +3,29 @@ auto lo |
|||
iface lo inet loopback |
|||
iface eth0 inet dhcp |
|||
-auto wlan0 |
|||
-allow-hotplug wlan0 |
|||
-iface wlan0 inet manual |
|||
-wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf |
|||
- |
|||
-iface home inet static |
|||
- address 172.19.100.107 |
|||
- netmask 255.255.0.0 |
|||
- gateway 172.19.3.1 |
|||
+# auto config for home network |
|||
+# ---------------------------- |
|||
+# auto wlan0 |
|||
+# allow-hotplug wlan0 |
|||
+# iface wlan0 inet manual |
|||
+# wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf |
|||
+# |
|||
+#iface home inet static |
|||
+# address 172.19.100.107 |
|||
+# netmask 255.255.0.0 |
|||
+# gateway 172.19.3.1 |
|||
+ |
|||
+# Config for wifi hotspot |
|||
+# ----------------------- |
|||
+#allow-hotplug wlan0 |
|||
+#iface wlan0 inet static |
|||
+# address 192.168.42.1 |
|||
+# netmask 255.255.255.0 |
|||
+# |
|||
+#up iptables-restore < /etc/iptables.ipv4.nat |
|||
+ |
|||
+# Config for bridged mode |
|||
+auto br0 |
|||
+iface br0 inet dhcp |
|||
+bridge_ports eth0 wlan0 |
|||
diff --git a/sysctl.conf b/sysctl.conf |
|||
index 52e7256..3f57b5c 100644 |
|||
--- a/sysctl.conf |
|||
+++ b/sysctl.conf |
|||
@@ -25,7 +25,7 @@ kernel.printk = 3 4 1 3 |
|||
#net.ipv4.tcp_syncookies=1 |
|||
# Uncomment the next line to enable packet forwarding for IPv4 |
|||
-#net.ipv4.ip_forward=1 |
|||
+net.ipv4.ip_forward=1 |
|||
# Uncomment the next line to enable packet forwarding for IPv6 |
|||
# Enabling this option disables Stateless Address Autoconfiguration |
|||
</source> |
</source> |
||
* Restart network |
|||
<source lang="bash"> |
|||
sudo service networking restart # or |
|||
sudo systemctl restart networking |
|||
# Check new interfaces |
|||
The following changes might be required as well: |
|||
ifconfig # or |
|||
ip addr |
|||
</source> |
|||
; Configure hostapd |
|||
* Enable conf file, {{file|/etc/default/hostapd}}: |
|||
<source lang="diff"> |
<source lang="diff"> |
||
-#DAEMON_CONF="" |
|||
diff --git a/default/hostapd b/default/hostapd |
|||
+DAEMON_CONF="/etc/hostapd/hostapd.conf" |
|||
index 5783c15..1d640ee 100644 |
|||
--- a/default/hostapd |
|||
+++ b/default/hostapd |
|||
@@ -17,4 +17,4 @@ DAEMON_CONF="/etc/hostapd/hostapd.conf" |
|||
# Note that -B (daemon mode) and -P (pidfile) options are automatically |
|||
# configured by the init.d script and must not be added to DAEMON_OPTS. |
|||
# |
|||
-#DAEMON_OPTS="" |
|||
+DAEMON_OPTS="-d -dd" |
|||
diff --git a/rc.local b/rc.local |
|||
index 7d39ed7..166b2cd 100755 |
|||
--- a/rc.local |
|||
+++ b/rc.local |
|||
@@ -17,4 +17,6 @@ if [ "$_IP" ]; then |
|||
printf "My IP address is %s\n" "$_IP" |
|||
fi |
|||
+/usr/sbin/ifplugd -i wlan0 --kill |
|||
+ |
|||
exit 0 |
|||
</source> |
</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