TL;DR --Build a router using the wireless LAN (wlan0) and wired LAN (eth0) of the Raspberry Pi. --Connect with the upstream wireless AP with wlan0 as the WAN side, and distribute the IP address to the subordinate PCs with eth0 as the LAN side. --The image is a wireless LAN repeater with a router function.
-** Wireless AP : An existing wireless AP that distributes addresses by DHCP is assumed.
- Raspberry Pi : WiFi connection with wireless AP and acquisition of address from DHCP server (wlan0). The IP segment of 192.168.21.0/24
is set on the LAN side (eth0), and the address is distributed to the PCs under the LAN by DHCP. It functions as a gateway and forwards the request received from the LAN side (eth0) to the WAN side (wlan0).
- PC **: Connected to Raspberry Pi via Ethernet and obtained IP address by DHCP.
Raspberry Pi uses Raspberry Pi 2. A USB wireless adapter is used for wireless LAN connection, but it is not necessary if it is a successor because it is installed as standard. Since 2 has an Ethernet connection of 100BASE-T, we recommend the latest 4 if possible. The OS is Raspbian Lite installed.
The initial setup of Raspberry Pi is omitted. Specifically, sshd and initial users.
This article uses vim
, but anything is fine.
As already described, the wireless LAN side is set to wlan0 and the wired LAN side is set to eth0 (default).
Use wpa_supplicant
to set up the wireless connection. Please search for SSID in Texto.
sudo iw dev wlan0 scan | grep SSID
Add the network settings to wpa_supplicant.conf
with the following command.
sudo sh -c 'wpa_passphrase <SSID> <Passphrase> >> /etc/wpa_supplicant/wpa_supplicant.conf'
Since the raw password is commented out, it is recommended to delete it after confirmation.
/etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="SSID"
#psk="Passphrase" #Erase
psk=xxxxxxxxxxx
}
Please connect to the wireless AP with wpa_supplicant. I feel that it can be started via systemd. Since it was connected without any special settings, it may depend on the environment. It suffices if the IP address can be obtained from the AP by DHCP.
sudo systemctl start wpa_supplicant.service
sudo systemctl enable wpa_supplicant.service
Set the IP segment on the eth0 side.
I have assigned 192.168.21.1
to the Raspberry Pi.
/etc/dhcpcd.conf
interface eth0
static ip_address=192.168.21.1/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
static routers=0.0.0.0
static domain_name_servers=0.0.0.0
Set to send packets from the LAN side (eth0) to the WAN side (wlan0). After setting, please restart once for reflection. Although the settings are simple here, please consider appropriate settings in consideration of security etc. when using in production.
/etc/rc.local
#Append
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
exit 0
Build a DHCP server. Install the following software.
sudo apt install -y isc-dhcp-server dnsmasq
Set the config. Comment out unnecessary settings and uncomment the required settings.
After that, set the address to be distributed by DHCP. This time, we will distribute addresses in the range from 192.168.21.2
to 192.168.21.99
.
/etc/dhcp/dhcpd.conf
#option domain-name "example.org"; #Comment out
#option domain-name-servers ns1.example.org, ns2.example.org; #Comment out
authoritative; #Uncomment
#Append
subnet 192.168.21.0 netmask 255.255.255.0 {
range 192.168.21.2 192.168.21.99;
option routers 192.168.21.1;
option domain-name-servers 192.168.21.1;
option broadcast-address 192.168.21.255;
ignore declines;
}
Associate with the interface. Please describe the interface on the LAN side (eth0).
/etc/default/isc-dhcp-server
INTERFACESv4="eth0"
#INTERFACESv6=""
Start the DHCP server. I feel that startup will fail if the eth0 side is not linked up. At this point, it's a good idea to connect your Raspberry Pi to your PC.
sudo systemctl start isc-dhcp-server.service
sudo systemctl enable isc-dhcp-server.service
If the address is assigned to the PC under the LAN and you can connect to the Internet, it is successful. Thank you for your hard work.
-Make Raspberry Pi 3 an Ethernet converter -How to convert Raspberry Pi to wireless LAN Ethernet converter -I tried using Raspberry Pi3 as a DHCP server