September 9, 2013 · connection debian ethernet firewall hacks raspberrypi raspi rpi server ssh tricks wicd

Etherneting Raspberry Pi (configure static eth0)

After running my webserver via WiFi connection for the past 2 months, I've finally decided to set a proper connection using Ethernet cable. I was postponing it, as I needed a 10m cable to connect my Pi to the nearest router. But, at last, I've managed to buy the cable and am preparing for setting up a proper connection of my server.

As mentioned, I've bought a 10m High Speed CAT6 Gold Headed Network Cable and a bunch of 100 x 7mm round cable clips to keep the cable near the walls. And that's it. everything else is done on the Pi.

I've connected the cable to my router, clipped it against walls so it climbs nicely to my RasPi nest. Now comes the tricky part which is configuring static IP address on my eth0 interface.

Setting up static IP

NOTE: Before you attempt to do any changes to your network connection, make sure you do not connect with your Raspberry Pi via ssh. You may loose connection in the process. It's a good idea to connect your RPi to an external monitor and use keyboard, or connect to your PC via serial port.

Using a static IP is very useful when you want to easily access your RPi without need to get its IP address every time it boots or reconnects to the network. It simplifies the work with SSH, FTP, and, most of all, lets the RPi web server run smoothly without the need to update DNS records if you have your own domain name as I do.

To achieve this, you only need to modify the /etc/network/interfaces file that holds your network interfaces configuration.

NOTE: Before you attempt to make any changes, especially with system files, it's a good idea to make backup of the file you want to edit. We need root privileges, to edit system files, so we use sudo before the command. Type:

sudo cp /etc/network/interfaces /etc/network/interfaces.old

If anything goes wrong, you can just overwrite the broken file with the old version:

sudo cp /etc/network/interfaces.old /etc/network/interfaces

You can edit the file with any text editor such as vim, joe, ed, nano, etc. Personally, I prefer to use nano.

sudo nano /etc/network/interfaces

In the file, look for a line such as:

iface eth0 inet dhcp

This helps to enable the DHCP client. We want to disable it. Put a hash at the beginning of the line to disable it or delete it:

#iface eth0 inet dhcp

In the file you must insert the following lines:

auto lo iface 
lo inet loopback auto 
eth0 iface 
eth0 inet static 
address #your static IP 
gateway #your gateway IP 
netmask #your network address 'family' 

Only the address and netmask data are strictly required.

Netmask usually is, and your gateway should end with 1: (your router IP or the one given by your ISP).

If you are not sure, of any data, check your router LAN configuration.

Now, we need to restart the network:

sudo service networking restart

If that fails, try:

sudo service networking reload

And in very rare cases reboot your RPi:

sudo shutdown -r now

To check if the connection is set up properly, type ifconfig and you should see something like tihs:

eth0 Link encap:Ethernet HWaddr b8:27:eb:fb:c0:c8 
     inet addr:x.x.x.x Mask:
     inet6 addr: xxxxxxxxxxxxxxxx Scope:Link
     RX packets:1958667 errors:0 dropped:43175 overruns:0 frame:0
     TX packets:2711788 errors:0 dropped:0 overruns:0 carrier:0
     collisions:0 txqueuelen:1000` 
     RX bytes:432321252 (412.2 MiB) TX bytes:3512983066 (3.2 GiB)

for your wired connection.

If you still encounter any problems, such as no data flow even if the connection seems to be ok, and you are using any network managers, such as network-manager, or wicd, you may have to disable connection established with them. For wicd try:

  1. Access wicd menu:
  2. Hit [Shift] + P to enter preferences menu
  3. In General Settings under Network Interfaces tick with Spacebar 'Always show wired interface' and 'Always switch to wired connection when available' and make sure the Wires Interface shows eth0. Hit [F10] to save.
  4. In the main menu, you should now see Wired Networks above Wireless Networks with the line:
    0 wired-default vvv
    If not, hit Q to quit and run wicd-curses again.
  5. Enter the wired-default to configure it by pressing the Right Arrow on your keyboard.
  6. Tick Use Static IP and enter your connection details as used in /etc/network/interfaces file. Hit [F10] to save.
  7. Hit [Shift] + D to disconnect form existing connection, then highlight the 0 wired-default vvv wired interface and hit C to connect. After few seconds you should get your connection.
  8. To make sure everything works fine, restart your RPi with sudo shutdown -r now command.

Everything should work well now and you can enjoy your static wired connection.

  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket