Monday, March 11, 2013

Setting up your Pi

So you've got a raspberry pi, and it's all on line and everything.

The next thing to do is customise the board a little more.

Hostname
The first think that you might decide is I don't want to call my machine Raspberry Pi, perhaps you have two, and they can't both be called RaspberryPi.

Well you'll need to change the host name then...

first to find out your host name type:

pi@raspberrypi ~ $ hostname
raspberrypi


now to edit this you need to edit the host name file, so type
sudo nano /etc/hostname

Delete RaspberryPi and enter the host name you wish to use and then save the file.

next you'll need to edit the hosts file:

type sudo nano /etc/hosts
find anywhere that says Raspberry pi in this file and replace it with the host name of your choice.

Now reboot your device for the changes to take effect.


DHCP vs. Static
Next you'll find that it's all very well to have your Raspberry pi having an IP address just provided by your router. and you've assigned your NAT rule to point to that address, but ,what if the router breaks, or the router restarts, or your Raspberry Pi is off for a while and another machine gets given that IP address?

What you really want to do is assign a static IP address.

To do this you need to enter your network configuration details into a configuration file.

for this example I'm going to suggest that the whole network range is
192.168.0.1 - 192.168.0.254 (The subnet for this range is /24)
and that the router has the address 192.168.0.1
and that it serves DHCP addresses from 192.168.0.2 - 192.168.0.200

So first we need to edit the file that controls the network configuration for the network interface.

sudo nano /etc/network/interfaces

by default this file will appear like this:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp

you need to tell the machine to be statically assigned not DHCP, so change the line

iface default inet dhcp to iface default inet static


Then you need to say what address to use
so add the line
address 192.168.0.201

(this address is outside of the DHCP range served by the router, so there should never be an IP address conflict)

then you need to say what the subnet is by adding the line

netmask 255.255.255.0

and finally you need to put the gateway address, (which is your routers address

gateway 192.168.0.1

then save and exit this file. then restart your machine

(remember to restart use sudo reboot)

If you've changed the IP address of your Raspberry pi, don't forget to update your NAT rule on your router so that you can have external access!

No comments: