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

# Defines the location of iptables executables.

#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 Run the script sudo ./

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. as the default gateway e.g. sudo route add default gw

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


15-01-2016 18:03