Raspbian boots to a DHCP address first, then the fixed IP

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
I have a Pi using only the /boot partition on the SD card, with
/boot/cmdline.txt set to mount / from a partition on the external USB
drive, & I edited /etc/network/interfaces to use a fixed IP address on
the LAN.  But I've noticed that when I reboot it, it comes up with a
DHCP address first, then changes to the fixed IP.  What have I done
wrong, & how do I fix it?

Thanks.

Re: Raspbian boots to a DHCP address first, then the fixed IP
On 01/07/15 13:11, Adam Funk wrote:
Quoted text here. Click to load it
Remove or disable the dhcpdc package. It's a recent addition to the  
Rasbian images and tends to ignore the interfaces file and do its own thing.

It's fine for the average user who uses the desktop and sets up  
networking via the GUI, but just gets in the way when you want to do  
things yourself.

Re: Raspbian boots to a DHCP address first, then the fixed IP
On Wed, 01 Jul 2015 17:04:43 +0100

Quoted text here. Click to load it

Most home routers make it easy to reserve an IP address for any device
(by MAC address), so running a DHCP client by default shouldn't be a
nuisance unless you have a really good reason not to.


Re: Raspbian boots to a DHCP address first, then the fixed IP
On 2015-07-01, Rob Morley wrote:

Quoted text here. Click to load it

I don't think my router does, but that's an interesting point.


--  
There's nothing in Scripture that forbids letting our lawn
go wild.                              --- Garrison Keillor

Re: Raspbian boots to a DHCP address first, then the fixed IP
On 2015-07-01, Dom wrote:

Quoted text here. Click to load it

Thanks.  Is removing it likely to break anything?  

I've never connected a keyboard, mouse, or monitor to this Pi --- I
just used dd to put the image on the SD card, put that in the Pi,
started it up, found it on the LAN (with a DHCP address) and used ssh
to do the rest (obviously changing the default password first...).
And I'd like to not have to dig out a spare keyboard (& so on) later
if it doesn't connect according to the static LAN IP for some reason.


--  
I used to be better at logic problems, before I just dumped
them all into TeX and let Knuth pick out the survivors.
We've slightly trimmed the long signature. Click to see the full one.
Re: Raspbian boots to a DHCP address first, then the fixed IP
Quoted text here. Click to load it

That will only be necessary when you make mistakes when configuring
it via /etc/network/interfaces.  Forgetting "auto eth0", typo in
address, etc.

Mistakes in setting a gateway and DNS resolver is another one.  But that
can usually be corrected without connecting monitor and keyboard.

Re: Raspbian boots to a DHCP address first, then the fixed IP
On 2015-07-01, Rob wrote:

Quoted text here. Click to load it


I just remembered that if I'm at home, I can correct the contents of
files by mounting the SD card (which is just /boot now) & the USB
drive into my laptop.  So I just have to avoid the temptation to
fiddle with certain things from outside the house.


--  
We do not debug. Our software does not coddle the weak. Bugs  
are good for building character in the user.
We've slightly trimmed the long signature. Click to see the full one.
Re: Raspbian boots to a DHCP address first, then the fixed IP
Quoted text here. Click to load it

Yes, that is another method.  A week or two ago I had a Pi for which
I had forgotten the login password, and I fixed it that way too.

Re: Raspbian boots to a DHCP address first, then the fixed IP
On Wed, 01 Jul 2015 21:45:00 +0100, Adam Funk wrote:

Quoted text here. Click to load it
I don't think you need to do that.  
My copy of the file /etc/network/interfaces looks like this:

auto lo

iface lo inet loopback
iface eth0 inet static
address 192.168.7.101
netmask 255.255.255.0
gateway 192.168.7.1

I set this file up manually so I can ssh in via the static IP  
192.168.7.101 and it lets my RPi access the internet via my router, which  
is on 192.168.7.1    

I run a DNS server on my main system which names both the RPi and the  
router so I can refer to the RPi as 'rpi' and the router as 'hellsgate'  
from anywhere on my LAN. There's also a file /etc/network/interfaces.dhcp  
that looks like this:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
iface default inet dhcp


I don't remember where the second file came from, but it was probably set  
up automatically last time I did a clean install as part of increasing  
the SD card size. If thats what happened I'd have renamed the newly set  
up /etc/network/interfaces file to /etc/network/interfaces.dhcp to  
preserve it before dropping my copy of interfaces into /etc/network and  
rebooting the RPi to make it come up with a known static IP.

I do not have a keyboard and monitor on my RPi because I only use it via  
an SSH login.



--  
martin@   | Martin Gregorie
gregorie. | Essex, UK
We've slightly trimmed the long signature. Click to see the full one.
Re: Raspbian boots to a DHCP address first, then the fixed IP
On 2015-07-01, Martin Gregorie wrote:

