mquinteiro
Posts: 10
Joined: Thu Sep 24, 2015 12:31 pm

DHCP starts after reconnection in a static interface

Fri May 06, 2016 1:57 pm

Hi,

I have a static eth0 configuration, everything goes right until I unplug the ethernet connector and plug it again, after that dhcp starts over eth0 and my dhcp server gives a new IP to PI2, so I lose the static IP.

I'm using raspbian jessie. Here is my interfaces file (actually I have one pseudo interface and both have the same problem).

Code: Select all

[email protected]# cat /etc/network/interfaces

auto lo eth0 eth0:1
iface lo inet loopback


iface eth0 inet static
address 10.5.0.3
netmask 255.255.255.0

iface eth0:1 inet static
address 192.168.100.27
netmask 255.255.255.0
gateway 192.168.100.24

#allow-hotplug wlan0
#iface wlan0 inet manual
#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp
Help welcome.
Thanks!

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6091
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: DHCP starts after reconnection in a static interface

Fri May 06, 2016 4:20 pm

Could you most the output of 'sudo journalctl' after that happens?

Edit: Also, that's not the correct way to set the static IP on the jessie image, but I am curious to see what actually goes wrong when you do it that way.

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

Re: DHCP starts after reconnection in a static interface

Fri May 06, 2016 9:05 pm

ShiftPlusOne wrote: Edit: Also, that's not the correct way to set the static IP on the jessie image, but I am curious to see what actually goes wrong when you do it that way.
It's well documented that doing it that way (without disabling dhcpcd) means that each active interface gets two IP addresses, one done with the static stuff in the interfaces file, one done by dhcpcd if there's an active DHCP server on the subnet.

The interfaces file even tells you what to do to avoid that problem.
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.

ShiftPlusOne
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 6091
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy

Re: DHCP starts after reconnection in a static interface

Fri May 06, 2016 9:37 pm

The original init.d file has this check in it:

Code: Select all

        if grep -q "^[[:space:]]*iface[[:space:]]*.*[[:space:]]*inet[[:space:]]*dhcp" \
        $INTERFACES; then
                log_failure_msg "Not running $NAME because $INTERFACES"
                log_failure_msg "defines some interfaces that will use a" \
                        "DHCP client"
                exit 6
        fi
I thought that check existed in dhcpcd itself, but must have remembered wrong.

A similar check for the systemd unit (perhaps as a ExecStartPre=grep...) could be used to prevent dhcpcd from starting when the interfaces file uses static or dhcp for any of the interfaces. That would probably save people some trouble.

User avatar
rpdom
Posts: 15892
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: DHCP starts after reconnection in a static interface

Sat May 07, 2016 6:09 am

ShiftPlusOne wrote:The original init.d file has this check in it:

Code: Select all

        if grep -q "^[[:space:]]*iface[[:space:]]*.*[[:space:]]*inet[[:space:]]*dhcp" \
        $INTERFACES; then
                log_failure_msg "Not running $NAME because $INTERFACES"
                log_failure_msg "defines some interfaces that will use a" \
                        "DHCP client"
                exit 6
        fi
I thought that check existed in dhcpcd itself, but must have remembered wrong.

A similar check for the systemd unit (perhaps as a ExecStartPre=grep...) could be used to prevent dhcpcd from starting when the interfaces file uses static or dhcp for any of the interfaces. That would probably save people some trouble.
This sounds like a really good idea! :-)

mquinteiro
Posts: 10
Joined: Thu Sep 24, 2015 12:31 pm

Re: DHCP starts after reconnection in a static interface

Sat May 07, 2016 2:20 pm

DougieLawson wrote:
ShiftPlusOne wrote: It's well documented that doing it that way (without disabling dhcpcd) means that each active interface gets two IP addresses, one done with the static stuff in the interfaces file, one done by dhcpcd if there's an active DHCP server on the subnet.
I don't get two IP's for the interface, interfaces starts with just one static and correct IP.

I haven't hdcpcd.conf , my system is a migration from wheezy. I have remember this "detail" right now, perhaps this is the reason of my headache.

Thanks!

epoch1970
Posts: 4134
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: DHCP starts after reconnection in a static interface

Sat May 07, 2016 2:58 pm

I will show my age and the ravages it brings.
But I have to say dhcpcd (besides its ridiculous name) is an aggravation almost equal to systemd sticking its nose everywhere.
/etc/network/interfaces has worked perfectly well for ages. So why deprecate it?
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

mquinteiro
Posts: 10
Joined: Thu Sep 24, 2015 12:31 pm

Re: DHCP starts after reconnection in a static interface

Sat May 07, 2016 3:13 pm

epoch1970 wrote:I will show my age and the ravages it brings.
But I have to say dhcpcd (besides its ridiculous name) is an aggravation almost equal to systemd sticking its nose everywhere.
/etc/network/interfaces has worked perfectly well for ages. So why deprecate it?
I agree with everything and my age is an old secret too.

FM81
Posts: 518
Joined: Wed Apr 17, 2013 4:33 pm

Re: DHCP starts after reconnection in a static interface

Sat May 07, 2016 3:25 pm

epoch1970 wrote:... But I have to say dhcpcd (besides its ridiculous name) is an aggravation almost equal to systemd sticking its nose everywhere.
/etc/network/interfaces has worked perfectly well for ages. So why deprecate it?
Agreeing too ...

[IRONIC MODE]
It's a type of "Modern Times": If something works good, replace it with something new, which didn't work better, makes things more complicated or what ever ...
But everyone will like the NEW and will be happy with it, because it is NEW ...
[/IRONIC MODE]

Greetings, FM_81
A: What does the command 'cat /dev/urandom', can you tell me please?
B: Yeah, that's very simple: It feeds your cat with radioactive material!

mquinteiro
Posts: 10
Joined: Thu Sep 24, 2015 12:31 pm

Re: DHCP starts after reconnection in a static interface

Mon May 09, 2016 1:23 pm

Hi This is what I did.

I have modified /etc/wpa_supplicant/ifupdown.sh

And replaced

Code: Select all

# quit if we're called for the loopback
if [ "$IFACE" = lo ]; then
        exit 0
fi
with

Code: Select all

# quit if we're called for the loopback
if [ "$IFACE" = lo ]; then
        exit 0
fi

if [ "$IFACE" = eth0 ]; then
        exit 0
fi
Now it works ok, I suppose that I could analyze a little bit more and propose a better solution but I'm in a rush.

mquinteiro
Posts: 10
Joined: Thu Sep 24, 2015 12:31 pm

[SOLVED] DHCP starts after reconnection in a static interfac

Tue May 10, 2016 9:05 am

I have install a fresh Jessie image and same problem.

I had follow the dhcpcd.conf creating profiles and blablabla but it is buggy. Do exactly the same. At the boot everything works ok, but when you unplug and plug again if fails.

Solution, the one mention before, edit /etc/wpa_supplicant/ifupdown.sh with it everything works even dhcpcd.conf

dicktonyboy
Posts: 6
Joined: Wed Jul 27, 2011 10:40 pm

Re: DHCP starts after reconnection in a static interface

Tue May 10, 2016 1:29 pm

eg stick this in /etc/dhcpcd.conf

interface eth0
static ip_address=192.168.0.181/24
static routers=192.168.0.1
static domain_name_servers=192.168.0.1

and leave /etc/network/interfaces as just

iface eth0 inet manual

This survives any disconnection /reconnection.
(Now all I need to know is how to add multiple ip addresses to eth0)

Return to “Troubleshooting”