Page 1 of 1
RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 3:33 pm
by DCDi
Hi,
I am running a RPI4 Buster lite 4.19.
I am trying to specify a static IP address on eth0. Secondary, I want the wlan0 to take priority over eth0 for an internet connection - In fact, I do not want to have the eth0 have internet connectivity at all. I can make neither work.
Issue 1
Static IP - I have modified /etc/dhcpcd.conf with a standard static IP configuration like: I am not specifying a gateway to prevent internet connectivity.
Code: Select all
interface eth0
static ip_address=192.168.0.4/24
Upon reboot - this works, but I am also still pulling an IP address from the DHCP on the eth0 interface. So hostname -I shows:
192.168.0.101 192.168.0.4.
The output of /etc/network/interfaces is: source-directory /etc/network/interfaces.d
/etc/network/interfaces.d is an empty directory.
I am not sure where else to look, I have googled around and tired various things to no avail. Any on how to stop pulling dhcp on an interface that already had a static address set?
issue 2
I am assuming the above will work to prevent eth0 to not access the internet because no gateway was specified. Prior on a different test pi I tried to get this to work by setting a route metric in /etc/dhcpcd.conf like:
Code: Select all
interface eth0
metric 300
interface wlan0
metric 200
That did not work as expected. I am trying to prevent loosing connectivity if eth0 goes down or gets unplugged. I do, however, want to access the network device connected to eth0. Any thoughts on this one?
Thanks in advance for any/all help.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 5:42 pm
by rwcooper
Hi, when I do hostname -I I see two ip addresses as well. One is for eth0 and the other is for wlan0. Are you using dhcp for wlan0?
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 5:54 pm
by DCDi
I see 3 IP address - two in the 192.168.0.0/24 network The 3rd address is from the wlan and is working as expected using hdcp.
I don't understand why it is pulling dhcp when I have a static IP configured to eth0.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 6:28 pm
by bls
Please post the output from the command
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 9:54 pm
by DCDi
What should I be looking for? This was a fresh card/pi setup this a.m.
Code: Select all
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether dc:a6:32:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet 192.168.0.101/24 brd 192.168.0.255 scope global dynamic noprefixroute eth0
valid_lft 424sec preferred_lft 424sec
inet 192.168.0.4/24 brd 192.168.0.255 scope global secondary noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::eb3b:36xx:xxxx:xxxx/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether dc:a6:32:xx:xx:xx brd ff:ff:ff:ff:ff:ff
inet 192.168.100.5/24 brd 192.168.100.255 scope global dynamic noprefixroute wlan0
valid_lft 259072sec preferred_lft 226672sec
inet6 fe80::18cb:4cxx:xxxx:xxxx/64 scope link
valid_lft forever preferred_lft forever
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 10:00 pm
by DCDi
I did try the last post in this thread - It sounded like what I was experiencing so I was hopeful....
viewtopic.php?t=246949
but upon reboot eth0 still grabbed a dhcp address.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 10:12 pm
by DCDi
I also added a static router and static domain_name_server to the /etc/dhcpcd.conf file think that would help. Upon reboot it still pulls 2 address has 2 IP addresses.
I also read that adding "denyinterfaces eth0" - can stop the dhcp client from running on it, but that did not work either.
I will solider on...
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 10:40 pm
by wh7qq
I get the same issue on my network and it is clearly a router issue. As long as DHCP is enabled, it pays no attention to the fact that a static IP has been set. Most commercial routers use an old Linux kernel (2.6.x where current kernel is 5.5.x or greater) and I do not know if that still works that way. It would be interesting to see if any of the readers of this forum are using PC or other based routing have the same issue. Also, I intend to raise the issue on snbforums.com and see if a solution exists.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 10:45 pm
by DCDi
wh7qq wrote: ↑Fri Jun 26, 2020 10:40 pm
I get the same issue on my network and it is clearly a router issue. As long as DHCP is enabled, it pays no attention to the fact that a static IP has been set. Most commercial routers use an old Linux kernel (2.6.x where current kernel is 5.5.x or greater) and I do not know if that still works that way. It would be interesting to see if any of the readers of this forum are using PC or other based routing have the same issue. Also, I intend to raise the issue on snbforums.com and see if a solution exists.
Not sure how this is a router issue. I mean, there must be a dhcp client/service sending out those requests. If there is a static IP set on the RPi t he dhcp client should stop asking no?
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 10:53 pm
by dickon
Correct. This is not a router issue.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 10:59 pm
by pidd
Not specifying a gateway won't stop stop the Pi from responding to the routers advertisement, on most PC's you don't specify a gateway, it just finds one and connects.
Your best bet is to try and firewall the eth0's MAC address at the router to stop it accessing the internet, if the router allows this. You could blacklist the MAC address altogether at the router but the I'm not sure of the validity of any static IP set at the Pi end, at the minimum it would have to be outside the DHCP range of the router otherwise an IP collision could occur but also the Pi eth0 would be operating without a gateway which I'm not sure would work, how is anything going to get routed to it?
I try and control everything from the router, the more rules you put in the Pi the more work you have to do if things change. I assign all static IPs from the router only.
General rule I use:- its a network, everything has got to operate as a network not individually and the router is the coordinator.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 11:03 pm
by DCDi
pidd wrote: ↑Fri Jun 26, 2020 10:59 pm
Not specifying a gateway won't stop stop the Pi from responding to the routers advertisement, on most PC's you don't specify a gateway, it just finds one and connects.
Your best bet is to try and firewall the eth0's MAC address at the router to stop it accessing the internet, if the router allows this. You could blacklist the MAC address altogether at the router but the I'm not sure of the validity of any static IP set at the Pi end, at the minimum it would have to be outside the DHCP range of the router otherwise an IP collision could occur but also the Pi eth0 would be operating without a gateway which I'm not sure would work, how is anything going to get routed to it?
I try and control everything from the router, the more rules you put in the Pi the more work you have to do if things change. I assign all static IPs from the router only.
General rule I use:- its a network, everything has got to operate as a network not individually and the router is the coordinator.
I get what your are saying.... in my use case I cannot do that. Even so - how would this stop any other Pi from picking up to addresses that are statically set? Many people setup static IP addresses and only have one. Right?
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 11:12 pm
by drgeoff
Post the full contents of your dhcpcd.conf file.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 11:28 pm
by DCDi
I only changed the lines at the bottom.
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
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu
# Most distributions have NTP support.
#option ntp_servers
# A ServerID is required by RFC2131.
require dhcp_server_identifier
# Generate SLAAC address using the Hardware Address of the interface
#slaac hwaddr
# OR generate Stable Private IPv6 Addresses based from the DUID
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
######################
interface eth0
static ip_address=192.168.0.4/24
######################
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Fri Jun 26, 2020 11:35 pm
by dickon
pidd wrote: ↑Fri Jun 26, 2020 10:59 pm
Not specifying a gateway won't stop stop the Pi from responding to the routers advertisement, on most PC's you don't specify a gateway, it just finds one and connects.
That's just wrong.
For IPv4, a client sends a DHCP request, and optionally accepts any response it gets with a positive acknowledgement that it has done so. It won't just listen to some broadcast by a router saying 'Hello! Here I am!'; it doesn't work that way, and there are no such broadcasts.
For IPv6 it does, but that appears to be out of scope for this question.
Something is sending a DHCP request on eth0, hence the second address on that interface. The IP stack will use the gateway configured -- no matter which interface that was configured on -- to send packets to. It's entirely possible, albeit not sensible, to send a DHCP request from one interface which specifies a default route that's only reachable from a second, and the kernel will use it.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Sat Jun 27, 2020 12:13 am
by pidd
dickon wrote: ↑Fri Jun 26, 2020 11:35 pm
pidd wrote: ↑Fri Jun 26, 2020 10:59 pm
Not specifying a gateway won't stop stop the Pi from responding to the routers advertisement, on most PC's you don't specify a gateway, it just finds one and connects.
That's just wrong.
i've been staring at wireshark too long

