The problem: connect a WLAN-only LTE router to an Ethernet-only appliance, with remote access.
sudo apt update sudo apt upgrade
sudo raspi-config
Set the following:
Raspberry Pi stores known APs SSID via WPA Supplicant configuration file
sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
network={ ssid="ssid" psk="password" }
LAN will use 192.168.88.0/24 network range
eth0 interface uses fixed IP address 192.168.88.1
sudo vim.tiny /etc/dhcpcd.conf
#interface eth0 #static ip_address=192.168.0.10/24 interface eth0 static ip_address=192.168.88.1/24
dnsmasq provides a DHCP server and DNS proxy on eth0 interface:
sudo apt install dnsmasq #sudo apt install isc-dhcp-server
sudo vim /etc/dnsmasq.conf
#interface= interface=eth0 #dhcp-range=192.168.0.50,192.168.0.150,12h dhcp-range=192.168.88.10,192.168.0.20,12h
sudo service dnsmasq restart cat /var/lib/misc/dnsmasq.leases cat /var/log/syslog | grep dnsmasq
Now, client and router should be able to ping each others
In order for Pi-Router to forward traffic between interfaces:
sudo vim /etc/sysctl.conf
#net.ipv4.ip_forward=1 net.ipv4.ip_forward=1
Now, device from LAN can reach the internet, however, response cannot be sent back since 4G router does not know about 192.168.88.x network.
Solution is to implement NAT on Pi-Router (so that it relays requests using it's own source IP address)
sudo iptables -A FORWARD -i eth0 -j ACCEPT sudo iptables -A FORWARD -o eth0 -j ACCEPT sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
To make iptables rules persistent between reboots:
sudo apt-get install iptables-persistent sudo netfilter-persistent save
Note: if iptables does not support masquerade, use legacy one:
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE iptables v1.8.2 (nf_tables): Chain 'MASQUERADE' does not exist Try `iptables -h' or 'iptables --help' for more information. sudo update-alternatives --config iptables There are 2 choices for the alternative iptables (providing /usr/sbin/iptables). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/sbin/iptables-nft 20 auto mode 1 /usr/sbin/iptables-legacy 10 manual mode 2 /usr/sbin/iptables-nft 20 manual mode Press <enter> to keep the current choice[*], or type selection number: 1 update-alternatives: using /usr/sbin/iptables-legacy to provide /usr/sbin/iptables (iptables) in manual mode
Since the 4G router does not provide any remote access capability, PiRouter will intiate a VPN connection to a public OpenVPN server.
That way, pi is accessible (ssh, http) from the outside.