Computers

Configuring the Raspberry Pi as a Headless Ethernet-to-Computer Tether w/ Internet Sharing to Macbook Pro

photo
This article will walk you through a setup for the Raspberry Pi to enable it to be accessed via ethernet-computer, specifically with the Macbook Pro running OS X.8.5 (developer). After the initial configuration, you will never have to plug your raspberry into a router EVER again… unless you explode something in the /etc/network/interfaces file, which we’ll explore soon.

The standard configuration requires that you have:

-An SD card with about 4GB + formatted using the program from https://www.sdcard.org/downloads/formatter_4/eula_mac/ – Note: use the full erase option and MAKE SURE YOUR TARGET IS THE SD CARD. This process will take a few minutes.

-A copy of the NOOBS installer : NOOBS_v1_2.zip or NOOBS_v1_2.zip.torrent (mac users, use the legal torrent with a client like uTorrent [Download Now])

-A TV or monitor with HDMI (easiest and by default where the Raspberry sends its video output)

-Patience

-A USB connected keyboard

-Mouse (optional, but “perhaps” required: see below)

-WiPi wireless card (also optional, but it is likely that BOTH USB PORTS must be filled with something before the Raspberry device will initialize data from the SD card for the ‘first’ time boot operation)

-5V 700mA continuous power through “micro” USB (I use an old LG cable with an iPhone charger cube [white]).

- a STANDARD cat5e (crossover optional: more on this later)

-a router with internet connection

LETS DO IT:

After downloading and extracting the NOOBS .zip contents, open the NOOBS folder and DRAG all the contents onto the SD card. Again, do not simply place the extracted FOLDER with the NOOB contents onto the SD card. Just drag the contents from the folder onto the SD.

Now, eject the SD card properly. With the Raspberry unplugged completely (no single thing connected to it), place the SD card (upside down of course) into the Pi.

Next, connect your HDMI cable to the device and a display, followed by the mouse/wifi card/ keyboard, and ethernet cable. Plug the other end of the ethernet cable into your router.

When you are ready, power up the Raspberry Pi.

You will know that the device has initialized the information on the SD card when different colored lights begin to appear. If something has not been configured correctly, the device will idle with a red light.

If your device is not initializing for some reason, make sure your peripherals are plugged in. If you do not think the issue is hardware related, make sure you moved the contents of the extracted NOOBS folder onto the SD card – and not just the folder itself.

LET THERE BE LIGHTS

With the NOOBS installer, we can choose from several variants of Linux which will run on our small-but-mighty ARM device. I would suggest Raspbian, essentially a command-line/GUI version of Debian optimized for your Raspberry.

If you select Raspbian, allow the installer to do its thing (which means it is creating three partitions of the SD card: a Boot, the Main (usually ‘untitled’), and a Recovery).

You will be brought to a screen allowing for other options before proceeding into the main environment of your device. This is the raspi-config. Do these two things from the raspi-config screen:

-enable SSH

-allow the filesystem to use the remaining space on your SD card

After these have been selected, enter the environment of the Pi.

Default username: Pi
Default username: Raspberry

Once all is said and done, you should be at the command prompt of your Raspberry.

Set up the root with: $ sudo root passwd
Enter your password for root.

Now, let’s get rid of this TV and extra keyboard/mouse/ right away!

$ sudo su

$ nano /etc/network/interfaces

Here we are using nano to edit the interfaces file. Our goal is to have the device tethered to a computer and be independent of a Pi-to-Router connection for the Pi to use the internet.

First, take a look at the line: iface eth0 inet dhcp

We need to assign the Pi a STATIC ip in order to have some consistency when attempting to ssh to the device, the main method we’ll be using the initiate contact between the pi and our computer.

Change the dhcp line to:

iface eth0 inet static

Now we have declared the Pi is to establish a static IP. But we still need to fill in the other parameters. They are as follow:

Since we are using the Pi connected to our computer, we should NOT have the Pi’s static IP in the same 192.168.x.x range our computer shares with our router. So, below the edited line, let’s set up the Pi in this way (TYPE these lines; do not copy and paste):

address 10.168.2.31
netmask 255.255.0.0
broadcast 10.168.2.255

