Raspberry Pi Tutorials : how to assign static IP and change hostname

Making a Raspberry Pi cluster requires an initial setup to be performed. Here I assume that the OS that is running is Raspbian. So once the cluster is built generally one Raspberry pi designated as the  master node controls the functionality of all the other nodes. So this post deals with how the master node connects to or other nodes ,how you can use the master node to login to any other node in the cluster, how to assign static IP address and how to differentiate each of the nodes from the other by assigning different hostnames.

Assigning static IP address :

The first thing that has to be done is assign static IP address to each PI . This helps to connect to other PIs(nodes) via SSH (Secure Shell) . So first use the command :


This lists all the IP addresses. My result of running the command ifconfig was :

inet addr: bcast addr: mask:

Make a note of these addresses. So, from the above result, the inet address indicates the IP address of the node. What we do now is assign addresses to each node. The first step in it is to decide a range of IPs . I had 5 nodes and so I decided to take the range to . Once the range is fixed login to one of the PIs.
Also, make a note of the gateway address by typing the following command

sudo route -nee

Gateway: 192.168.3. 1

The final step is to modify the interface file :

sudo nano /etc/network/interfaces

Remove the line that reads

iface eth0 inet dhcp

Add the following:

iface eth0 inet static
address #change according to your range

save by pressing CTRL+X and then type Y to save and exit. then reboot the PI using :

sudo reboot

Type the following command to ping your gateway address or router and will return :

ping  -c3

The response should look somewhat like this :

64 bytes from icmp_req=1 ttl=255 time=2.18
64 bytes from icmp_req=2 ttl=255 time=2.43
64 bytes from icmp_req=3 ttl=255 time=3.24


Learn  how to make your Bench Automation Raspberry Pi computer now!!!

One last thing that needs to be modified is the /etc/resolv.conf file. This file contains information of DNS name resolvers that allow your raspberry pi to resolve names to IP addresses. For example, if you ping http://sourcedexter.com, the raspberry pi will have to determine the IP address of my python tutorials website,

Enter the following command to edit the resolv.conf file:

sudo nano /etc/resolv.conf

Enter the follow Google public DNServer IP address:


Press CTRL-X to exit but remember to save the file by accepting the changes.

Now type ifconfig and the new IP will be the one you would have assigned.Repeat this for all the other nodes on the cluster individually.


Change the hostname manually

If SSH is not installed then the hostname can be changed manually by logging into each of the raspberry pi individually and changing the hostname file as :

sudo nano /etc/hostname

By default the content of the file is :


change it to what you want. for example, if the new hostname should be client003 , then delete the existing name and type the new name :
press CTRL+X followed by Y to save and exit. So from the next time you login the new hostname will be seen.



SOURCE :   http://www.suntimebox.com/ ,  http://www.southampton.ac.uk/~sjc/raspberrypi/

Using secure shell (ssh) for login and secure copy (scp) for data transfer on Linux

SSH stands for secure shell. It is an encrypted remote login protocol. Once it has been set up on each node, it can be used to communicate with various other nodes in that network.

The main benefits of SSH are:

  • SSH uses the RSA encryption algorithm to generate public and private keys, making intrusion extremely difficult.
  • Since SSH is a remote login protocol, it can be configured on a laptop. That means you can use your laptop to wirelessly connect to the raspberry pi cluster.
  • Because protocols like SCP (Secure Copy) and SFTP (Secure File Transfer Protocol) run on top of SSH,  you can use them to transfer files and folders directly from one node to another.
  • SSH supports one time log in. This means that you only have to enter credentials the first time you log in. From the second log in onwards, it’s not necessary.

To log in to any other node from the master node use the command:

ssh pi@
(change the IP address to represent your IP address) .
This will ask for a password. Once you log in, all the commands you type will run on that node and not on the master.

SSH can also be used to run commands directly on the other nodes. For example, to   change  the hostname of  different nodes, use this command:

ssh pi@  ‘sudo echo “cilent001″  | sudo nano /etc/hostname
ssh pi@  ‘sudo echo “cilent002″  | sudo nano /etc/hostname
ssh pi@  ‘sudo echo “cilent003″  | sudo nano /etc/hostname       …and so on.


This way SSH can be used to run commands on other nodes from the master node as:

ssh pi@  ‘sudo poweroff’      


latest blog pic

This command safely shuts down the node with IP address

The following figure shows how SSH is used to log in to a worker node ( and from the worker node, get the control terminal back to the master node.

As you can see in the above figure, logging in to a worker node happens directly. But each time the control of the terminal comes back to the master node (, the login credential has to be entered.

So after issuing commands via SSH to other nodes, there might be situations where data has to be sent to multiple nodes. If the number of nodes are small, then we can manually log in to each node, connect it to a display and keyboard, and send files. But this is a highly inefficient way to do it when the size of the cluster is large.

An easier way would be to use SCP to send files. Install SCP using the command:
sudo apt-get install scp

Read my full post on HowToforge : here