Difference between revisions of "Internet Sharing with a Raspberry Pi"

From Double Jump Electric Wiki
Jump to navigation Jump to search
(from Ubuntu)
(from Ubuntu)
 
Line 13: Line 13:
 
echo 1 > /proc/sys/net/ipv4/ip_forward
 
echo 1 > /proc/sys/net/ipv4/ip_forward
 
</source>
 
</source>
 +
 +
Note that the script above assumes that you are sharing the ''eth0'' connection from ''wlan0''. This may not be the case for your computer. (Mine was ''enx..'' and ''wlp59s0''. Check with the ''ifconfig'' command.
  
 
From the terminal, make the file executable with:
 
From the terminal, make the file executable with:

Latest revision as of 10:38, 15 May 2020

from Ubuntu

Open a text editor and save the contents below as ipmasq.sh.

#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 wlan0 -j MASQUERADE
iptables --append FORWARD --in-interface eth0 -j ACCEPT

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

Note that the script above assumes that you are sharing the eth0 connection from wlan0. This may not be the case for your computer. (Mine was enx.. and wlp59s0. Check with the ifconfig command.

From the terminal, make the file executable with:

chmod +x

To share the internet connection, run the file with

sudo ./ipmasq.sh

References