Raspberry Pi: Difference between revisions
Jump to navigation
Jump to search
Line 39: | Line 39: | ||
References: |
References: |
||
* http://www.daveconroy.com/turn-your-raspberry-pi-into-a-wifi-hotspot-with-edimax-nano-usb-ew-7811un-rtl8188cus-chipset/ |
* http://www.daveconroy.com/turn-your-raspberry-pi-into-a-wifi-hotspot-with-edimax-nano-usb-ew-7811un-rtl8188cus-chipset/ |
||
<source lang="diff"> |
|||
diff --git a/default/hostapd b/default/hostapd |
|||
index 1e12174..5783c15 100644 |
|||
--- a/default/hostapd |
|||
+++ b/default/hostapd |
|||
@@ -7,7 +7,7 @@ |
|||
# file and hostapd will be started during system boot. An example configuration |
|||
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz |
|||
# |
|||
-#DAEMON_CONF="" |
|||
+DAEMON_CONF="/etc/hostapd/hostapd.conf" |
|||
# Additional daemon options to be appended to hostapd command:- |
|||
# -d show more debug messages (-dd for even more) |
|||
diff --git a/default/isc-dhcp-server b/default/isc-dhcp-server |
|||
index df30daa..ec7fb5a 100644 |
|||
--- a/default/isc-dhcp-server |
|||
+++ b/default/isc-dhcp-server |
|||
@@ -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> |
|||
The following changes might be required as well: |
|||
<source lang="diff"> |
|||
diff --git a/default/hostapd b/default/hostapd |
|||
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> |
|||
== Troubleshoot == |
== Troubleshoot == |
Revision as of 18:41, 25 April 2017
Network
Detect all Raspberry Pi on local network
From [1].
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 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)
References:
diff --git a/default/hostapd b/default/hostapd
index 1e12174..5783c15 100644
--- a/default/hostapd
+++ b/default/hostapd
@@ -7,7 +7,7 @@
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz
#
-#DAEMON_CONF=""
+DAEMON_CONF="/etc/hostapd/hostapd.conf"
# Additional daemon options to be appended to hostapd command:-
# -d show more debug messages (-dd for even more)
diff --git a/default/isc-dhcp-server b/default/isc-dhcp-server
index df30daa..ec7fb5a 100644
--- a/default/isc-dhcp-server
+++ b/default/isc-dhcp-server
@@ -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
The following changes might be required as well:
diff --git a/default/hostapd b/default/hostapd
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
Troubleshoot
403 Forbidden when apt-get upgrade
From [2]:
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