Raspberry PI – Configure Static IP with /etc/network/interfaces or dhcpcd

[Update] Changed order of the solutions due to comments. Added warning to solution 2.[/Update]

[A simple solution for Wifi can be found here.]

Problem

  • In the default config the Raspberry PI 3 is configured using Wifi and DHCP (Jessie)
  • If you want to use wired ethernet with a static IP config, you have to reconfigure

Solution 1 – dhcpcd

Open dhcpcd.conf

sudo nano /etc/dhcpcd.conf

A valid config would look like this:

interface eth0
static ip_address=192.168.2.77/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1

Restart networking and the work is done:

sudo service networking restart

Solution 2 – /etc/networking/interfaces (get rid of the dhcpcd service)

Warning: This solution is only useful, if you do not depend on dhcpcd, e.g. in a wired static IP environment.

Open the interfaces file with

sudo nano /etc/network/interfaces

A correct config would look like this:

auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168.2.77
netmask 255.255.255.0
gateway 192.168.2.1
dns-nameservers 192.168.2.1

Now you have to stop and disable dhcpcd, because it will make your config useless:

sudo service dhcpcd stop

sudo systemctl disable dhcpcd

Restart networking and the work is done:

sudo service networking restart

Fin

Advertisements

3 thoughts on “Raspberry PI – Configure Static IP with /etc/network/interfaces or dhcpcd

  1. Do you know what this does to the Pi’s WiFi?
    In Jessie on the Pi, the /etc/network/interfaces file contains the line:
    “# For static IP, consult /etc/dhcpcd.conf and ‘man dhcpcd.conf'”
    Running ‘man dhcpcd.conf’ on the Pi explains how to set up static addresses on the Ethernet and/or WiFi interfaces. See this thread in the Raspberry Pi Forums:
    https://www.raspberrypi.org/forums/viewtopic.php?f=28&t=132066&sid=5572fc310ab254c228d242fd83eb1051&p=934456#p934456

    Thanks,
    Dave.

    Like

    • Yes i know, but i present two solutions, including using the “right” dhcpcd solution.
      The interfaces solution is good, if you want to get rid of the service you don’t need in a static IP environment.

      Like

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s