gateway 10.168.2.1

Control+x , yes to save, and let’s get back to the command line. Now from root, type:
$cd
$nano resolv.conf

Inside resolv.conf, you will likely need THREE nameservers. These are ways the Raspberry is able to establish names and entities out there in the deep dark ocean of the internet.

I use the following three and my resolv.conf looks like this:

nameserver 8.8.8.8

nameserver 192.168.0.1

nameserver 4.2.2.2

Control+x, yes to save, and back to the command line.

Now, it is a mystery to me as to why the Pi cannot grab net data without three nameservers. The first one is google. The second is my “router” out there in the room somewhere. But the 4.2.2.2 seems to be one of the most important with our configuration. Since the Pi is tethered to another device using the internet it gets through ANOTHER router, and the fact our computer is in someway acting as a router, I choose 4.2.2.2 instead of 4.2.2.1. Such is the case for our initial static configuration when we selected 10.168.2.xx rather than 10.168.1 (or 0) .xx. Since the Pi is going to be a parasite with the computer as the host, the static configuration also places the Pi on a different subnet, one lower than the Computer-to-Router (255.255.0.0 instead of our computer’s 255.255.255.0).

Now comes the fun part. The Pi is configured, but the computer needs to be set up to “listen” to traffic over the ethernet tether. And guess what…

… you don’t need a crossover cable.

Since this tutorial is for a Mac running OSX, I’ll explain the sharing setup first…
But let’s power down the Raspberry issuing the ($ halt) command. After the red light stays on and no activity is seen on your Pi screen, pull the plug.

Switch to the computer. Head to System Preferences>Sharing>Internet Sharing.

Share your connection FROM wifi (or whatever your computer usually uses) TO computers using ETHERNET (check the box). Feel free to enable internet sharing now but do not plug in the Raspberry quite yet. One more step.

System Preferences>Network

Click on Ethernet. Configure IPv4: Manually
IP Address: 10.168.2.11 (THIS SHOULD NOT MATCH THE PI – EVER EVER EVER)

Subnet Mask: 255.255.0.0

Router: leave blank

Click Advanced…

Enable IPv6 for “local-link only”

Head to the DNS tap and add 8.8.8.8 to the DNS list, removing all others.

Click apply.

Reboot the machine. Maybe reboot it three times. I always reboot it three times… (someone will get the joke).

Upon startup, I’d go back to System Preferences> Sharing and make sure you have enabled it. If you have, click the lock. This prevents anything else on your system from altering your settings in this given preference (and this lock is an important technique in manual configurations on Mac). Go back to your Network preference and make sure our changes to Ethernet have been saved. If they look intact, click the lock.

Grab the Pi. Plugin the Ethernet cable to the Pi and your computer and power ‘er up!

Now, inside Network preferences, Ethernet should turn green and you might see the IPv6 address assignment already. Give the raspberry a few seconds to startup.

Now, head to Utilities>Terminal and type
$ ssh root@10.168.2.31

You should be prompted to type your password.

If you get some message about a conflicting key and that it will not allow you to connect, head back to your mac terminal and > $ nano .ssh/known_hosts and wipe the contents. If you are like me and you’ve tried this a hundred different ways, there could be a conflict in there and the file rebuilds itself automatically. Don’t be afraid to kill things there.

And welcome to your Pi! To do a test as to whether or not your Pi is grabbing the internet connection from your computer, login to your Pi through ssh and ping 8.8.8.8 AND THEN to verify the other facet to the nameserver resolution is happening, ping google.com. You should see times in milliseconds. You can also go back to Terminal and type $ifconfig to see what interfaces are configured and accessible to your computer.

Afterthoughts:

Note the IP address I chose for my Pi corresponds to… well, Pi. .31. Just make sure if you use something different that you remember what it was.
It’s probably not a good idea to modify ext2, ext3, and ext4 filesystems from your Mac – say, in the instance you needed to change /etc/network/interfaces by popping your SD card into your Mac and using text edit. Now, I’ve found several third-party extensions supposedly allowing me to “access” these filesystems which Linux utilizes in these fashions (ext4 boot, ext3 and on down I believe). Now you can safely edit the base configuration files and in theory you can perform an ENTIRELY headless configuration by inserting a static IP line into one of these files, but I have yet to get it to work. So once your SD card is formatted for your raspberry, do all of the editing from within the Pi prompt. Just… Don’t… Textedit…

