This configuration will allow to share/extend a Wireless network to use your own router (192.168.0.0/24); will be like and extender
or repeater
. The WAN side can be any DHCP WIFI connection.
There will be a double NAT, plus the extra hop, so the system will not be a fast access point but, a very convenient. You may also use this with a switch
, allowing internet access to almost any non wireless enabled device.
I use this configuration on my boat, using a pretty good external antenna, to connect to a remote (1 mile +) access point.
Connect the extender
to the WAN. Create a wpa_supplicant with the proper credentials. You can have multiple WIFI credentials on file if you are roaming.
- Change your
eth0
parameters to have a fix IP address:
Showing here the eth0
configuration.
nano /etc/network/interfaces
.....
allow-hotplug eth0
iface eth0 inet static
address 192.168.0.1
network 192.168.0.0
netmask 255.255.255.0
....
Remove isc-dhcp if available and install a couple of packages to provide DHCP and DNS to your private network:
apt-get autoremove isc-dhcp-server
apt-get install -y dnsmasq dnsutils
dnsmasq is a very common and powerful package included in a vast number of commercial routers. Modify a few lines on the .conf file (they may be commented with #) most are self explanatory:
nano /etc/dnsmasq.conf
interface=eth0
except-interface=wlan0
dhcp-range=192.168.0.2,192.168.0.254,1h
dhcp-option=option:router,192.168.0.1
# option 6 is dns server
dhcp-option=6,192.168.0.1
- Configure IPTABLES to forward packets between the networks:
Using cron
execute this bash
to run on reboot.
#!/bin/bash
# request package forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
i=$(which iptables)
PUB=wlan0
PRI=eth0
GW=$(route -n | grep "^0\.0\..*${PUB}"| tail -n 1| awk '{print $2}')
$i -A FORWARD -i $PUB -m comment --comment "Created" -j ACCEPT
$i -A FORWARD -i $PRI -m state --state RELATED,ESTABLISHED -m comment --comment "Created" -j ACCEPT
$i -t nat -A POSTROUTING -o $PRI -m comment --comment "Created" -j SNAT --to-source $GW
$i -t nat -A POSTROUTING -o $PUB -m comment --comment "Created" -j MASQUERADE
unset i wlan0 eth0
In my case, sometimes with no apparent reason I get disconnected (once or twice a day). I have this job running every few minutes to reconnect the WAN if not up:
#!/bin/bash
wlan=wlan0
c=$(iw $wlan link | grep [Cc]onnected\ to | sed 's/.* to //')
# if not connected, reconnect
if [ "x${c}" == "x" ] ; then
wpa_cli terminate
sleep .05
ifconfig $wlan down
wpa_supplicant -B -K -Dnl80211 -i$wlan -c/etc/wpa_supplicant/wpa_supplicant.conf
sleep .05
dhclient $wlan
fi
unset c wlan