otalado
Posts: 6
Joined: Tue Oct 27, 2015 4:17 pm

Re: [Solved] Raspbian Stretch: Setting a static IP

Wed Oct 25, 2017 6:42 am

I have installed latest raspbian stretch lite (September 2017) on PI Zero, then performed update&upgraded on it. Then I set out to make my ethernet to have static IP address (following the instructions) :

1) ifconfig shows the traditional name i.e my network interface is named eth0 (not the 'predictable' enx name)

2) So I edited /etc/dhcpcd.conf and added to end of this file:

interface eth0
static ip_address=192.168.1.50/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 193.189.160.13 193.189.160.23

After reboot eth0 still have the IP address assigned by dhcp !?!

I don't know if raspbian stretch lite is different fom the raspbian stretch & desktop. If not, then the instructions need fixing.

I will now go the 'old' way by editing /etc/network/interfaces and disabling the dhcp. I only hope that this will not bite me somewhere unpleasant weeks from now

pcmanbob
Posts: 2218
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: [Solved] Raspbian Stretch: Setting a static IP

Wed Oct 25, 2017 9:04 am

if you look at the dhcpcd.conf file on stretch you will find a static IP configuration section all you need to do is remove the # from the start of each line and put your own IP addresses in save it and reboot and it will just work.
Here's a copy for the file from my test stretch lite set up on a pi3.

Code: Select all

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# static IP configuration:
interface eth0
static ip_address=192.168.1.16/24
static routers=192.168.1.1
static domain_name_servers=192.168.1.1 8.8.8.8

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

Bosse_B
Posts: 631
Joined: Thu Jan 30, 2014 9:53 am

Re: [Solved] Raspbian Stretch: Setting a static IP

Fri Nov 03, 2017 5:25 pm

I am trying to understand how to set my RPi3 with the latest Stretch image to use a static IP address 10.0.0.235.
Currently it is using 10.0.0.69, received by DHCP.
I am interfacing to it using PuTTY since it is headless, so messing up the reconfiguration will cause major problems...

This thread outlines how it is done by editing the /etc/dhcpcd.conf file, but the solutions do not mention the way yo set all items in the conf file.

My current setup is like this:

Code: Select all

