Make a wireless LAN Ethernet converter and simple router with Raspberry Pi

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.

Construction environment

-** 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.

2020-09-15_blockdiag (2).png

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.

Build

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).

Wireless setting (wlan0)

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

Wired setting (eth0)

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

IP masquerade settings

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

DHCP server installation and configuration

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.

reference

-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

Recommended Posts

Make a wireless LAN Ethernet converter and simple router with Raspberry Pi
Make a wash-drying timer with a Raspberry Pi
Make a simple CO2 incubator using Raspberry PI and CO2 sensor (MH-Z14A)
Make a thermometer with Raspberry Pi and make it viewable with a browser Part 4
Make a Kanji display compass with Raspberry Pi and Sense Hat
Make a thermometer with Raspberry Pi and make it visible on the browser Part 3
Create a web surveillance camera with Raspberry Pi and OpenCV
Easily make a TweetBot that notifies you of temperature and humidity with Raspberry Pi + DHT11.
Using a webcam with Raspberry Pi
Make a simple OMR (mark sheet reader) with Python and OpenCV
Christmas classic (?) Lighting a Christmas tree with Raspberry Pi and Philips Hue
Turn Raspberry Pi into a router (Wake on LAN [4] over NAT)
Pet monitoring with Rekognition and Raspberry pi
[Raspberry Pi] Add a thermometer and a hygrometer
Build a Tensorflow environment with Raspberry Pi [2020]
Let's make a simple language with PLY 1
Operate an oscilloscope with a Raspberry Pi
Create a car meter with raspberry pi
Detect analog signals with A / D converter using python on Raspberry Pi 3!
[Python + PHP] Make a temperature / humidity / barometric pressure monitor with Raspberry Pi
I tried to make a traffic light-like with Raspberry Pi 4 (Python edition)
Create a socket with an Ethernet interface (eth0, eth1) (Linux, C, Raspberry Pi)
Simple VPN construction of IPsec gateway with Ubuntu 20.04 and Raspberry Pi ―― 1. StrongSwan introduced
Make a simple pixel art generator with Flask
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server --2 PHP introduction
Cross-compiling Raspberry Pi and building a remote debugging development environment with VS Code
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a Web server ―― 1. Apache introduction
MQTT RC car with Arduino and Raspberry Pi
[Python] Make a simple maze game with Pyxel
Creating a temperature control system with Raspberry Pi and ESP32 (3) Recipient Python file
[For beginners] I made a motion sensor with Raspberry Pi and notified LINE!
Get temperature and humidity with DHT11 and Raspberry Pi
Build a distributed environment with Raspberry PI series (Part 3: Install and configure dnsmasq)
I tried to make a simple image recognition API with Fast API and Tensorflow
[Note] Use a wired LAN connection device with WiFi-Eth bridge on Raspberry Pi 4B
Control music playback on a smartphone connected to Raspberry Pi 3 and bluetooth with AVRCP
Build a server on Linux and local network with Raspberry Pi NextCloud and desktop sharing
Source compile Apache2.4 + PHP7.4 with Raspberry Pi and build a web server --3. Use MySQL
Simple VPN construction of IPsec gateway with CentOS 8 and openSUSE (Raspberry Pi) ―― 1. StrongSwan introduced
Simple VPN construction of IPsec gateway with Ubuntu 20.04 and Raspberry Pi --2 StrongSwan VPN connection confirmation
Record temperature and humidity with systemd on Raspberry Pi
Try making a simple website with responder and sqlite3
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Create a color sensor using a Raspberry Pi and a camera
Easy IoT to start with Raspberry Pi and MESH
Make a simple Slackbot with interactive button in python
Measure temperature and humidity with Raspberry Pi3 and visualize with Ambient
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
Let's make a Mac app with Tkinter and py2app
Make an umbrella reminder with Raspberry Pi Zero W
Getting Started with Yocto Project with Raspberry Pi 4 and WSL2
What is God? Make a simple chatbot with python
Troubleshoot with installing OpenCV on Raspberry Pi and capturing
A memorandum when making a surveillance camera with Raspberry Pi
DigitalSignage with Raspberry Pi
Make a note of what you want to do in the future with Raspberry Pi
Make an autonomous driving robot car with Raspberry Pi3 B + and ultrasonic distance sensor HC-SR04
I tried to make a motion detection surveillance camera with OpenCV using a WEB camera with Raspberry Pi
Make a LINE bot with GoogleAppEngine / py. Simple naked version
A simple interactive music player made with Chuck and OpenPose
Python beginner opens and closes interlocking camera with Raspberry Pi