Raspberry Pi Computing

Sunday, 30 December 2018

Raspberry Pi setup as a bridged WiFi access point


Per instructions at raspberrypi.org with some modification to make it easier to follow and for localisation.
Install the most recent raspbian disk image onto a microSD card using Disk Imager or similar.
Create a new file on the microSD card called ssh. I simply right click on the folder and go 'Create new text document'. The file will have the suffix .txt, but this won't matter. This allows ssh to be enabled on first boot.
Unmount the microSD card and put it into the Pi. Have the Pi connected to a monitor so that you can see what the IP address is when it finishes booting. Alternatively, check the connected devices on a router page.
Turn the power on. The automatic re-sizing will be carried out and the IP address will be shown.
Start WinSCP. Use the IP address, port 22, the username pi and the password raspberry to connect. You will be warned about a potential security breach because the host key won't match the one that WinSCP has in its cache. This is fine. Just press the 'Update' button to continue.
sudo apt-get update sudo apt-get upgrade
To use the Raspberry Pi as an bridged access point is to provide wireless connections to a wired Ethernet connection, so that anyone logged into the access point can access the internet, providing of course that the wired Ethernet on the Pi can connect to the internet via some sort of router.
To do this, a 'bridge' needs to put in place between the wireless device and the Ethernet device on the access point Raspberry Pi. This bridge will pass all traffic between the two interfaces. Install the following packages to enable the access point setup and bridging.
sudo apt-get install hostapd bridge-utils
Since the configuration files are not ready yet, turn the new software off as follows:
sudo systemctl stop hostapd
Bridging creates a higher-level construct over the two ports being bridged. It is the bridge that is the network device, so we need to stop the eth0 and wlan0 ports being allocated IP addresses by the DHCP client on the Raspberry Pi.
sudo nano /etc/dhcpcd.conf
Add denyinterfaces wlan0 and denyinterfaces eth0 to the end of the file (but above any other added interface lines) and save the file.
Add a new bridge, which in this case is called br0.
sudo brctl addbr br0
Connect the network ports. In this case, connect eth0 to the bridge br0.
sudo brctl addif br0 eth0
Now the interfaces file needs to be edited to adjust the various devices to work with bridging.
sudo nano /etc/network/interfaces
Make the following edits by adding the bridging information at the end of the file.
# Bridge setup
auto br0
iface br0 inet manual
bridge_ports eth0 wlan0 
You need to edit the hostapd configuration file, located at /etc/hostapd/hostapd.conf, to add the various parameters for your wireless network. After initial install, this will be a new/empty file.
sudo nano /etc/hostapd/hostapd.conf
Add the following

interface=wlan0
bridge=br0
#driver=nl80211
ssid=water_tank
hw_mode=g
channel=11
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=water_tank_password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
We now need to tell the system where to find this configuration file.
sudo nano /etc/default/hostapd
Find the line with #DAEMON_CONF, and replace it with this:
DAEMON_CONF="/etc/hostapd/hostapd.conf"
Now reboot the Raspberry Pi.
sudo reboot
There should now be a functioning bridge between the wireless LAN and the Ethernet connection on the Raspberry Pi, and any device associated with the Raspberry Pi access point will act as if it is connected to the access point's wired Ethernet.
The ifconfig command will show the bridge, which will have been allocated an IP address via the wired Ethernet's DHCP server. The wlan0 and eth0 no longer have IP addresses, as they are now controlled by the bridge. It is possible to use a static IP address for the bridge if required, but generally, if the Raspberry Pi access point is connected to a ADSL router, the DHCP address will be fine.

No comments:

Post a Comment