Sharing an internet connection using a Raspberry Pi + Mifi device

You have a Raspberry Pi connected to the internet using Mifi, but now you want to connect other computers to the internet through the LAN. Here's how to set up the Raspberry Pi to share its internet connection with other devices on the LAN.

Create the the following file on your Pi and save it as ipmasq.sh:

# Defines the location of iptables executables.
iptables=/sbin/iptables

#Clears if any old iptable rules/ policies are there.
iptables --flush -t nat

 # Now we will do Masquerading ie. we are doing NAT.
iptables --table nat --append POSTROUTING --out-interface wwan0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT

 # Enabling packet forwarding.
echo 1 > /proc/sys/net/ipv4/ip_forward

Make the script file executable chmod 755 ipmasq.sh. Run the script sudo ./ipmasq.sh

Your computer should now be sharing its internet connection.

On each of the other computers to be connected to the internet, ensure the route table has the Raspberry PI LAN ip address (e.g. 192.168.0.188) as the default gateway e.g. sudo route add default gw 192.168.0.188.

You should now be able to connect to the internet from that device (i.e. laptop, tablet, IP cam, other Raspberry Pi).

Resources

Tags:
Source:
1803hrs.txt
Published:
15-01-2016 18:03