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 TV or monitor with HDMI (easiest and by default where the Raspberry sends its video output)
-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:
-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):
Control+x , yes to save, and let’s get back to the command line. Now from root, type:
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:
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 22.214.171.124 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 126.96.36.199 instead of 188.8.131.52. 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.
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
Enable IPv6 for “local-link only”
Head to the DNS tap and add 184.108.40.206 to the DNS list, removing all others.
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 email@example.com
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 220.127.116.11 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.
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
#iface wlan0 inet manual
iface wlan0 inet static
wpa-key-mgm1 WPA-PSK(type of security, possibly 2 by default)
wpa-proto RSN WPA
wpa-group CCMP TKIP
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.