shanem2
Posts: 13
Joined: Tue Jan 23, 2018 10:38 am

4G Wireless router with WiFi fail back

Tue Jan 23, 2018 10:47 am

I'm looking to configure my Pi to be a WiFi repeater, so when traveling my devices can access the Internet. When no WiFi access points are available, I want to be able to fail over to 4G dongle.

Do I need two USB WiFi adapters? Any code available to do this?

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: 4G Wireless router with WiFi fail back

Tue Jan 23, 2018 3:18 pm

You can try one wireless device for both a client and access point, but it is a bit difficult to set up. Once you get this working, you can add a masquerade for your 4G wireless unit just like wlan0. Ensure your wlan0 interface has the lowest metric. That way it will be used as the preferential WAN interface.

Add this to /etc/network/interfaces

Code: Select all

auto wlan0
iface wlan0 inet dhcp
	wpa-ssid "MySSID"
	wpa-psk "MyPassphrase"
Reboot. This will cause the dhcpcd service to fail.

Insure your OS is up to date.

Code: Select all

sudo apt-get update
sudo apt-get upgrade
Install the modules.

Code: Select all

sudo apt-get install dnsmasq hostapd
Edit /etc/rc.local and add this above "exit 0". Note that is two underscores on __ap.

Code: Select all

service hostapd stop
service dnsmasq stop
iw dev wlan0 interface add uap0 type __ap
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
ifdown wlan0
ip link set uap0 up
ip addr add 192.168.4.1/24 broadcast 192.168.4.255 dev uap0
service hostapd start
ifup wlan0
service dnsmasq start
The /etc/dnsmasq.conf file

Code: Select all

interface=uap0
dhcp-range=192.168.4.20,192.168.4.100,255.255.255.0,12h
The /etc/hostapd/hostapd.conf file. If you change the wpa_passphrase, it must be 8 to 63 characters. No shorter or longer!

Code: Select all

interface=uap0
driver=nl80211
ssid=RPiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Edit /etc/default/hostapd, uncomment and change this:

Code: Select all

DAEMON_CONF="/etc/hostapd/hostapd.conf"
Edit /etc/sysctl.conf and uncomment

Code: Select all

net.ipv4.ip_forward=1
Reboot.

Return to “Networking and servers”