Actually I have a single ethernet port on my router for connection. So that I can only get my desktop working with my router. Now I wanted to connect Raspberry PI to the internet through router. This can only be possible if somehow I can share my desktop's connection with raspberry pi since my desktop has two ethernet port. So how can share my desktop's connection with raspberry pi and connect raspberry Pi to Internet ?
I just did successfully this with my Mac a few days ago. I'm not sure if the instructions would be the some for Linux/Windows, but hopefully some of these parts will be relevant/useful to you.
Caveat: These instructions tell you how to manually configure the interface because that was the only way that worked for me.
Notes: I own a late 2011 MacBook Air, and I have Raspbian installed on my RPi.
Assign a static IP address to the Ethernet interface on your Mac. (System Preferences -> Network). Next to Configure IPv4, select Manually in the dropdown. For the IP address, assign something in the
10.x.x.xpattern (I used
10.2.2.2, for example), and for the DNS server, you can enter, for example,
188.8.131.52(one of Google's Public DNS servers; another one is
184.108.40.206. You can also go the OpenDNS route, which would be
eth0interface on your RPi. If you're paranoid (like I am), make a backup first:
$ sudo cp /etc/network/interfaces /etc/network/interfaces.bak
Then open the file for editing with vim (or whichever editor you prefer):
$ sudo vim.tiny /etc/network/interfaces
You'll see the following:
auto lo iface lo inet loopback iface eth0 inet dhcp allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf iface default inet dhcp
Go ahead and change it to:
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 10.2.2.3 # or whichever unused IP you want to assign to the RPi netmask 255.255.255.0 gateway 10.2.2.2 # i.e. IP that you assigned the ethernet in step 1 network 10.2.2.0 broadcast 10.2.2.255
$ sudo vim.tiny /etc/resolv.conf):
Change the contents to:
nameserver 10.2.2.2 nameserver 220.127.116.11 nameserver 18.104.22.168
Again, change the last two nameservers to whichever DNS you prefer.
Now reboot your RPi (
Turn on Internet Sharing on your Mac: System Preferences -> Sharing -> Internet Sharing. Next to Sharing your connection from, select however you're connected to the internet on your Mac (in my case, AirPort). Then, under To computers under, select Ethernet.
Once your RPi has booted up again, check its new static IP address:
My personal opinion is that bridging or sharing your desktop connection is the wrong way of going about this. When you bridge your connections on the desktop, your Pi will only have a connection when your desktop is on and logged in.
The 'proper' way of fixing this is to get a small Ethernet switch. Plug your router into the up-link port, your desktop into one port, and your Pi into another. This has no dependencies on the state of your desktop, and your Pi will always be online. You also eliminate one other point configuration complexity on your network.
There are a couple of solutions here, but the easiest would be to just plug the raspberry pi into one of the ethernet slots of your desktop. Then, connect your desktop to the router. Then what you have to do is setup Connection Sharing on your desktop. Here is more info on connection sharing:
Also helpful for Ubuntu:
While it would be most appropriate to use a Network Switch for your requirements.But, as you have talked about the sharing internet connection between your desktop and Pi,which i will be explaining in this answer.
Assuming your desktop is running a Linux Distro[Eg: Ubuntu,Red Hat, Debian etc].
Router[eth0]------[eth0]Your Desktop(+firewall running)[eth1]------[eth0]Raspberry.
I guess the illustration of the configuration is clear.
1.In order to configure your raspberry pi to share a internet connection you will require a firewall.
Also you need to enable ICS[Internet Connection Sharing] in the host(Desktop-the one that is sharing its internet connection with Pi ).
Check that the the RaspberryPi and your Desktop form a LAN.Check this by pinging either way for connectivity.If any problem,try fixing this prior to moving ahead with further instructions.
Install the Shorewall Firewall in your Desktop[I am using Ubuntu Linux]:
$sudo apt-get install shorewall
5.Next,you need to configure shorewall for IP Masquerading.
Run $leafpad /etc/shorewall/masq and configure accordingly....
#INTERFACE SOURCE ADDRESS PROTO PORT(s) IPSEC eth0
*Note: Here eth0 refers to the port in your desktop that is connected directly to the router.
Open $leafpad /etc/shorewall/shorewall.conf
Here, ensure that IP Forwading is set to on.
i.e IP_FORWARDING = ON
$sudo shorewall restart
Configuring the Raspberry Pi....
Assuming the Pi and Desktop are already pinging each other, you need to change the gateway of Pi to the ip address of desktop.
Open $leafpad /etc/network/interfaces
Under, eth0 set gateway as the
P.S: If you still face problem, doing it that way...please leave a comment.I will try to explain it more clearly :)