Raspberry as Pi Ethernet-WiFi-Bridge: Difference between revisions

From Wurst-Wasser.net
Jump to navigation Jump to search
Line 47: Line 47:
and set something like this:
and set something like this:
  nohook wpa_supplicant
  nohook wpa_supplicant
interface wlan0
# interface wlan0
static ip_address=192.168.178.58/24
# static ip_address=192.168.178.58/24
Explanation: I try to omit <tt>/etc/wpa_supplicant/wpa_supplicant.conf</tt>, and configure a static [[IPA]] for <tt>wlan0</tt>. NOTE TO SELF: Might be unnecessary since the [[bridge]] is now working. TBD: CHECK!
Explanation: I try to omit <tt>/etc/wpa_supplicant/wpa_supplicant.conf</tt>, and configure a static [[IPA]] for <tt>wlan0</tt>. NOTE TO SELF: Might be unnecessary since the [[bridge]] is now working. Note: It seems not to matter whether the [[IPA]] gets configured or not.
----
----
  vi /etc/network/interfaces
  vi /etc/network/interfaces

Revision as of 11:48, 5 February 2019

The Challenge

I wanted to set up my Raspberry Pi 3 as Webcam, intranet server, and Ethernet-WiFi-Bridge. In the long run I want to use some kind of QOA/shaping on the Pi to manage my really bad internet connection (yes, 6MBit/s in a country where 82 million people live on 356 thousand square-kilometers (about 230 people per square-km).

Setup

Install additional software

apt get install hostapd bridge-utils dhcp-helper dnsutils traceroute

What do they do?

  • hostapd: A daemon that sets up your WiFi as a access point, so anyone can join. Please note, that this means WiFi only. No DHCP, and therefore no DNS.
  • bridge-utils: These provide the bridging you need to "connect" the ethernet and WiFi interfaces.
  • dhcp-helper: DHCP uses a broadcast to the network (address) to reach the DHCP-server. Since broadcasts stay in the broadcast-domain with a TTL of 1, the won't get bridged. This is where dhcp-helper comes in. It forwards the broadcasts in all other nets (except the one specified with -b.
  • dnsutils: Just to do a nslookup from time to time. You can test your DNS-setup as well as lookup with nslookup[1]
  • traceroute: Might come in handy if you have networking problems (and you WILL have :) )

Configuration

vi /etc/sysctl.conf

and set

net.ipv4.ip_forward=1
net.ipv6.conf.all.disable_ipv6 = 1

Explanation: Disable IPv6 (to KISS) and enable forwarding for IPv4.


vi /etc/default/hostapd 

and set:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Explanation: The hostapd looks in the configfile, where his configfile is. I don't get what this is good for.


vi /etc/hostapd/hostapd.conf

and set something like this:

interface=wlan0
driver=nl80211
bridge=br0
hw_mode=g
channel=7
ieee80211n=1
wmm_enabled=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=HeartOfGold
wpa_passphrase=42

Explanation: hostapd creates the WiFi-Access Point and creates a bridge-device br0, which he ties (only) wlan0 to[2].


vi /etc/dhcpcd.conf

and set something like this:

nohook wpa_supplicant
  1. interface wlan0
  2. static ip_address=192.168.178.58/24

Explanation: I try to omit /etc/wpa_supplicant/wpa_supplicant.conf, and configure a static IPA for wlan0. NOTE TO SELF: Might be unnecessary since the bridge is now working. Note: It seems not to matter whether the IPA gets configured or not.


vi /etc/network/interfaces

Don't touch this file. dhcpcd gets jealous...


vi /etc/default/dhcp-helper

and set:

DHCPHELPER_OPTS="-b eth0"

Explanation: dhcp-helper will now forward all DHCP-related boradcasts to this interface (and none coming from there to the other interfaces).


As mentioned before, the br0-device is only tied to wlan0, so we must take care of this. You might want to do this with a script in /etc/network/if-up.d/ like (WORK-IN-PROGRESS!):
# only do it, if necessary
/sbin/brctl show | /bin/grep eth0 && exit 0

# do it
echo "Creating interface, adding it to the bridge. The wlan0 is added by hostapd.conf (bridge=br0)..."
/sbin/brctl addif br0 eth0
/bin/sleep 1
/sbin/ifconfig eth0:0 192.168.178.69 up

Known issues

  • After br0 is set up…
    • DNS-lookups fail (and therefore everything else, like pings to external hosts or apt-get
    • the Pi can't be reached by ssh or any other service


Notes

Since you use a DHCP server and you manually set IPAs, you might want to reserve those IPAs in your DHCP-server configuration. This might become handy:

systemd-resolve --status

Displays your DNS-setup

nslookup www.wurst-wasser.net

  • More like this:
    • tbd
  • Footnotes
  1. or dig
  2. Check with: brctl show