poldim
Posts: 6
Joined: Mon Jul 14, 2014 10:45 pm

Why would it not keep a static IP?

Sun May 22, 2016 7:15 pm

I recently switched from a Linksys router running Tomato firmware to a Ubiquiti Edge Router running EdgeOS. Prior to the change, my RPi had no issues keeping it's static IP which is outside the DHCP range of the router. After the switch, I booted up my RPi to find that it's got a DHCP address from the router on 192.168.1.229 even though none of the RPi settings have changed.

What would make the RPi not follow it's interfaces settings and use DHCP instead of Static?
None of the other devices on the network have similar behaviour.

Code: Select all

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

#iface eth0 inet manual

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
iface eth0 inet static
address 192.168.1.65
netmask 255.255.255.0
gateway 192.168.1.1
broadcast 192.168.1.255

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Why would it not keep a static IP?

Sun May 22, 2016 7:39 pm

Greetings.

You could read those lines from the head of the /etc/network/interfaces:

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'


/etc/network/interfaces should have: iface eth0 inet manual

Add these to /etc/dhcpcd.conf:
interface eth0
static ip_address=192.168.aaa.bbb



It's a Pi specific thing, different from Debian.

This is a piece of information which already be copied a lot of times on this forum. So you really should google.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Why would it not keep a static IP?

Mon May 23, 2016 3:33 am

... or has been said here many times, you could leave your PI alone (let it run dhcp, that is the correct setup) and get it a reserved "dynamic" address from the router; in other words, by mach address, you assign the same 'reserved' address to that mach address "dynamically". The end result is what you want-- a static address for the PI, served up dynamically from the router's reserved address pool.
marcus
:ugeek:

poldim
Posts: 6
Joined: Mon Jul 14, 2014 10:45 pm

Re: Why would it not keep a static IP?

Mon May 23, 2016 4:56 am

allfox wrote:Greetings.

You could read those lines from the head of the /etc/network/interfaces:

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'


/etc/network/interfaces should have: iface eth0 inet manual

Add these to /etc/dhcpcd.conf:
interface eth0
static ip_address=192.168.aaa.bbb



It's a Pi specific thing, different from Debian.

This is a piece of information which already be copied a lot of times on this forum. So you really should google.
Thanks, this solved it.

As an aside, I never run to the forums as the first choice. I search both through Google and the search here, usually finding a posted solution online saves a lot of time and helps me learn. Admin's should look into changing how the crawlers catalog the forum as it has room for improvement.

Thanks again.

poldim
Posts: 6
Joined: Mon Jul 14, 2014 10:45 pm

Re: Why would it not keep a static IP?

Mon May 23, 2016 4:59 am

MarkHaysHarris777 wrote:... or has been said here many times, you could leave your PI alone (let it run dhcp, that is the correct setup) and get it a reserved "dynamic" address from the router; in other words, by mach address, you assign the same 'reserved' address to that mach address "dynamically". The end result is what you want-- a static address for the PI, served up dynamically from the router's reserved address pool.
I'm not sure how this is better than a static IP. Most devices that don't move run static. I guess having a static map on your network would save you a couple steps if you ever disconnect your Pi and move it to another network, but very unlikely in my situation. Do you have a use case where this is better for a permanent resting place?

User avatar
DougieLawson
Posts: 36098
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Why would it not keep a static IP?

Mon May 23, 2016 6:56 am

poldim wrote:
MarkHaysHarris777 wrote:... or has been said here many times, you could leave your PI alone (let it run dhcp, that is the correct setup) and get it a reserved "dynamic" address from the router; in other words, by mach address, you assign the same 'reserved' address to that mach address "dynamically". The end result is what you want-- a static address for the PI, served up dynamically from the router's reserved address pool.
I'm not sure how this is better than a static IP. Most devices that don't move run static. I guess having a static map on your network would save you a couple steps if you ever disconnect your Pi and move it to another network, but very unlikely in my situation. Do you have a use case where this is better for a permanent resting place?
You're right, Marcus is wrong. If the machine is a client give it a DHCP address (because nothing needs to connect to it), if the machine is a server give it a static address and a DNS entry (so it's easy to find).
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Why would it not keep a static IP?

Mon May 23, 2016 6:22 pm

DougieLawson wrote:
poldim wrote:
MarkHaysHarris777 wrote:... or has been said here many times, you could leave your PI alone (let it run dhcp, that is the correct setup) and get it a reserved "dynamic" address from the router; in other words, by mach address, you assign the same 'reserved' address to that mach address "dynamically". The end result is what you want-- a static address for the PI, served up dynamically from the router's reserved address pool.
I'm not sure how this is better than a static IP. Most devices that don't move run static. I guess having a static map on your network would save you a couple steps if you ever disconnect your Pi and move it to another network, but very unlikely in my situation. Do you have a use case where this is better for a permanent resting place?
You're right, Marcus is wrong. If the machine is a client give it a DHCP address (because nothing needs to connect to it), if the machine is a server give it a static address and a DNS entry (so it's easy to find).
We're both right; and for the record, I'm seldom wrong... and in this case I'm absolutely correct.

The reason for NOT setting static addresses in clients is so that they can be moved, but more importantly so that NO ONE has to maintain them ! (they just work where-ever they are located). In my network all of my users need to be able to ssh to all of my clients (because all of my clients are also servers!) Consequently they all really need to have consistent addresses and they all need to be on the name server (DNS bind). I pick my machines up (literally) and move them all over the place... one day I'll be at the university, one day at the public library, one day I'll spend the whole day at the coffee shop... and when I'm moving around I want my machines to 'just work' there too... and the only way to do that is to leave every machine configured as dhcp "dynamic" only (no static addresses). When I return to base the machines still work (with their consistent named 'static' like address) because my router assigns them the same dynamic address from the reserved address pool by mach address.

There is ONLY one reason to ever assign a static address... and that's the case I'm writing up in the robotic subforum... you want to connect your notebook computer to your PI over a single Ethernet cable and so you create a two address subnet (static) from the PI to the notebook.

I have only set ONE static address since 1994... last week I setup a single cable route from PI to notebook (two address subnet) and I used static addresses. All of the other addresses I've set in the past twenty-five years have been dynamic only.
marcus
:ugeek:

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Why would it not keep a static IP?

Mon May 23, 2016 7:34 pm

I run dnsmasq on a Pi to be the DHCP server. So other machine in the network could stay with a dynamic address which won't change. It doesn't need me to assign that address, dnsmasq uses a hash function to generate it from MAC. MAC seldom change.

Well, theoretically everyone in the private network get a stable address with no human interaction.

But recently, there was an upgrade to dnsmasq, from 2.75 to 2.76. After I followed that upgrade, the DHCP result changed. I don't know if it's the upgrade or the recompilation cause the trick.


About using a single wire to connect Pi to PC, I personally used static IP either, however I read that there is a "link local IP address", maybe it could be used, I don't know how yet.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Why would it not keep a static IP?

Mon May 23, 2016 8:01 pm

allfox wrote:I run dnsmasq on a Pi to be the DHCP server. So other machine in the network could stay with a dynamic address which won't change. It doesn't need me to assign that address, dnsmasq uses a hash function to generate it from MAC. MAC seldom change.
... beauty!
allfox wrote: Well, theoretically everyone in the private network get a stable address with no human interaction.
I love it...
allfox wrote: But recently, there was an upgrade to dnsmasq, from 2.75 to 2.76. After I followed that upgrade, the DHCP result changed.
... rats.
allfox wrote: I don't know if it's the upgrade or the recompilation cause the trick.
... need to snoop that out!
allfox wrote: About using a single wire to connect Pi to PC, I personally used static IP either, however I read that there is a "link local IP address", maybe it could be used, I don't know how yet.
Yes, I am new to that too... its the 169.xx.xx.xx address you may have been seeing. Supposedly, if you leave that alone (and theoretically all your machines use it) then all you have to do to get the single wire to work is connect them and link to the local machine! voila! I have not been able to get this to work with my PI yet.... :cry:
marcus
:ugeek:

JimmyN
Posts: 1109
Joined: Wed Mar 18, 2015 7:05 pm
Location: Virginia, USA

Re: Why would it not keep a static IP?

Mon May 23, 2016 8:17 pm

MarkHaysHarris777 wrote: There is ONLY one reason to ever assign a static address... and that's the case I'm writing up in the robotic subforum... you want to connect your notebook computer to your PI over a single Ethernet cable and so you create a two address subnet (static) from the PI to the notebook.
Here's an example of another reason. For my RPi #4 I always want the IP to be 192.168.0.4. But I may plug it into ethernet if I have it on my desk, or I may plug in a wireless dongle if it's not at my desk and I don't have ethernet available. A router won't let you reserve the same IP for two different MAC addresses, it will tell you the IP is already in use when you try to do a second reservation for the same IP. Therefore I set the same static IP for wired and wireless on RPi #4, as it can't be done in the router.

So you have the ONLY reason that you've justified for doing it, but there are others.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Why would it not keep a static IP?

Mon May 23, 2016 8:22 pm

JimmyN wrote:A router won't let you reserve the same IP for two different MAC addresses, it will tell you the IP is already in use when you try to do a second reservation for the same IP. Therefore I set the same static IP for wired and wireless on RPi #4, as it can't be done in the router.

So you have the ONLY reason that you've justified for doing it, but there are others.
Except, that technically, you shouldn't be doing that...

... there is a reason your router won't allow you to set the same IP address for two mach addresses! From a networking standpoing, I want to know how the unit is connecting, and I know that (just by looking) because of the IP address range it falls into... whether it is on the wifi network or on the wired network. In your setup you don't know that... and worse... if you want to close your wifi network and leave the wired network alone, you have no way of knowing which of those machines you're affecting!
marcus
:ugeek:

poldim
Posts: 6
Joined: Mon Jul 14, 2014 10:45 pm

Re: Why would it not keep a static IP?

Tue May 24, 2016 3:14 pm

MarkHaysHarris777 wrote:
JimmyN wrote:A router won't let you reserve the same IP for two different MAC addresses, it will tell you the IP is already in use when you try to do a second reservation for the same IP. Therefore I set the same static IP for wired and wireless on RPi #4, as it can't be done in the router.

So you have the ONLY reason that you've justified for doing it, but there are others.
Except, that technically, you shouldn't be doing that...

... there is a reason your router won't allow you to set the same IP address for two mach addresses! From a networking standpoing, I want to know how the unit is connecting, and I know that (just by looking) because of the IP address range it falls into... whether it is on the wifi network or on the wired network. In your setup you don't know that... and worse... if you want to close your wifi network and leave the wired network alone, you have no way of knowing which of those machines you're affecting!
You're assuming that most people have a separate VLAN for wired vs unwired devices. Probably 99% of people who use wifi or own a router have no idea what a VLAN is, nor do they care. I would also probably bet that most devices that have static IPs, never leave or disconnect from their network. While it may work for you in your case, I don't think it applies to the general masses. But like you said before, you're seldom wrong. ;)

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Why would it not keep a static IP?

Tue May 24, 2016 5:58 pm

poldim wrote:
MarkHaysHarris777 wrote:
JimmyN wrote:A router won't let you reserve the same IP for two different MAC addresses, it will tell you the IP is already in use when you try to do a second reservation for the same IP. Therefore I set the same static IP for wired and wireless on RPi #4, as it can't be done in the router.

So you have the ONLY reason that you've justified for doing it, but there are others.
Except, that technically, you shouldn't be doing that...

... there is a reason your router won't allow you to set the same IP address for two mach addresses! From a networking standpoing, I want to know how the unit is connecting, and I know that (just by looking) because of the IP address range it falls into... whether it is on the wifi network or on the wired network. In your setup you don't know that... and worse... if you want to close your wifi network and leave the wired network alone, you have no way of knowing which of those machines you're affecting!
You're assuming that most people have a separate VLAN for wired vs unwired devices. Probably 99% of people who use wifi or own a router have no idea what a VLAN is, nor do they care. I would also probably bet that most devices that have static IPs, never leave or disconnect from their network. While it may work for you in your case, I don't think it applies to the general masses. But like you said before, you're seldom wrong. ;)
Yes. And the other thing is, some of my opinion is purist. I'm less inclined to favor a solution that is 'forced' or goes very far outside the design criteria for the system (call it a personality flaw). A person can force a system to do things it wasn't designed to do, or wasn't specifically designed to handle, either because the don't understand the design constraints, or don't care... they just want it to work so they bang on it until they get it to comply (whether its right or not doesn't phase them one way or another).

The design is that there will be a one-to-one relationship between IP address and mach address. Forcing the system outside the router to break the design of one-to-one (while it functions) defeats the purpose for which the one-to-one was established. Learning the correct method is better IMHO. ... and, this point its a matter of opinion, not a matter of being correct. (and I'm correct about that too)
marcus
:ugeek:

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Why would it not keep a static IP?

Tue May 24, 2016 6:13 pm

I just have to remark that not all routers are capable of allocating IPs based on MACs.
Mine for example can not do it (Siemens Speedstream).

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Why would it not keep a static IP?

Tue May 24, 2016 7:13 pm

shuckle wrote:I just have to remark that not all routers are capable of allocating IPs based on MACs.
Mine for example can not do it (Siemens Speedstream).
Yes. I used to have one of those routers too. That's when I bought a high-speed switch and configured it and my Pentium II gnu+linux box (and the switch) to be my router. (used that for many years, acutally)

Then, I bought a commercial router that supports port forwarding, port triggering, full access controls (also by mach address) as well reserved IP addresses. Many of them are now under $100 and most of them are now under $200.

I realize that some folks still use hubs, have no nameserver, and all three of their machines are static; but, that does not mean they can't learn the correct approach.
marcus
:ugeek:

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Why would it not keep a static IP?

Tue May 24, 2016 8:26 pm

A little follow up about connecting Pi with PC with a single Ethernet wire.

No DHCP, no static IP. It would work OOTB as "raspberrypi.local".
So we could ping raspberrypi.local, or putty raspberrypi.local.

This is due to the multicast DNS service, it would resolve the name to the link local address.

I tried it on Windows 10 pro, and a Pi 2 is loaded with a fresh copy of 2016-05-10-raspbian-jessie-lite.

And, thanks marcus, your post encouraged me to find these out.

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: Why would it not keep a static IP?

Tue May 24, 2016 9:40 pm

allfox wrote:A little follow up about connecting Pi with PC with a single Ethernet wire.

No DHCP, no static IP. It would work OOTB as "raspberrypi.local".
So we could ping raspberrypi.local, or putty raspberrypi.local.

This is due to the multicast DNS service, it would resolve the name to the link local address.

I tried it on Windows 10 pro, and a Pi 2 is loaded with a fresh copy of 2016-05-10-raspbian-jessie-lite.

And, thanks marcus, your post encouraged me to find these out.
Most excellent, dude !
marcus
:ugeek:

ajk
Posts: 9
Joined: Fri May 06, 2016 11:35 pm

Re: Why would it not keep a static IP?

Wed May 25, 2016 9:52 pm

allfox wrote:A little follow up about connecting Pi with PC with a single Ethernet wire.

No DHCP, no static IP. It would work OOTB as "raspberrypi.local".
So we could ping raspberrypi.local, or putty raspberrypi.local.

This is due to the multicast DNS service, it would resolve the name to the link local address.

I tried it on Windows 10 pro, and a Pi 2 is loaded with a fresh copy of 2016-05-10-raspbian-jessie-lite.

And, thanks marcus, your post encouraged me to find these out.
Am I correct in assuming you have Apple Bonjour installed ( via iTunes or the like) on your windows 10 system. To the best of my knowledge windows (all versions) not support mDNS out of the box.

User avatar
allfox
Posts: 452
Joined: Sat Jun 22, 2013 1:36 pm
Location: Guang Dong, China

Re: Why would it not keep a static IP?

Thu May 26, 2016 6:34 am

ajk wrote:Am I correct in assuming you have Apple Bonjour installed ( via iTunes or the like) on your windows 10 system. To the best of my knowledge windows (all versions) not support mDNS out of the box.
Yes, I have iTunes here, didn't know it helped. Thanks for making that clear.

I think the problem with local link address is that how to find the other end's address. I'll find further.

This sounds bad: "To connect to Pi, install iTunes."

ajk
Posts: 9
Joined: Fri May 06, 2016 11:35 pm

Re: Why would it not keep a static IP?

Thu May 26, 2016 12:22 pm

allfox wrote:
This sounds bad: "To connect to Pi, install iTunes."
It's not quite as bad as it sounds. The open source Linux version of Bounjour (aka zero config) is called avahi. Nobody has bothered to port avahi to windows since Bonjour is easily obtained and free to install use. The easiest way to get Bounjour onto a windows system is to install Apple's iTunes or its Bonjour Print Services. If somebody does not want iTunes or Bonjour Print Services on there windows system they can just install one of them followed by an uninstall; by default Bonjour will be left behind.

DirkS
Posts: 9936
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Why would it not keep a static IP?

Thu May 26, 2016 8:34 pm

ajk wrote:The easiest way to get Bounjour onto a windows system is to install Apple's iTunes or its Bonjour Print Services. If somebody does not want iTunes or Bonjour Print Services on there windows system they can just install one of them followed by an uninstall; by default Bonjour will be left behind.
Or download iTunes installer, extract the bonjour installer (msi file) from that file and install it.

User avatar
DougieLawson
Posts: 36098
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Why would it not keep a static IP?

Thu May 26, 2016 9:37 pm

You don't need that. All supported versions of Windows have mDNS (aka avahi, aka Bonjour) support built in.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

poldim
Posts: 6
Joined: Mon Jul 14, 2014 10:45 pm

Re: Why would it not keep a static IP?

Sat May 28, 2016 11:00 pm

Any idea why the Pi able to resolve DNS inquiries?

I can SSH in and I can force in a default gateway route by sudo route add default gw 192.168.1.1. At this point I'm able to ping http://www.google.com. What can I do to keep the gateway in the route table?

Route output, upon reboot:

Code: Select all

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     202    0        0 eth0
Route output, after sudo route add default gw 192.168.1.1:

Code: Select all

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     *               255.255.255.0   U     202    0        0 eth0

mfa298
Posts: 1387
Joined: Tue Apr 22, 2014 11:18 am

Re: Why would it not keep a static IP?

Sun May 29, 2016 1:39 am

MarkHaysHarris777 wrote:We're both right; and for the record, I'm seldom wrong... and in this case I'm absolutely correct.
I'm going to correct you on one thing.
MarkHaysHarris777 wrote:... in other words, by mach address, you assign the same 'reserved' address to that mach address "dynamically".
There's no such thing as mach address, you mean MAC (media access control) address. It's also known as an Ethernet Address or Physical Address but not mach address.

As for the address on the device itself or static ip via dhcp both have their merits (even for servers). There are a few cases where you should have a static ip configured (dhcp servers, routers, firewalls) but after that both options have advantages: configured static (servers keep running if dhcp is broken), static via dhcp (easier to roll out network changes to systems).


allfox wrote: But recently, there was an upgrade to dnsmasq, from 2.75 to 2.76. After I followed that upgrade, the DHCP result changed. I don't know if it's the upgrade or the recompilation cause the trick.
From memory that might be broken behaviour based on the rfc specs. I recall that the dhcp server is supposed to store lease information to stable storage and should then re-assign the same address based on what it did previously. That is how the isc dhcp server works which is the reference implementation.
allfox wrote: About using a single wire to connect Pi to PC, I personally used static IP either, however I read that there is a "link local IP address", maybe it could be used, I don't know how yet.
There is the 169.254 network used as a fall back, however it can't be used to get internet access as it wont give you a default route (how would you know what device is the router). If this setup is supported by the pi it would provide a means to get into the os and configure it to get on the main network.

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Why would it not keep a static IP?

Sun May 29, 2016 2:29 am

allfox wrote:No DHCP, no static IP. It would work OOTB as "raspberrypi.local".
So we could ping raspberrypi.local, or putty raspberrypi.local.
But if you let the actual ip float about, you will have to change the default configuration of ssh to not do strict ip checking, at least on most distributions, assuming you don't want it to complain every time you try to log in.

Return to “Troubleshooting”