I have more than one DHCP gateway on my network which complicates things.
DCDi wrote: Even so - how would this stop any other Pi from picking up to addresses that are statically set? Many people setup static IP addresses and only have one. Right?
Because if you set all static IP's at the router then those IP addresses are reserved for the relevant MAC address, If you set them at the Pi and they are inside the DHCP range of the router then there is a risk the router will issue that same IP address to another device and you will have a mess.
That's why some people tend to set static IPs at the high end of the DHCP range, it is a wish that the address is never issued by the router. Setting a low IP number without reserving it in the router is high risk.
Generally it is safer if every port on the same device (eg eth0 and wlan0) has their own separate IP addresses otherwise how can routing work?
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Sat Jun 27, 2020 2:10 am
by bassamanator
DCDi wrote: ↑Fri Jun 26, 2020 3:33 pm
Is the static ip that you've assigned able to be assigned by the router?
My rpi is at 192.168.1.100. My router cannot assign this ip to another device because it's out of the range of allowable assignments.
Perhaps look into that.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Sat Jun 27, 2020 2:14 am
by DCDi
bassamanator wrote: ↑Sat Jun 27, 2020 2:10 am
DCDi wrote: ↑Fri Jun 26, 2020 3:33 pm
Is the static ip that you've assigned able to be assigned by the router?
My rpi is at 192.168.1.100. My router cannot assign this ip to another device because it's out of the range of allowable assignments.
Perhaps look into that.
Thanks for that - it is outside the dhcp scope. and consequently the only device attached.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Sat Jun 27, 2020 9:10 am
by epoch1970
DCDi wrote: ↑Fri Jun 26, 2020 10:12 pm
I also read that adding "denyinterfaces eth0" - can stop the dhcp client from running on it, but that did not work either.
You have more than one dhcp client running on the Pi then. Find what is configuring your network besides dhcpcd. Systemd-networkd, ifupdown, some Desktop applet, some random script anywhere, the kernel itself in cmdline.txt...
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Sat Jun 27, 2020 6:46 pm
by DCDi
So, after some time and hunting this down I think I have solved most of my problem. Whether this is optimal is far from certain.
His command helped me find out what was dhcp responses
Code: Select all
sudo grep dhclient /var/log/syslog
That showed the dhcp communication coming from NetworkManager
I then edited the /etc/NetworkManager/NetworkManager.conf and added the following:
Code: Select all
[keyfile]
unmanaged-devices=mac:dc:a6:32:xx:xx:xx
That is the mac address for eth0 on my pi. I think this tells NetworkManager to ignore this device allow dhcpcd.conf to take over.
That stopped it from pulling a dhcp address on eth0. I now only have 1 IP from eth0 and one IP from wlan0.
My only issue is that it still automatically added a route that took precedence. Is that because eth0 came up first? Once I unplugged the Ethernet cable the wlan0 route became default. Then the Ethernet cable could be unplugged without loosing connection to the pi.
I have a metric set to prefer wlan0, but I think that is just for traffic once the interface is up and the route established? Not necessary, but is there a way to set a static route for wlan0 that would be priority over anything else?
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Sat Jun 27, 2020 6:57 pm
by DCDi
epoch1970 wrote: ↑Sat Jun 27, 2020 9:10 am
DCDi wrote: ↑Fri Jun 26, 2020 10:12 pm
I also read that adding "denyinterfaces eth0" - can stop the dhcp client from running on it, but that did not work either.
You have more than one dhcp client running on the Pi then. Find what is configuring your network besides dhcpcd. Systemd-networkd, ifupdown, some Desktop applet, some random script anywhere, the kernel itself in cmdline.txt...
Thank you for this it was helpful to get me looking in other places.
Re: RPi 4 - static IP set on eth0 but Pi gets 2nd IP on eth0 via DHCP?
Posted: Sat Jun 27, 2020 7:55 pm
by epoch1970
DCDi wrote: ↑Sat Jun 27, 2020 6:46 pm
My only issue is that it still automatically added a route that took precedence. ... I have a metric set to prefer wlan0, but I think that is just for traffic once the interface is up and the route established? Not necessary, but is there a way to set a static route for wlan0 that would be priority over anything else?
Route priority is effective only on identical routes. This attribute is often used on Linux to help the system choose a certain default route.
Raspios (by way of dhcpcd) gives priority to routes via Ethernet over routes via WiFi. In the man page for dhcpcd you can find that it attaches a priority (“metric value”) of 200+interface number (ifindex) to Ethernet devices, and 300+ifindex to WiFi devices. Maximum priority is denoted by 0, which is also the default value for routes created without specifying the metric option.
Assuming all your routes are created by dhcpcd, the following in dhcpcd.conf would give priority to wlan0 over any other interface in the system when trying to reach the internet: