Freakstreet
Posts: 3
Joined: Mon Oct 19, 2015 1:55 pm

4G router based for LAN/WiFi

Tue Apr 07, 2020 2:00 pm

Hi all,
I'm being stuck in setting up my raspberry 3+ as a 4G LAN/WiFi router. I've lately discovered pi-hole project so I'd like to integrate it too in my solution, later.

My goal is to share a 4G internet access over LAN and WiFi in an isolated place and being linked to my home with openvpn.

Actually, I'm setting :
eth0 192.168.2.2
wlan0 192.168.2.3 setup as WiFi AP
wwan0 is my 4G connection
tun0 10.8.0.30

I'm probably mismatching functions between Dnsmasq, hostapd, bridge functions and my network configuration so it may be time saving to restart from the beginning with all your advices then trying to explain what I've done so far... I'll skip openvpn part, I'll manage it later.

So from a clean install of Raspbian buster I do :
setup wifi client to apt update the system

Activate ipv4 forwarding :

Code: Select all

# Activate ip_forwarding
sudo echo 1> /proc/sys/net/ipv4/ip_forward
apt install libqmi-utils udhcpc, then I can setup the 4G wwan0 link with this script :

Code: Select all

echo "Setting up wwan0 interface and setting internet link"
if [ ! -e /sys/class/gpio/gpio4 ]; then
    echo "4" > /sys/class/gpio/export
fi
echo "out" > /sys/class/gpio/gpio4/direction
echo "0" > /sys/class/gpio/gpio4/value
sleep 2
echo "1" > /sys/class/gpio/gpio4/value
sleep 5
sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
sleep 1
sudo qmicli -d /dev/cdc-wdm0 -w
sleep 1
sudo ip link set wwan0 down
sleep 1
echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip
sleep 1
sudo ip link set wwan0 up
sleep 1
sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='free',ip-type=4" --client-no-release-cid
sleep 1
sudo udhcpc -i wwan0
echo "Activating routing function"
sudo iptables -t nat -A POSTROUTING -o wwan0 -j MASQUERADE
Then, stop the wlan0 link and have internet access through wwan0.

Setup DHCP server :
sudo apt install dnsmasq
with /etc/dnsmask.conf content

Code: Select all

# DHCP Settings
dhcp-range=192.168.2.100,192.168.2.150,255.255.255.0,12h
# Router
#dhcp-option=3,192.168.2.1
# DNS
dhcp-option=6,192.168.2.2
# Delays sending DHCPOFFER and proxydhcp replies for at least the specified number of seconds.
dhcp-mac=set:client_is_a_pi,B8:27:EB:*:*:*
dhcp-reply-delay=tag:client_is_a_pi,2
Then setup the WiFi as AP :
sudo apt install hostapd
with /etc/hostapd/hostapd.conf content :

Code: Select all

interface=wlan0
country_code=FR
ctrl_interface=wlan0
ctrl_interface_group=0
ssid=my_ssid
hw_mode=g
channel=7
wpa=3
wpa_passphrase=secret
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
beacon_int=100
auth_algs=3
macaddr_acl=0
wmm_enabled=1
An pointing to this file on /etc/default/dhcpd

To finish, I'm having all the setup forced at startup in a script :

Code: Select all

#!/bin/bash

echoc () {
    echo -e "\e[44m$1\e[49m"
}

echoc "Setting up eth0 interface address to 192.168.2.2"
sudo ifconfig eth0 down
sudo ifconfig eth0 192.168.2.2
sudo ifconfig eth0 up

echoc "Setting up wlan0 interface address to 192.168.2.3"
sudo ifconfig wlan0 down
sudo ifconfig wlan0 192.168.2.3
sudo ifconfig wlan0 up

sleep 1

echoc "Restarting AP and DHCP services"
sudo service hostapd restart
sudo service dnsmasq restart

echoc "Setting up wwan0 interface and setting internet link"
if [ ! -e /sys/class/gpio/gpio4 ]; then
    echo "4" > /sys/class/gpio/export
fi
echo "out" > /sys/class/gpio/gpio4/direction
echo "0" > /sys/class/gpio/gpio4/value
sleep 2
echo "1" > /sys/class/gpio/gpio4/value
sleep 5
sudo qmicli -d /dev/cdc-wdm0 --dms-set-operating-mode='online'
sleep 1
sudo qmicli -d /dev/cdc-wdm0 -w
sleep 1
sudo ip link set wwan0 down
sleep 1
echo 'Y' | sudo tee /sys/class/net/wwan0/qmi/raw_ip
sleep 1
sudo ip link set wwan0 up
sleep 1
sudo qmicli -p -d /dev/cdc-wdm0 --device-open-net='net-raw-ip|net-no-qos-header' --wds-start-network="apn='free',ip-type=4" --client-no-release-cid
sleep 1
sudo udhcpc -i wwan0

echoc "Activating routing function"
sudo iptables -t nat -A POSTROUTING -o wwan0 -j MASQUERADE
I can restart all from the beginning if this seems better but it's weeks I'm being stuck in there. Thanks all for your help.
Regards

Return to “Troubleshooting”