2

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 '13 at 8:19
1

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

  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 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
    
  3. Now edit /etc/resolv.conf ($ sudo vim.tiny /etc/resolv.conf):

    Change the contents to:

    nameserver 10.2.2.2 nameserver 8.8.8.8 nameserver 8.8.4.4

    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

3

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 '13 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 '13 at 1:40
3

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:

Windows:

Mac:

Ubuntu

Also helpful for Ubuntu:

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

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

Configuration:

 Router[eth0]------[eth0]Your Desktop(+firewall running)[eth1]------[eth0]Raspberry.

I guess the illustration of the configuration is clear.

Instructions:

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

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

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

    Here, ensure that IP Forwading is set to on.

    i.e IP_FORWARDING = 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, privacy policy and cookie policy

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