Incredibly, I can't find a post that presents this simple setup. So I gave it a go.
Objective: Have wireless devices connect through your Pi 3 to your local LAN. Not a hotspot, no firewall, a simple transparent bridge that allows wireless clients to use LAN resources (DHCP server, router, DNS server.)
Hardware prerequisites: a Pi 3 with wired access to the LAN, a (home) router providing the usual DHCP, DNS firewalling/routing services.
Software prerequisites: raspbian, hostapd (apt-get install hostapd), brctl (apt-get install bridge-utils)
Caveats:
- Not tested against dhcpcd. (I don't use it on my Pi)
- Do not attempt this if you only have remote (ssh, X or vnc...) access to the Pi. You will disrupt connectivity and might lose contact with the Pi. To setup this comfortably you need local access to the Pi, through the text or graphical console.
- This was not written starting with a clean raspbian install. There might be some discrepancies between what you read and what you see. I expect they would be minor.
1. Prologue
Connect the ethernet cable to the Pi 3, boot it and verify it has connectivity.
Start a terminal or use the console to log in your Pi 3.
Now have a look at file /etc/network/interfaces which defines networking setup for the machine. It should look like this:
Code: Select all
admin@berck:~ $ cat /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
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Verify the current IP configuration. You should get something like this:
Code: Select all
admin@berck:~ $ ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:01:02:03
inet addr:172.17.255.192 Bcast:172.17.255.255 Mask:255.255.0.0
inet6 addr: fe80::ba27:ebff:fe01:0203/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:991 errors:0 dropped:0 overruns:0 frame:0
TX packets:470 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:81898 (79.9 KiB) TX bytes:78496 (76.6 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:158 errors:0 dropped:0 overruns:0 frame:0
TX packets:158 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:14314 (13.9 KiB) TX bytes:14314 (13.9 KiB)
wlan0 Link encap:Ethernet HWaddr b8:27:eb:11:12:13
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:1 errors:0 dropped:1 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:60 (60.0 B) TX bytes:0 (0.0 B)
Here you see the wired interface "eth0" has IPv4 address "172.17.255.192", which was given by the dhcp server on the LAN. The wifi "wlan0" interface has no IP address, because the /etc/wpa_supplicant/wpa_supplicant.conf referred to in /etc/networking/interfaces is missing. That's ok.
2. Setup bridging
Make two (or more) interfaces behave as if they were plugged into a physical switch.
Start with adding network interface bridging capability to the Pi 3. The raspbian package to install is called "bridge-utils":
Code: Select all
admin@berck:~ $ sudo apt-get install bridge-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
bridge-utils
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.1 kB of archives.
After this operation, 60.4 kB of additional disk space will be used.
Get:1 http://mirrors.ircam.fr/pub/raspbian/raspbian jessie/main armhf bridge-utils armhf 1.5-9 [32.1 kB]
Fetched 32.1 kB in 0s (101 kB/s)
Selecting previously unselected package bridge-utils.
(Reading database ... 70524 files and directories currently installed.)
Preparing to unpack .../bridge-utils_1.5-9_armhf.deb ...
Unpacking bridge-utils (1.5-9) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up bridge-utils (1.5-9) ...
Once installed you have access to a new command, "brctl":
Code: Select all
admin@berck:~ $ brctl show
bridge name bridge id STP enabled interfaces
OK, nothing to see here yet.
Next we modify the networking configuration to bridge the wireless interface "wlan0" and the wired interface "eth0". We want the bridge to manage both interfaces and get the IP address for itself via DHCP.
Start by making a backup copy of file /etc/network/interfaces in case you want to roll back to stock configuration
Code: Select all
admin@berck:~ $ sudo cp -v /etc/network/interfaces /etc/network/interfaces.backup
‘/etc/network/interfaces’ -> ‘/etc/network/interfaces.backup’
You can edit /etc/network/interfaces any way want; I'll use nano:
Code: Select all
admin@berck:~ $ sudo nano /etc/network/interfaces
and change the configuration to this:
Code: Select all
admin@berck:~ $ cat /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
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual
auto wlan0
iface wlan0 inet manual
auto br0
iface br0 inet dhcp
bridge-stp on
bridge-maxwait 2
bridge-fd 2
bridge-ports eth0 wlan0
Time for the suicide jump that will cut networking but hopefully return with a new working configuration. Again, run this command from the local console or risk losing connexion with your Pi 3:
Code: Select all
admin@berck:~ $ sudo service networking reload
Warning: Unit file of networking.service changed on disk, 'systemctl daemon-reload' recommended.
admin@berck:~ $ sudo service networking restart
Warning: Unit file of networking.service changed on disk, 'systemctl daemon-reload' recommended.
You're in luck, the network still works. And now it looks like this:
Code: Select all
admin@berck:~ $ ifconfig
br0 Link encap:Ethernet HWaddr b8:27:eb:01:02:03
inet addr:172.17.255.192 Bcast:172.17.255.255 Mask:255.255.0.0
inet6 addr: fe80::ba27:ebff:fe01:0203/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:225 errors:0 dropped:0 overruns:0 frame:0
TX packets:143 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:45462 (44.3 KiB) TX bytes:49855 (48.6 KiB)
eth0 Link encap:Ethernet HWaddr b8:27:eb:01:02:03
inet addr:172.17.255.192 Bcast:172.17.255.255 Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:8042 errors:0 dropped:15 overruns:0 frame:0
TX packets:3607 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:755414 (737.7 KiB) TX bytes:412604 (402.9 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:164 errors:0 dropped:0 overruns:0 frame:0
TX packets:164 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:15010 (14.6 KiB) TX bytes:15010 (14.6 KiB)
wlan0 Link encap:Ethernet HWaddr b8:27:eb:11:12:13
UP BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:1 errors:0 dropped:1 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:60 (60.0 B) TX bytes:0 (0.0 B)
Now the bridge br0 has received the IP address from the DHCP server. It has taken the MAC address of the wired interface eth0, so the DHCP server gave it the same address as before.
EDIT: In fact this doesn't look right. eth0 should not have an address any longer. Instead of running networking restart, reboot if you can.
How is our bridge doing?
Code: Select all
admin@berck:~ $ brctl show
bridge name bridge id STP enabled interfaces
br0 8000.b827eb010203 yes eth0
Hum, wait. Where is wlan0?
Well, since wlan0 is a wifi interface, bridging is not allowed (by the Wi-Fi standard body) unless the interface is in Access Point mode. It's not yet, so it wasn't included to the bridge. That's ok, we'll see to that next.
3. Setup the Access Point
Allow wireless devices to connect to the Pi 3 and then obtain an address on the LAN through the wireless<->ethernet bridge.
First we need to install the "hostapd" package:
Code: Select all
admin@berck:/etc/hostapd $ sudo apt-get install hostapd
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
hostapd
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 459 kB of archives.
After this operation, 1,164 kB of additional disk space will be used.
Get:1 http://mirrors.ircam.fr/pub/raspbian/raspbian jessie/main armhf hostapd armhf 1:2.3-1+deb8u3 [459 kB]
Fetched 459 kB in 0s (1,228 kB/s)
Selecting previously unselected package hostapd.
(Reading database ... 70530 files and directories currently installed.)
Preparing to unpack .../hostapd_1%3a2.3-1+deb8u3_armhf.deb ...
Unpacking hostapd (1:2.3-1+deb8u3) ...
Processing triggers for man-db (2.7.0.2-5) ...
Processing triggers for systemd (215-17+deb8u4) ...
Setting up hostapd (1:2.3-1+deb8u3) ...
Now we create a configuration file for the access point. I'll edit the file with:
Code: Select all
admin@berck:~ $ sudo nano /etc/hostapd/hostapd.conf
This is the final file. It should work with the integrated wifi interface of Pi 3. Peruse hostapd documentation to refine this basic setup:
Code: Select all
admin@berck:~ $ cat /etc/hostapd/hostapd.conf
# Basic AP parameters
ssid=test
wpa_passphrase=it's good to be the king
interface=wlan0
bridge=br0
channel=1
# WPA 2 PSK
wpa=2
auth_algs=1
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
# Wifi-N
driver=nl80211
hw_mode=g
ieee80211n=1
ieee80211d=1
country_code=<your_2-letter_country_code>
ieee80211h=1
# I'm sorry, I don't know if the right stanza is
# wme_ or wmm_ so I include both...
wme_enabled=1
wmm_enabled=1
Now make sure file /etc/default/hostapd contains the uncommented line
Code: Select all
DAEMON_CONF="/etc/hostapd/hostapd.conf"
(in other words, remove the sharp sign # in front of this line if there is one)
And now a second leap of faith. Reboot the machine, and once you're logged in again you should see this
Code: Select all
admin@berck:~ $ ifconfig br0
br0 Link encap:Ethernet HWaddr b8:27:eb:01:02:03
inet addr:172.17.255.192 Bcast:172.17.255.255 Mask:255.255.0.0
inet6 addr: fe80::ba27:ebff:fe01:0203/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2766 errors:0 dropped:0 overruns:0 frame:0
TX packets:622 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:563003 (549.8 KiB) TX bytes:87940 (85.8 KiB)
admin@berck:~ $ pidof hostapd
1051
admin@berck:~ $ brctl show
bridge name bridge id STP enabled interfaces
br0 8000.b827eb010203 yes eth0
wlan0
We have our bridge working, hostapd is running, and lo and behold, the interface wlan0 in AP mode got included to the bridge.
Now grab a wireless device, point it to the AP "test", input the password "it's good to be the king" and it should get an address on the LAN, just as another machine.