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

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.

Reply to
Adam Funk
Loading thread data ...

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.

Reply to
Dom

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.

Reply to
Rob Morley

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. 
                                               -- plorkwort
Reply to
Adam Funk

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
Reply to
Adam Funk

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.

Reply to
Rob

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 
org       |
Reply to
Martin Gregorie

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.

Reply to
Dom

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. 
                              --- Klingon Programmer's Guide
Reply to
Adam Funk

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. 
                                                  --- Kinky Friedman
Reply to
Adam Funk

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  
someone else's pocket.
Reply to
The Natural Philosopher

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.

Reply to
Dom

isn't the auto bit saying 'bring this up on boot'?

formatting link

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  
someone else's pocket.
Reply to
The Natural Philosopher

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.

Reply to
Rob

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.
Reply to
Adam Funk

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'.

Reply to
Adam Funk

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

Reply to
Rob

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
Reply to
Adam Funk

The dns-nameservers option does work on Raspbian.

Reply to
Dom

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.