Pi Wifi Adaptor


flowchart LR A[Phone] -.->|Hotspot| B[Pi]; B -->|Ethernet| C[PC without Wifi Adaptor];

Background

I built a PC which has no Wifi Support but Ethernet support. However, sometimes some area has no fibre broadband, ethernet is still slow. So you may prefer 4G.

Steps

Installation

sudo apt-get install dnsmasq
    
Configure dnsmasq

sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo vim /etc/dnsmasq.conf.wlan2pceth
### New
interface=eth0
dhcp-range=192.168.4.20,192.168.4.100,255.255.255.0,24h
###
sudo cp /etc/dnsmasq.conf.wlan2pceth /etc/dnsmasq.conf
    
Configure dhcpcd

sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.orig
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.wlan2pceth
sudo vim /etc/dhcpcd.conf.wlan2pceth
### Add
interface eth0
static ip_address=192.168.4.1/24
###
sudo cp /etc/dhcpcd.conf.wlan2pceth /etc/dhcpcd.conf
    
Configure sysctl

sudo cp /etc/sysctl.conf /etc/sysctl.conf.orig
sudo cp /etc/sysctl.conf /etc/sysctl.conf.wlan2pceth
sudo vim /etc/sysctl.conf.wlan2pceth
### Uncomment
net.ipv4.ip_forward=1
###
sudo cp /etc/sysctl.conf.wlan2pceth /etc/sysctl.conf
    
Configure rc.local

sudo cp /etc/rc.local /etc/rc.local.orig
sudo cp /etc/rc.local /etc/rc.local.wlan2pceth
sudo vim /etc/rc.local.wlan2pceth
### Add before "exit 0"
sudo iptables -t nat -A  POSTROUTING -o wlan0 -j MASQUERADE
###
sudo cp /etc/rc.local.wlan2pceth /etc/rc.local
    

Then just reboot.

References


  1. Raspberry Pi 3 As WiFi Adapter?
  2. What Is a Wireless Bridge and Why Do You Need One?
  3. DHCP Lease Time – What is it and How does it work?
  4. Setting up a Raspberry Pi as an access point in a standalone network