$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.69  netmask 255.255.255.0  broadcast 10.0.0.255
        ether b8:27:eb:ba:c2:5b  txqueuelen 1000  (Ethernet)
        RX packets 10258  bytes 1039749 (1015.3 KiB)
        RX errors 0  dropped 159  overruns 0  frame 0
        TX packets 77  bytes 10488 (10.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
and the content of the /etc/dhcpcd.conf:

Code: Select all

 $ cat /etc/dhcpcd.conf
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=192.168.1.23/24
#static routers=192.168.1.1
#static domain_name_servers=192.168.1.1

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0
What should I change to make it work?
From reading this thread a possible setup would be:

Code: Select all

interface eth0
static ip_address=10.0.0.235/24
static routers=10.0.0.1
static domain_name_servers=10.0.0.3 10.0.0.7 8.8.8.8 
But what about the following:
static ip6_address
Will it get one from DHCP if this is not set? I don't want to use IPV6 internally anyway.
Is the above change all it takes, no other file to modify or anywhere else in this file to edit?
Bo Berglund
Sweden

pcmanbob
Posts: 2218
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: [Solved] Raspbian Stretch: Setting a static IP

Fri Nov 03, 2017 7:25 pm

Yes that setup looks nearly right.

Code: Select all

interface eth0
static ip_address=10.0.0.235/24
static routers=10.0.0.1
static domain_name_servers=10.0.0.3 10.0.0.7 8.8.8.8 
the only thing that looks a bit wrong is your DNS settings that would indicate that you are running 2 DNS's on your own network at addresses 10.0.0.3 & 10.0.0.7 ?
if you are not then your line should probably be like this

Code: Select all

 static domain_name_servers=10.0.0.1 8.8.8.8 
or you could add your ISP own DNS in place of 10.0.0.1

I very much doubt your router is giving out IPV6 IP's any way so don't worry about it what you are seeing is a default one set by the pi because one has not been given by the router.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

Bosse_B
Posts: 631
Joined: Thu Jan 30, 2014 9:53 am

Re: [Solved] Raspbian Stretch: Setting a static IP

Fri Nov 03, 2017 8:30 pm

Thanks,
I took the DNS input from running ipconfig /all on my Windows computer and it has these 3 server entries.
Meanwhile I bit the bullet and rebooted the RPi3 and it works fine.
Bo Berglund
Sweden

jag466379
Posts: 1
Joined: Tue Nov 21, 2017 3:23 pm

Re: [Solved] Raspbian Stretch: Setting a static IP

Tue Nov 21, 2017 3:35 pm

Hello All, This seems to be the relevant place for my question, apologies if not.
I would like to ADD a static address on a different subnet, but keep the DHCP running.
It used to be easy to do this but now there are so many conflicting instructions.
Does anyone know how to do this the proper way?
Thanks in advance.
Jim

Migzy
Posts: 2
Joined: Tue Nov 21, 2017 3:53 pm

Re: [Solved] Raspbian Stretch: Setting a static IP

Tue Nov 21, 2017 3:59 pm

You forgot about the netmask... if you don't specify one it defaults to 255.0.0.0 which will obviously mess things up a bit if you are on a different subnet to the pi.
Also the interface name has been changed from eth0 to enx<long hex number> in stretch, so you need to use this instead.

Here's an example from a pi I'm configuring at the minute:

Code: Select all

interface enxb827ebb5c09f
static ip_address=10.1.1.1
static routers=10.1.1.254
netmask=255.255.255.0
static domain_name_servers=10.1.1.254
Muchas gracias.

pcmanbob
Posts: 2218
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: [Solved] Raspbian Stretch: Setting a static IP

Tue Nov 21, 2017 7:35 pm

You forgot about the netmask...
Actually he did not ....

by specifying the IP address like this ( note /24 at end )

Code: Select all

 static ip_address=10.0.0.235/24 
you don't need to then include the

Code: Select all

 netmask=255.255.255.0 
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

Bosse_B
Posts: 631
Joined: Thu Jan 30, 2014 9:53 am

Re: [Solved] Raspbian Stretch: Setting a static IP

Tue Nov 21, 2017 9:04 pm

Migzy wrote:
Tue Nov 21, 2017 3:59 pm
Also the interface name has been changed from eth0 to enx<long hex number> in stretch, so you need to use this instead.
Well, you seem to have another Raspbian Stretch than I have...
Here is ifconfig taken a minute ago:

Code: Select all

~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.0.235  netmask 255.255.255.0  broadcast 10.0.0.255
        ether b8:27:eb:ba:c2:5b  txqueuelen 1000  (Ethernet)
        RX packets 2483439  bytes 661684060 (631.0 MiB)
        RX errors 0  dropped 15339  overruns 0  frame 0
        TX packets 667690  bytes 465754545 (444.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 1  (Local Loopback)
        RX packets 7  bytes 384 (384.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7  bytes 384 (384.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 10.8.1.1  netmask 255.255.255.0  destination 10.8.1.1
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 100  (UNSPEC)
        RX packets 5501  bytes 1843297 (1.7 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5625  bytes 2847320 (2.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tun1: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 10.8.0.1  netmask 255.255.255.0  destination 10.8.0.1
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 100  (UNSPEC)
        RX packets 267112  bytes 137694655 (131.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 305816  bytes 299701007 (285.8 MiB)
        TX errors 0  dropped 449 overruns 0  carrier 0  collisions 0

wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether b8:27:eb:ef:97:0e  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Some things have changed which forced me to modify a boot script I run in order to report the RPi network address by email on each boot so I can find it. The inet and ether lines were formatted differently before Stretch so my script did not extract a proper address now. Had to edit the script to grab the lines starting with inet and ether instead.
But the interface name is still eth0 for me.
Bo Berglund
Sweden

pcmanbob
Posts: 2218
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: [Solved] Raspbian Stretch: Setting a static IP

Tue Nov 21, 2017 9:24 pm

Also the interface name has been changed from eth0 to enx<long hex number> in stretch, so you need to use this instead.
So the first release of raspbian stretch dated 2017-08-17 did used the enx<long hex number> to identify network ports,
But due to the confusion it caused and the fact it broke many scripts and how to's it was changed on the
second release of raspbian stretch dated 2017-09-08 back to the eth0 format.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

SurferTim
Posts: 1113
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: [Solved] Raspbian Stretch: Setting a static IP

Tue Nov 21, 2017 9:27 pm

The default interface names are different depending on the Stretch version you are using.
2017-08-16 uses predictable interface names like enx<mac address>
2017-09-07 uses standard interface names like eth0.

You can change the interface names if you like.

You should start another thread. This one is marked [Solved].

Return to “Troubleshooting”

Who is online

Users browsing this forum: Abe_Stew, GordonTGopher and 30 guests