` Connecting a Raspberry Pi to a ubuntu netbook

Connecting a Raspberry Pi to a ubuntu netbook

The Raspberry Pi is a tiny, cheap single board computer designed to hook up to a TV and help with teaching programming.

Mine arrived recently but as I don't have a modern (HDMI capable) TV or wifi dongle, it was difficult to start developing with it. I also don't have a free connection on my router to plug the R-Pi in there. I decided figure out how to make a direct ethernet connection between the R-Pi and my Ubuntu 12.04 netbook, and use the netbook's keyboard and display. My netbook has an ethernet port which I don't normally use, and a built in wifi card which I use to access a wireless router. These instructions should work for a netbook or laptop running Ubuntu 12.04, and may help in configuring other versions of linux.

Warning - reconfiguring networking can be quite tricky. The steps outlined below worked pretty well for me but you may see different results on your system. I recommend taking a backup of all files that are modified when following these instructions.

Note that to edit the files mentioned below, you'll usually need to use sudo to run your favourite editor. I used the following command:

sudo vi <filename>
                

Configuring the R-Pi

The first thing to note is that to connect the ethernet ports on the R-Pi and the netbook directly, you'll need to use a crossover cable (ie the standard patch ethernet cable used to connect a computer to a router will NOT work).

You will also need to make some minor changes to the R-Pi, depending on which OS you've installed. I have the debian "squeeze" distribution and I needed to enable ssh (thanks to this blog post on how to do that). I hooked my R-Pi to a (very blurry) TV and USB keyboard, logged in and ran the following to enable secure shell (ssh) connections to be made:

sudo mv /boot/boot_enable_ssh.rc /boot/boot.rc
                

I also modified /etc/dhcp/dhclient.conf, to find and edit the line with the command send host-name commented out, changing it to:

send host-name "raspberrypi";
                

As we'll see later, this will be useful in identifying the IP address assigned to the R-Pi. After making these changes, reboot your R-Pi (you can also disconnect the TV and keyboard at this point). Don't connect the R-Pi to the netbook just yet though.

sudo shutdown -r now
                

Configuring the netbook

The remaining steps focus on the Ubuntu laptop/netbook. Firstly we will need to configure a subnetwork on the netbook's ethernet port (eth0). First backup the file /etc/network/interfaces (if you want to use the netbook's wired connection to connect to a router, you'll need to revert to this backup).

sudo cp /etc/network/interfaces /etc/network/interfaces.orig
                

Now edit the file /etc/network/interfaces and add the following at the end of the file:

iface eth0 inet static
        address 192.168.1.1
        netmask 255.255.255.0
        network 192.168.1.0
                

On Ubuntu, this entry ensures that the system networkmanager will not try and and manage the ethernet port eth0 (this just leads to trouble, believe me). Revert to the backup interfaces.orig to restore normal behaviour (ie to allow a direct cable connection from the netbook to a router to work properly).

The next thing we'll need to do is install and configure a DHCP server. This is a service which we'll configure to allocate IP addresses to computers that connect to the netbook on eth0. Install the standard DHCP server:

sudo apt-get install dhcp3-server    
                

You'll notice that the service will automatically start after the install completes but will report errors as we still need to configure it. First lets stop it if its running and ensure that the DHCP service is not started automatically at boot time.

sudo /etc/init.d/isc-dhcp-server stop
sudo sh -c "echo 'manual' > /etc/init/isc-dhcp-server.override"
                

Edit the file /etc/default/isc-dhcp-server and configure the INTERFACES setting to include eth0. This instructs DHCP to manage connections on the netbook's wired ethernet port, but not the wireless network. After editing the file should look like:

# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?
#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".
INTERFACES="eth0"
                

Now edit the main DHCP configuration file /etc/dhcp/dhcp.conf. We'll configure DHCP to assign network addresses in the range 192.168.1.100 to 192.168.1.200.

ddns-update-style	none;
default-lease-time 3600;
max-lease-time 7200;
authoritative;

subnet 192.168.1.0 netmask 255.255.255.0 {
  option routers 192.168.1.1;
  range 192.168.1.100 192.168.1.200;
}
                

Create scripts to manually enable/disable the R-Pi connection

Now we'll define two scripts to manually start and stop the necessary services for connecting to the R-Pi. Download these scripts to a location on your netbook and make them executable. You'll need to run the start_rpi.sh script before connecting up the R-Pi. You can also run the script stop_rpi.sh after disconnecting the R-Pi, to stop any unnecessary services.

start_rpi.sh
#!/bin/sh

# bring up the eth0 interface
sudo ifup eth0 

# start DHCP service
sudo service isc-dhcp-server start

# enable forwarding from the ethernet to wireless router
sudo /sbin/iptables --table nat -A POSTROUTING -o wlan0 -j MASQUERADE
stop_rpi.sh
#!/bin/sh

# stop the DHCP server
sudo service isc-dhcp-server stop

# shutdown the eth0 interface
sudo ifdown eth0 

Testing the connection

Lets try connecting the R-Pi and the netbook via the crossover ethernet cable. Run the start_rpi.sh script and then connect the netbook up to the R-Pi with the crossover cable, wait a few seconds and then check the system log.

tail /var/log/syslog
                

You should see an entry of the form:

Jul 26 18:32:19 dev-AOA110 dhcpd: DHCPACK on 192.168.1.100 to a8:f7:eb:62:43:c2 (raspberrypi) via eth0
                

This shows that DHCP has assigned the IP address 192.168.1.100 to the R-Pi. DHCP should re-assign the same IP address each time the R-Pi connects. This means we can edit the file /etc/hosts so we don't need to remember the IP address, to add the following entry:

192.168.1.100   raspberrypi
                

Check that the R-Pi can be ping'ed

dev@dev-AO722:~$ ping raspberrypi
PING raspberrypi (192.168.1.100) 56(84) bytes of data.
64 bytes from raspberrypi (192.168.1.100): icmp_req=1 ttl=64 time=0.927 ms
64 bytes from raspberrypi (192.168.1.100): icmp_req=2 ttl=64 time=0.790 ms
                

If ping is successful, next try and ssh to the raspberry pi

ssh pi@raspberrypi
                

You should be able to log in (the default password is "raspberry").

Displaying R-Pi applications on the netbook screen

The X-windows architecture makes it possible to launch applications on the r-pi and have them display using the netbook's X-server. One way to enable this is via the X11 forwarding feature of ssh. On the netbook, edit the file /etc/ssh/ssh_config and ensure that the following settings ForwardX11Trusted and AddressFamily are added or uncommented and configured as below.

Host *
#   ForwardAgent no
#   ForwardX11 no
   ForwardX11Trusted yes
   AddressFamily inet
   ...
                

Now try to ssh to the r-pi using the -X option.

ssh pi@raspberrypi -X
                

You should now be able to launch an application from your ssh session (for example, xeyes or xclock) and it will display on the netbook

Configuring internet access for the R-Pi

Another useful configuration step will allow the r-pi to access the internet through the netbook. On the netbook, edit the kernel parameters file /etc/sysctl.conf and uncomment the following line:

net.ipv4.ip_forward=1
                

After making this change, issue the following command to reload the settings.

sudo sysctl -p
                

You should be now able to ssh into the R-Pi and access the internet from there. Use ping to test connectivity.

ssh pi@raspberrypi -X
pi@raspberrypi:~$ ping www.slashdot.org
PING www.slashdot.org (216.34.181.48) 56(84) bytes of data.
64 bytes from star.slashdot.org (216.34.181.48): icmp_req=1 ttl=239 time=116 ms
64 bytes from star.slashdot.org (216.34.181.48): icmp_req=2 ttl=239 time=115 ms
                

 

Leave a comment

Anti-Spam Check
Comment