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 ?

  • The easiest way is for your router to support DHCP and then you can just plug your Pi into your router. See this tutorial.
    – gideon
    Jun 25, 2013 at 8:19

4 Answers 4


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.

  1. 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.x pattern (I used, for example), and for the DNS server, you can enter, for example, (one of Google's Public DNS servers; another one is You can also go the OpenDNS route, which would be or

  2. Configure the eth0 interface 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 # or whichever unused IP you want to assign to the RPi
    gateway # i.e. IP that you assigned the ethernet in step 1
  3. Now edit /etc/resolv.conf ($ sudo vim.tiny /etc/resolv.conf):

    Change the contents to:

    nameserver nameserver nameserver

    Again, change the last two nameservers to whichever DNS you prefer.

  4. Now reboot your RPi (sudo reboot).

  5. 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.

  6. Once your RPi has booted up again, check its new static IP address:

    $ ifconfig


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.

  • I believe this is a better solution if you have the hardware for it, it could even be a router or a hub but a switch would work fine too.
    – John
    Jun 26, 2013 at 19:42
  • @John Just to clarify, in this setup this particular setup has a (presumably) DSL, cable, or wireless connection which is handed off in the form of a single Ethernet connection. This device is a router, so there is little reason to add a second router(unless you have one laying around, It will work, just add unnecessary complexity). A hub would work as well, but is old technology, and can lead to problems in the future.
    – Butters
    Jun 27, 2013 at 1:40

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:

  • actually my desktop is running Linux. So if you can point me to good tutorial for linux.
    – Jimit
    Jun 26, 2013 at 5:27
  • @Jimit is it ubuntu?
    – John
    Jun 26, 2013 at 5:39
  • yes,Its Ubuntu.
    – Jimit
    Jun 26, 2013 at 6:16
  • @Jimit added link
    – John
    Jun 26, 2013 at 6:51
  • thanks. this killed my ssh connection and now i cant get it back
    – blarg
    Oct 4, 2013 at 19:57

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.

  1. Also you need to enable ICS[Internet Connection Sharing] in the host(Desktop-the one that is sharing its internet connection with Pi ).

  2. 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.

  3. 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....


*Note: Here eth0 refers to the port in your desktop that is connected directly to the router.

  1. Open $leafpad /etc/shorewall/shorewall.conf

    Here, ensure that IP Forwading is set to on.


  2. Restart Shorewall

    $sudo shorewall restart

  3. 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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.