Another issue that could come up is having a WiFi card attached to your Pi. It will have its own configurations added to the /etc/network/interfaces file as well. I made sure to assign it a static IP as well and hashed-out (#) the line wpa-roam /etc/wpa_supplicant.conf since this file is trying to associate your device with a different workgroup than what you are tied into when connected to your computer (i.e. your Raspberry workgroup becomes thenameofyourcomputer.local when you do $ who am i).

To manually configure a known network for your Pi’s Wifi card (if you got one), you can actually throw it up into the 192.168.x.x range and it will work just fine.

My configuration looks like this, inserted below

allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface wlan0 inet static
address 192.168.0.41
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1

wpa-scan-ssid 1
wpa-ap-scan 1
wpa-key-mgm1 WPA-PSK(type of security, possibly 2 by default)
wpa-proto RSN WPA
wpa-group CCMP TKIP
wpa-ssid “NetworkName”
wpa-psk “YOURPASSWORD”

Anyway… More on multiple interfaces and potential uses later…

Congratulations! Welcome to your tethered headless Raspberry Pi with full internet sharing capabilities. Now get out there and see how to configure your Pi as a portable VPN ;D.

15 thoughts on “Configuring the Raspberry Pi as a Headless Ethernet-to-Computer Tether w/ Internet Sharing to Macbook Pro

  1. Hi, thanks for the post. I have successfully connected to my Pi from my Mac os via SSH (direct ethernet cable from pc to Pi). but I am unable to share my computer’s internet with my Pi. Do you have any suggestions?

    • Sure, could you be more specific with your Ethernet ip vs. the Pi ip? They should be on the same subnet together but NOT be assigned identical ip addresses. Anyway, please post your configuration and let’s try to get you set up :)

      • I assigned a static IP to Rpi “172.17.6.130″ and configured ethernet IPv4 in mac os to have an IP “172.17.6.129″ and subnet for both “255.255.0.0″ . I use my dongle to share my PC’s internet connection to Rpi.

      • I detect the problem. You are attempting to configure a device in the 172.17.6.130 range to talk to another device in the same range (172.xx.x.xxx). You need your ethernet static address to be separate from your internet source altogether. Your subnet is correct for the Ethernet and Pi. But, try for example: instead of 172.xx… try 10.1.x.11 for the Ethernet MANUAL IP address (static) and 10.1.x.some-other-number for the pi. Get the devices out of 172.xx… range and establish static connection with your wi-fi to your router. Wi-fi must be in a different range than the Ethernet and Pi. For this wi-fi device, try to configure manually (static) with the router (example: 192.168.x.x). Raise the wi-fi subnet to: 255.255.255.0.

        Other advice: between the Ethernet and Pi, you can establish link-local only IPv6 under Network:Ethernet:Advanced:IPv6:select “Link-local only.”

        Hope this helps!

        Nathan

      • thanks for your quick reply. I changed everything but I couldn’t change ‘link-local’ in IPv6 settings. I am using Mac OS 10.6.8 . I only found two options under Configure IPv6 under advanced tab viz automatically or manually. :(

      • Hey,

        I see. Another issue about your configuration was using USB instead of Ethernet to tether your Internet connection. The Pi is not very good configuring with USB Internet.

      • i tried with my wifi connection now with ip address 192.168.x.x, and changed the gateway in Rpi to my router’s ip. in IPv4 settings(manual) i changed ip to 10.11.x.x as you suggested. Stil,l I am not able to connect it. And i tried to change IPv6 setting to link – local only. but i couldn’t find where the option is… can you tell me where I can find “link-local only ” option. its not displaying in Network>advanced>IPv6

      • Please reread my article and responses and find that I have not suggested 10.11, rather 10.1.x.x., also suggesting 10.2.x.x as a redundancy; I believe the answers are present and transparent. Yet I am gladly willing to give time and thus we may go into this together. Did you check for syntax errors in your /etc/network/interfaces on the Pi side? Is your Pi within the broadcast umbrella of your MacBook Ethernet (Ethernet port append being higher in this case)? Is the cable plugged in? I know… But… Check for bad voltage to your computer or Pi. Any disruptions in current will result in defamed network status. Oops. However, if it is not hardware related on a power side and all cables have proper shielding, the computer not running excessively hot (?), you then believe for a moment that you will figure this out. Keep studying closely my friend.

        Nathan

      • hi, sorry to bother you again. I changed the ip address, but again no luck again. I connect to my Rpi via SSH ethernet cable. So i guess there is no problem in hardware or error in codes. The only problem is when I try to connect Rpi to internet via the same network I am getting an error. And I am not able to find “IPv6 local-link only” option.

      • First, you are no bother :D Let’s keep trying to figure this out together. In my article, I wrote about creating a resolv.conf file (from root, $ cd $ nano resolv.conf) in your root directory. Inside resolv.conf, you should have three nameservers. They will each have their own line and should look like this:

        nameserver IPaddress-of-Router, i.e. the Gateway
        nameserver 8.8.8.8
        nameserver 4.2.2.2

        Can you please take the time to post your Local area network IP addresses? Perhaps we can spot the problem there? You will need to provide: The MacBook’s primary gateway using Wi-Fi (router IP, not public), subnet, and DNS information; Your MacBook’s Ethernet configuration (IP, etc.); a printout of your Raspberry Pi’s /etc/network/interfaces file (the easy way is to copy and paste what you get from $ cat /etc/network/interfaces). Let’s work on it together until you nail it. Please note, this is a somewhat advanced networking topic, but I think we are very close. If you are able to ssh to the Pi “headless,” you are very close.

        Nathan

      • hi , I guess I found where my problem lies, though I am unable to resolve it. I used an app to find ip address of my router and add to my gateway.
        The output for $netstat -nr:

        Kernel IP routing table
        Destination Gateway Genmask Flags MSS Window irtt Iface
        10.168.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0

        and when i try to run $sudo ifdown eth0 i get the output “ifdown: interface eth0 not configured” I tried to add the output by $sudo route add default gw 172.x.x.x ( the ip address of router) i getting the error “SIOCADDRT: Network is unreachable”

        Any idea how to resolve this?

      • Hey Vikram, are you still stuck with your device configuration? I might have found something for you about different classes of networks. http://www.akadia.com/services/ip_routing_on_subnets.html

        There is another subnet you can assign to the Raspberry which is even lower than the 255.255.0.0 and 10.x.x.x. It would be the class A network configuration. Since your router appears to be in a “B” configuration, you can still go lower for the Pi and assign a 1.5.x.x IP to the Pi with a subnet of 255.0.0.0. :D Hope this helps. Sorry if we still haven’t managed to get the problem taken care of…

  2. this is my router ip 172.17.9.71 (as displayed in Network/Airport)
    IPv4 ethernet configuration :
    IP address : 10.168.2.11
    subnet mask: 255.255.0.0
    DNS server 8.8.8.8
    IPv6 ->automatic
    the lines in the file /etc/network/interfaces
    auto lo

    iface lo inet loopback

    auto eth0

    iface eth0 inet static

    address 10.168.2.31

    netmask 255.255.0.0

    broadcast 10.168.2.255

    gateway 172.17.9.71

    and lines in the file resolv.conf

    nameserver 172.17.9.71
    nameserver 8.8.8.8
    nameserver 4.2.2.2

  3. As an RPi newbie (within an oldie body) I shall try your approach, thanks Nathan. I’m fed up with having to connect my RPi to my TV via an HDMI cable.

    By the way, some of your other writing (e.g. on Aspergers) resonated with what I experience in my day job as a part-time teacher of blind children who also have various other special educational needs.

    The “stream of consciousness” idea interests me, the more so because it does not seem to fit very well with the norms of what is expected of students’ behaviour and/or “literacy” skills in what I might label as the standard educational model (UK version).

    If you have any suggestions about what makes a good teacher (from your personal experience) I would be very pleased if you would email me.

    Sincerely

    Peter Bryenton

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s