0

I'm trying to set a static IP for my Pi Zero's USB ethernet port using /etc/dhcpcd.conf. I'm using Raspbian Stretch.

Here is my /etc/dhcpcd.conf file:

pi@raspberrypi:~ $ 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.2.09

#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

Notice that I set static ip_address=192.168.2.09 for eth0.

However, after rebooting my Pi, when I check ifconfig I see the following:

pi@raspberrypi:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.161  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::9f9b:41c1:8aa3:4427  prefixlen 64  scopeid 0x20<link>
        ether 02:00:00:00:00:09  txqueuelen 1000  (Ethernet)
        RX packets 179  bytes 14789 (14.4 KiB)
        RX errors 1  dropped 0  overruns 1  frame 2
        TX packets 176  bytes 22776 (22.2 KiB)
        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
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        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

The IP address listed for eth0 is 192.168.2.161 which I believe was set automatically by my router.

sudo systemctl status dhcpcd yields the following output:

pi@raspberrypi:~ $ sudo systemctl status dhcpcd
● dhcpcd.service - dhcpcd on all interfaces
   Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: e
   Active: active (running) since Tue 2018-11-20 21:12:10 UTC; 20min ago
  Process: 209 ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -b (code=exited, status=0/SU
 Main PID: 232 (dhcpcd)
   CGroup: /system.slice/dhcpcd.service
           └─232 /sbin/dhcpcd -q -b

Nov 20 21:12:13 raspberrypi dhcpcd[232]: eth0: IAID 00:00:00:09
Nov 20 21:12:13 raspberrypi dhcpcd[232]: eth0: adding address fe80::9f9b:41c1:8a
Nov 20 21:12:14 raspberrypi dhcpcd[232]: eth0: soliciting a DHCP lease
Nov 20 21:12:14 raspberrypi dhcpcd[232]: eth0: soliciting an IPv6 router
Nov 20 21:12:14 raspberrypi dhcpcd[232]: eth0: offered 192.168.2.161 from 192.16
Nov 20 21:12:15 raspberrypi dhcpcd[232]: eth0: probing address 192.168.2.161/24
Nov 20 21:12:20 raspberrypi dhcpcd[232]: eth0: leased 192.168.2.161 for 259200 s
Nov 20 21:12:20 raspberrypi dhcpcd[232]: eth0: adding route to 192.168.2.0/24
Nov 20 21:12:20 raspberrypi dhcpcd[232]: eth0: adding default route via 192.168.
Nov 20 21:12:27 raspberrypi dhcpcd[232]: eth0: no IPv6 Routers available
lines 1-18/18 (END)

Why isn't the static IP change taking effect?

  • Which OS are you using? If it's Raspbian, you should be able to check what dhcpcd was up to like this: sudo systemctl status dhcpcd – RubberStamp Nov 20 '18 at 21:25
  • @RubberStamp I'm using Raspbian Stretch. I've edited the initial question to include the output of` sudo systemctl status dhcpcd – Matt Nov 20 '18 at 21:34
  • Perhaps the 09 should simply be 9 .... 192.168.2.9 rather than 192.168.2.09 – RubberStamp Nov 20 '18 at 22:18
  • @RubberStamp never had a problem with specifying 09 vs. 9 in the past – Matt Nov 20 '18 at 23:42
1

It didn't work because you specified an incomplete CIDR address - which was presumably ignored by dhcpcd.

See How to set up Static IP Address

NOTE unless you are trying to run a standalone network you should also specify static routers and static domain_name_servers to get internet access. This is normally handled by your router.

  • You may have been right but oddly enough the address randomly started working without adding anything to it. I am running this on a standalone network, hence no DNS/router specified. I was just troubleshooting it using my router for ease of access. – Matt Nov 20 '18 at 23:40
  • 1
    @Matt dhcpcd is a rather complex program. It tries to guess BUT you should specify the correct format (which supplies the mask). It is unclear what you did but you need to reboot (or at least restart dhcpcd) on any change. It is likely that it will behave differently if connected to a router - which it was in the log in your question. – Milliways Nov 20 '18 at 23:57
0

I restarted it again a couple hours later without changing anything and it worked. Still unsure why it started working randomly so if anyone has any insights on why this happened I will accept your answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.