Tuesday 4 November 2014

RPi Home Server. Part 1: Headless Pi

Hello everyone, today we are going to prepare our own Home Server with the Raspberry Pi.
In this first part we are going to download and burn the OS into the RPi, do the basic configuration to the RPi, connect to it through SSH and set up a static IP address so that it doesn’t change.

 

Advantages:

  • You’ll learn how to manage a Linux Server
  • You’ll learn how to burn an image to an SD card
  • Install a OS
  • Set up a web server
  • Set up a Samba file sharing network
  • Control Samba Users
  • Use no-ip to get access from outside of your network
  • Use a command line to install packages
  • Mount hard drives permanently
  • Understand port-forwarding
  • Set up a web based torrent server
  • SSH into the RPi to execute commands
  • Download automatically any show as their air.

 

Services:

  • Webmin Admin Interface: Webmin is a state of the art server management web user interface. It allows the installation, management and control of the various services you may wish to add to the server. The interface is great for first timers as it minimalizes the required use of the command line interface.
  • Samba Windows File Server: Samba is software that can be run on a platform other than Microsoft Windows, for example, Linux. Samba uses the TCP/IP protocol that is installed on the host server. When correctly configured, it allows the host to interact with a Microsoft Windows client as if it is a Windows file and print server.
  •  Transmission BitTorrent WebUI: Transmission is designed for easy, powerful use. It's web user interface allows torrent's to be remotely added, then downloaded to the default torrent location. This location can then be shared via samba/ownCloud to allow remote streaming of downloaded content.
  • Apache Webserver: The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems such as Linux. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.
  • No-ip Sync Client: The no-ip sync client will allow us to give the server a 'external static address', such as "yourname.no-ip.biz". The sync client will update the current ip your ISP's allocated you every ten or fifteen minutes. You must first create a free account at no-ip.biz, but more on that later.

Hardware:

The hardware that we’ll need will be pretty basic:
  • x1 Raspberry Pi (really?), I’ll be using the model B, the B+ would also work for this purpose but the model A would maybe be a little bit short on power and doesn’t have an Ethernet connector.

  • x1 RPi Case. The one you prefer, there are a lot of them out there, you can even build your own with LEGO.

  • x1 External Hard drive. You’ll need one that has an external power source because the RPi can’t power it from USB as it only uses 5V of power.

  • x1 Ethernet cable.

  • x1 SD Card. It’s strongly recommended to get 8gb or above. I use a 8gb class 10 SD card.

OS:

You can use different OS’s for the RPi.
I’ll be using Raspian, you can download it from here, or download NOOBS and install it directly.
There is also the raspliance which is also used in various servers and comes pre-installed with turnkey.

 

LET’S BEGIN:

 

Burning the image

First of all we’re going to download the Raspian Image for the RPi from here. Or as said before you can download NOOBS from the same link and it will automatically install Raspian (or any other OS available in NOOBS)
image
Then if we are using Windows we’re going to download Win32DiskImager and install it. Open the program and you’ll see this.
image
Select the image file and the SD card Letter (F: in my case) and click write. It will take from 5 to 10 minutes depending on the write speed of your SD card writer and on the SD card.

 

Installing the OS

First of all plug in the SD card into the RPi, connect it to a monitor through HDMI, connect a keyboard and finally connect the power cable and wait until it asks you for the username or this appears:
image
If it asks you for the username put the default one “pi” and password “raspberry” (you won’t see anything while you type in the password). Then execute:
sudo raspi-config
and you should be like in the last image.
Then select expand filesystem so that your SD card doesn’t get limited by the image file. You MUST change your password to one secure because the most probable thing is that the RPi will be available to the whole internet and a LOT of people know the default user/password for the RPi. Then select the Internationalisation Options that best fit your keyboard and place you live in. Then go to Advanced Options and select memory split

image
and type 16 so that your GPU only uses 16mb of memory and the rest of it is for the other services. Only do this if you aren’t going to use the X-server (RPi desktop).
image
Then go to SSH (also from the advanced options) and enable it so we can connect to it from our computer.
image
If you want you can overclock the RPi but it’s not needed for what we are going to do. For the raspi-config we are done, select finish and it will ask you if you want to reboot and select yes.
Now to shutdown just type
sudo halt
Now we don’t need any more the display and the keyboard, you can disconnect them and connect it to you router through Ethernet. Then go to your computer (finally, somewhere where we can use the mouse : ) ). First of all if your in windows download the latest version of putty here. Then you have to get the IP address of your RPi, there are a lot of tools out there to scan your network, I recommend using this one because it is very easy to use. You just put explore and you look for the one with hostname “raspberrypi” and you’ve got the RPi’s IP address. Open Putty and put the IP address of the RPi in marked box and click in open.
image
Then it will ask if you trust the server and you will put Yes. Then you’ll have to login to the RPi as before. Username “pi” and password “password?”.
image

 

Setting up a static IP address

So that the ip address of the RPi doesn’t change every time that it boots up we will have to set up a static IP address.
First lets execute this command
cat /etc/network/interfaces
image

In this line we can see that for the “eth0” interface we have “dhcp” (Dynamic Host Configuration Protocol) enabled, that means that it will ask for a random IP to the router every time the RPi is connected to the network. We are going to change that by editing this file. But before we need to get some information. We’ll execute this command
ifconfig
image
We’ll write down the text highlighted in blue:
  • inet addr: 192.168.0.206 (the IP of the RPi)
  • Bcast: 192.168.0.255
  • Mask: 255.255.255.0
And
netstat –nr
image


  • Gateway: 192.168.0.1
  • Destination: 192.168.0.0 (forgot to put the square around it, it’s in the first column, sorry)
  • Now we’re going to put this information in the /etc/network/interfaces file with the command line editor “nano”.
    sudo nano /etc/network/interfaces
    image
    image
    Change the
    iface eth0 inet dhcp
    to
     iface eth0 inet static
    Then directly below it put the information that we gathered before (put the values that you found before).
            Value to put                                                   Value found before
    address 192.168.0.206         --> inet addr
    netmask 255.255.255.0         --> Mask
    network 192.168.0.0           --> Destination
    broadcast 192.168.0.255       --> Bcast
    gateway 192.168.0.1           --> Gateway
    It should look like this but with your values
    image
    Now press “Ctrl+X” to exit and “y” to save and “Enter” to finish.
    For convenience I’ll change the ip address to something I know isn’t occupied on the network like 192.168.0.101 (remember that if you change the IP when you try to SSH into the RPi you’ll have to put the IP that you putted before not the first on (Eg: In my case 192.168.0.101 not 192.168.0.206)
    Now let’s reboot by typing in
    sudo reboot
    Log in as normal and check by executing the command
    ifconfig
    image
    (as said before I changed the IP address for convenience to 192.168.0.101)
    And you can also do another check by pinging your router address (gateway address) by executing this command.
    ping 192.168.0.1 –c10
    (The –c10 is so that it only executes it 10 times if not it would do it endlessly, in case you don’t remember to put it you can press “Ctrl+C” to exit the program)
    image
    As we can see there are no problems.
    Now we have a IP address that won’t change. YAY!

    Next Part

    In the next part we’ll be installing Webmin, do the basic configuration, mount the Hard Drive and create a Samba file share.

     

    Finish

    Hope you liked my first post/tutorial, please comment on what you would like to see from me or any thing you didn’t like about this post.
    Thanks again and if you liked it please share it.
    :)