Log into Raspberry Pi using Ethernet / Crossover cable ‘painlessly’

There are a few painful ways to share Internet connection on your Raspberry Pi without Wifi access, a hub, or a router.

This is a perfect setup when you have limited Ethernet port or no wireless access card.There are a few instances where we have to connect to a public Wifi, and not wanting to lose connection to our Raspi and still being able login and configure Raspi to connect to the network.

This can be typically done by sharing an existing PC / laptop connection via its spare Ethernet port. However most of the tutorials scattered on Mr Google land are either incomplete, outdated, or require several years of experience with Linux networking.

This tutorial attempts to simplify and summarise the whole process painlessly and hopefully is friendly enough for Linux beginners.

Hardware setup

1. A Wireless router with live Internet connection living in 10.0.0.0 network, with gateway 10.0.0.138.

2. A laptop connecting to an Internet via Wifi living in 10.0.0.0 network, with DHCP assigned by the router. Spare Ethernet port will be set to live in 192.168.1.0 network so it cant talk to external device with the same IP range.

3. A Rasperry Pi with Raspbian Installed living in 192.168.1.0 network

4. A crossover direct Ethernet cable or the normal PC-to-hub RJ-45 cable.

Applications needed

  • ifconfig (IP / port configuration tool)
  • dhcp3-server (your laptop will be the DHCP server and give IP number to Raspberry Pi)
  • firestarter
  • ssh (most Linux distros would have this pre-installed)
  • NetworkManager (the default Ubuntu networking configuration tool to enter Wifi details)


Preparing the Laptop

1. Check your internet connection. On Ubuntu you can use NetworkManager to setup your Wifi connection.

2. Modify or add your laptop network interfaces file as follows.

sudo nano /etc/network/interfaces
# connection for Internet Connection Sharing, assuming eth0 is ethernet port, and eth1 is wifi.
auto eth1
iface eth1 inet dhcp

auto  eth0
iface eth0 inet static
   address 192.168.1.2
   netmask 255.255.255.0
   network 192.168.1.0

Assuming that the router gateway is on different network, we can link them together with firewall application like Firestarter.

2. Install DHCP server

sudo apt-get install dhcp3-server

3. Enable packet forwarding on IPv4.

sudo nano /etc/sysctl.conf

Look for the line “net.ipv4.ip_forward=1″ and uncomment it.

4. Install a firewall to configure some Internet sharing and packet forwarding. We like FireStarter.

sudo apt-get install firestarter

5. Run and configure Firestarter so it uses Eth1 (wlan) Eth0 (ethernet),

6. Add modify dhcp3 configuration file that is produced by FireStarter so it looks like below. Set ipforwarding to be on (highligted in bold).

sudo nano /etc/dhcp3/dhcpd.conf
# DHCP configuration generated by Firestarter

ddns-update-style interim;

ignore client-updates;
subnet 192.168.1.0 netmask 255.255.255.0 {

  option routers 192.168.1.8;

  option subnet-mask 255.255.255.0;

  option domain-name-servers 10.0.0.138;

  option ip-forwarding on;

  range dynamic-bootp 192.168.1.10 192.168.1.100;

  default-lease-time 21600;

  max-lease-time 43200;

}

7. Restart DHCP server.

sudo service dhcp3-server restart

8. Restart networking

sudo /etc/init.d/networking restart

Raspberry Pi Network Configuration

1. Enable DHCP on Raspi’s eth0

auto lo

iface lo inet loopback
iface eth0 inet dhcp

2. Restart network interfaces.

3. Link both Raspi and laptop with crossover cable. Turn on / Reboot Raspi, it will assign IP address given by laptop’s DHCP server.

4. Test the connection.

tail /var/log/syslog

You will see the new IP address in one of the lines that says “[raspberrypi]”. Expect something like 196.168.1.10

5. Log into Raspi via SSH on your laptop’s command prompt

sudo ssh pi@196.168.1.10

6. Ping some external address like www.linuxcircle.com

ping www.linuxcircle.com

If you see a response, it is done! You can start configuring your Pi painlessly! Post us some questions?

 

Reference

  1. http://www.mccarroll.net/blog/rpi_netbook/index.html
  2. http://pihw.wordpress.com/guides/direct-network-connection/
  3. http://interlockroc.org/2012/12/06/raspberry-pi-macgyver/
  4. http://shallowsky.com/blog/2012/Nov/09/
  5. http://morti12.blogspot.com.au/2012/08/network-connection-over-laptop-for.html
  6. http://roughlea.wordpress.com/raspberry-pi-experiences/configure-the-raspberry-pi-to-share-a-linux-internet-connection/

(8365)

  • http://alecthegeek.wordpress.com Alec the Geek

    You don’t need a X over cable. The Ethernet connection on the Pi will auto sense and configure itself accordingly.

  • Manuel Lopez

    I get lost at step 5, and the /etc/dhcp3/dhcpd.conf file isn’t even there for me to edit after I attempt to run and configure firetarter. Could someone flesh out how im suppose to configure firestarter?

    • http://www.linuxcircle.com John Dowe

      Where you able to run Firestarter GUI and select the right Ethernet and wifi ports?

      • Dipto Pratyaksa

        Once you installed Firestarter on your Ubuntu laptop, you can find it in your Systems menu.
        Then go to ‘Preference’ and select the ports.

    • Dipto Pratyaksa

      Please read some tutorials on using Firestarter. Once you get the basics, it should be easy to share internet connection with any device.