Quoted text here. Click to load it

Aha, I think the problem might be that I left too much in when editing
the file; I have these lines:

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
address ....
....

as well as some auto wlan0, allow-hotplug wlan0 stuff, & same again
for wlan1, which I should delete.  I guess those come in the default
configuration for people using the USB wifi dongles instead of a
cable.


--  
Most Americans are too civilized to hang skulls from baskets, having
been headhunters, of course, only as recently as Vietnam.
We've slightly trimmed the long signature. Click to see the full one.
Re: Raspbian boots to a DHCP address first, then the fixed IP
On 02/07/15 10:32, Adam Funk wrote:
Quoted text here. Click to load it
My rather aged debian server has this

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
  address 192.168.1.101
  netmask 255.255.255.0
  gateway 192.168.1.1
  broadcast 192.168.1.255
  network 192.168.1.0

doesn't have a gui at all



--  
New Socialism consists essentially in being seen to have your heart in  
the right place whilst your head is in the clouds and your hand is in  
We've slightly trimmed the long signature. Click to see the full one.
Re: Raspbian boots to a DHCP address first, then the fixed IP
On 02/07/15 10:32, Adam Funk wrote:
Quoted text here. Click to load it

I wouldn't worry too much about those wlan entries. You can get rid of  
them if you like, but they won't do anything unless you plug in a  
wireless dongle.

I don't know why the Foundation put in both auto eth0 and allow-hotplug  
eth0, it should really just be one or the other. I use auto where the  
interface is built-in, like on the Pi B models, and allow-hotplug where  
it is a removable device like a laptop card or USB adapter.


Re: Raspbian boots to a DHCP address first, then the fixed IP
On 02/07/15 11:20, Dom wrote:
Quoted text here. Click to load it
isn't the auto bit saying 'bring this up on boot'?

http://unix.stackexchange.com/questions/128439/good-detailed-explanation-of-etc-network-interfaces-syntax


Well, let?s separate it into pieces, to make it easier to understand  
/etc/network/interfaces:

"auto interface ? Start the interface(s) at boot. That?s why the lo  
interface uses this kind of linking configuration."

"allow-hotplug interface ? Start the interface when a "hotplug" event is  
detected. In the real world, this is used in the same situations as auto  
but the difference is that it will wait for an event like "being  
detected by udev hotplug api" or "cable linked"."


--  
New Socialism consists essentially in being seen to have your heart in  
the right place whilst your head is in the clouds and your hand is in  
We've slightly trimmed the long signature. Click to see the full one.
Re: Raspbian boots to a DHCP address first, then the fixed IP
On 01/07/15 21:45, Adam Funk wrote:
Quoted text here. Click to load it

Actually, yes, depending on how you remove it :(

Removing it will also remove a package called "raspberrypi-net-mods",  
which annoyingly claims that file as one of it's configuration files. If  
you use the "purge" option of apt-get, it will delete your  
/etc/network/interfaces file!

So, either don't use the purge option, or take a copy of your interfaces  
file and put it back after removing that package and before rebooting.


Re: Raspbian boots to a DHCP address first, then the fixed IP
On 2015-07-02, Dom wrote:

Quoted text here. Click to load it


Aha, I figured out how to disable it without removing the package:
edit /etc/dhcpcd.conf (that is a difficult filename to type
correctly!) to add these two lines:

nodhcp
nodhcp6

Thanks to everyone for the pointers.


--  
Unix is a user-friendly operating system. It's just very choosy about
its friends.

Re: Raspbian boots to a DHCP address first, then the fixed IP
On 2015-07-02, Adam Funk wrote:

Quoted text here. Click to load it


Oops, it turns out that doing that hoses the resolver.  I could ssh
into the pi but it couldn't contact anything else.  I also needed to
add a name_servers="..." line to /etc/resolvconf.conf and run
'resolvconv -u'.

Re: Raspbian boots to a DHCP address first, then the fixed IP
Quoted text here. Click to load it

You can put the nameservers in /etc/network/interfaces as well.

Re: Raspbian boots to a DHCP address first, then the fixed IP
On 2015-07-02, Rob wrote:

Quoted text here. Click to load it

I saw some stuff on the WWW to that effect, but I wasn't sure it would
work on Raspbian, & I've already made a couple of mistakes by trying
stuff that works on Ubuntu (e.g., /usr/bin/sensible-editor) without
double-checking first!


--  
svn ci -m 'come back make, all is forgiven!' build.xml

Re: Raspbian boots to a DHCP address first, then the fixed IP
On 02/07/15 20:56, Adam Funk wrote:
Quoted text here. Click to load it

The dns-nameservers option does work on Raspbian.

Site Timeline