macey
Posts: 58
Joined: Thu May 24, 2012 6:05 pm

Network sharing

Thu May 02, 2013 9:55 pm

So, I have my Edimax Nano WiFi dongle working just fine on my Pi. What I want to do now is share
my Pi network with another device via the network connector. Is there anyone here that knows
how to do that? On Ubuntu, it's very simple, just go to the network Manager/Edit Connections/Wired/Select Connection/Edit ipv4 & select "shared to other computers...

How can I do this on the Pi? OK with terminal/command line...
Help appreciated..

macey
Posts: 58
Joined: Thu May 24, 2012 6:05 pm

Re: Network sharing

Fri May 03, 2013 10:13 am

bump ;)

User avatar
DaveDriesen
Posts: 113
Joined: Sun Mar 31, 2013 8:28 pm
Location: Top of the food chain
Contact: Website

Re: Network sharing

Tue May 07, 2013 10:17 am

You will probably want to:

- Define both network interfaces and their networks (in /etc/network/interaces on raspbian)
- Enable IP forwarding
- Set up Network Address translation (NAT) using iptables/netfilter
- Set your rpi as default gateway on your other devices

There is no one-size-fits-all configuration, but here's the configuration that I *think* you're looking for:

Code: Select all

# Enable ip forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Clear all existing iptables rules
/sbin/iptables -F
/sbin/iptables -t nat -F
/sbin/iptables -t mangle -F

# Create new rules for routing between your wireless and wired connection
/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
/sbin/iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
This assumes that your wireless connection is defined as wlan0, and that your wired connection is defined as eth0.
The example should certainly point you in the right direction.

Good luck, and let us know how it worked out!

Dave Driesen
Linux dev and oldskool elite

macey
Posts: 58
Joined: Thu May 24, 2012 6:05 pm

Re: Network sharing

Tue May 07, 2013 10:59 am

Thanks but:-

Code: Select all

sudo echo 1 > /proc/sys/net/ipv4/ip_forward
-bash: /proc/sys/net/ipv4/ip_forward: Permission denied

User avatar
DaveDriesen
Posts: 113
Joined: Sun Mar 31, 2013 8:28 pm
Location: Top of the food chain
Contact: Website

Re: Network sharing

Tue May 07, 2013 11:16 am

Hi!

Syntax error :)

You're outputting the result of "sudo echo 1" to /proc/sys/net/ipv4/ip_forward using your own privileges, which is giving you the Permission Denied message.

If your user lacks elevated privileges:

Code: Select all

# Either open a root shell and execute your commands there:
sudo su -

# or use the following syntax:
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
Try that -- thanks!

Dave Driesen
Linux dev and oldskool elite

macey
Posts: 58
Joined: Thu May 24, 2012 6:05 pm

Re: Network sharing

Tue May 07, 2013 12:38 pm

Ok, here is my input (and listing output which doesn't look right to me,
but what do I know :lol:) :-

Code: Select all

root@raspberrypi:~# iptables -F
root@raspberrypi:~# iptables -t nat -F
root@raspberrypi:~# iptables -t mangle -F
root@raspberrypi:~# iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
root@raspberrypi:~# iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
root@raspberrypi:~# iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT
root@raspberrypi:~# iptables -t nat -n -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  0.0.0.0/0            0.0.0.0/0           
root@raspberrypi:~#

Return to “Advanced users”