Third party cookies may be stored when visiting this site. Please see the cookie information.

PenguinTutor YouTube Channel

Configuring Linux / Raspberry Pi with a static IP address

To use Linux as a server or to access it remotely requires a static IP address. This is assuming a computer on a home network with a router that connects to the Internet over a broadband connection.

The following is based on the Raspberry Pi running Debian Linux, but will be similar for other distributions.

By default Linux will request a dynamic IP address which is issued by your router as required. Instead we need to provide it with an address that doesn’t change such as

Note that this address can be used on the local network, but not on the Internet – later we’ll look at providing access through your router / firewall from the Internet.

First find out what DHCP address has been allocated by using the ifconfig command – see the extract below


eth0      Link encap:Ethernet  HWaddr b8:27:eb:8a:71:a0

          inet addr:  Bcast:  Mask:


This is saying that the ethernet port 0 – has an IP address of

You will also need to find out what address your router is, using the route command

$ route
Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

default         UG    0      0        0 eth0     *        U     0      0        0 eth0

This shows that the router IP address (Gateway) is and all traffic is sent via that router.

At this point you will also need to check on what address range is being issued by the router. This depends upon the individual router. In my case I have a Belkin Wireless Router which can be reached by pointing a web browser to the IP address of the router

The LAN settings are shown below:

Belkin wireless router lan settings

In this case the local network has valid addresses from to The router is at address and any DHCP requests will be given entries between and (you can change the range of the DHCP addresses if required). I have used for this server.

To change to static IP address

cd /etc/networks

sudo nano interfaces

replace the line “iface eth0 inet dhcp” with

iface eth0 inet static




You should also take a look at the file /etc/resolv.conf

and check it has a nameserver entry (probably pointing at your default gateway) or direct to your ISP name servers.


If the file has the following:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)

then it is using resolvconf program which should instead be configured using the following two lines in /etc/network/interfaces


Whilst you can dynamically reload the network interface I suggest a reboot at this stage to make sure that the configuration is correct.

sudo reboot

After logging in check using ifconfig to confirm that we have a static ip address

eth0      Link encap:Ethernet  HWaddr b8:27:eb:8a:71:a0

          inet addr:  Bcast:  Mask:


Useful networking commands

To make dynamic changes to the network configuration use the ipconfig command.

The ipconfig command can also be used to activate and deactivate the interface, but that is better done using the ifup and ifdown commands which will provide details of any errors.

See the main Linux tutorials