Linux · Raspberry Pi · Uncategorized

Changing IP address of your Raspberry Pi from Dynamic to a Static ip address


If your Raspberry Pi is configured to used a dynamic ip address and you would like to assign it a static address so that u can use it as a home server, use the following steps.

First of all, you need to identify the Raspberry Pis existing IP address. If you have access to the console, it is easy to do, if not you shall require to run some kind of network scan or check the DHCP lease for identifying the address. Follow this link for identifying the ip address of Raspberry Pi using network scan.

You shall need to identify your devices

  • IP address
  • Netmask/Network address
  • Default gateway
  • DNS

If you have console access you can examine the IP address  using the following command ( this shall work both over ssh using putty and directly from the console)

ip addr

The output will be something similar to this, follow the bold section

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:25:43:23 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.7/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::88a5:bc2e:fd52:87fd/64 scope link
valid_lft forever preferred_lft forever

This indicates the ip address of the RaspberryPi device is 192.168.1.7

The netmask is /24 or 255.255.255.0

Which makes the network address of 192.168.1.0

To find out the default gateway run

route -n

You shall see a similer output of

pi@raspberrypi ~ $ route -n
Kernel IP routing table
Destination         Gateway         Genmask          Flags      Metric Ref     Use       Iface
0.0.0.0               192.168.1.1     0.0.0.0              UG         202     0        0            eth0
192.168.1.0        0.0.0.0            255.255.255.0   U           202     0        0            eth0

Default gateway 192.168.1.1

To find out the dns addrss assigned by the dhcp server

cat /etc/resolv.conf

pi@raspberrypi ~ $ cat /etc/resolv.conf
# Generated by resolvconf
nameserver 192.168.1.1

DNS server/Name server is 192.168.1.1

Now that we have the information we need to change the Raspberry Pi configuration from dynamic to static we can start changing the configuration. Before we make any changes, it is wise to make a backup of the file you intend to change

sudo cp /etc/network/interfaces /etc/network/interfaces.orig

Now edit the file

 sudo nano /etc/network/interfaces

You shall see something like this

/etc/network/interfaces

Remove the line that reads

iface eth0 inet manual

Add the following

allow-hotplug eth0
iface eth0 inet static
address 192.168.1.201
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1

Now to check run

sudo service networking restart

Your device ip address is static.

Run

ifconfig
route -n
cat /etc/resolve.conf

Try pinging other hosts check connectivity. Hope you find this tutorial useful.

Advertisement

One thought on “Changing IP address of your Raspberry Pi from Dynamic to a Static ip address

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s