Solved dhclient running despite static IP addresses

trev

Aspiring Daemon

Reaction score: 161
Messages: 784

FreeBSD 10.3-STABLE #7 r317754: Sat Jun 17 16:25:50 AEST 2017

It appears that this rule in /etc/devd.conf is triggering:

Code:
#
# Try to start dhclient on Ethernet-like interfaces when the link comes
# up.  Only devices that are configured to support DHCP will actually
# run it.  No link down rule exists because dhclient automatically exits
# when the link goes down.
#
notify 0 {
        match "system"          "IFNET";
        match "type"            "LINK_UP";
        media-type              "ethernet";
        action "/etc/rc.d/dhclient quietstart $subsystem";
};
despite the fact that I have static IPv4 and IPv6 addresses.

From /var/log/messages:

Code:
Jun 19 10:29:46 shadow kernel: nfe0: link state changed to DOWN
Jun 19 10:31:47 shadow kernel: nfe0: link state changed to UP
Jun 19 10:31:47 shadow devd: Executing '/etc/rc.d/dhclient quietstart nfe0'
Jun 19 14:21:50 shadow kernel: nfe0: link state changed to DOWN
Jun 19 14:27:21 shadow kernel: nfe0: link state changed to UP
Jun 19 14:27:21 shadow devd: Executing '/etc/rc.d/dhclient quietstart nfe0'
From /etc/rc.conf:

Code:
ifconfig_nfe0=" inet 192.168.1.4 netmask 0xffffff00 media 100baseTx mediaopt full-duplex"
defaultrouter="192.168.1.1"
ifconfig_nfe0_ipv6="inet6 2400:1dc0:0:1a01:3631:c4dd::4 prefixlen 64"
ipv6_defaultrouter="fe80::3631:c4ff:febc:d01f%nfe0"
Anyone know why? This seems to have only started happening since setting up IPv6.
 
OP
OP
T

trev

Aspiring Daemon

Reaction score: 161
Messages: 784

Ok, I found a /var/db/dhclient.leases.nfe0 which may have something to do with it. I'm not sure how it came to exist, but I've moved it elsewhere now and will see what happens.
 
OP
OP
T

trev

Aspiring Daemon

Reaction score: 161
Messages: 784

Hmmm, there's no dhclient_enable setting in /etc/defaults/rc.conf and more to the point there's no trace of it in /etc/rc.d/dhclient either which suggests it would have no effect. Am I wrong?

[Edit] No I'm not wrong - dhclient_enable="NO" has no effect.

If I unplug the network cable, the interface goes down, when I plug it back in the interface comes up AND dhclient runs despite the static IP addresses.
 

sko

Well-Known Member

Reaction score: 227
Messages: 433

If you don't need the dhclient at all, just comment out the last line of the notify block in /etc/devd.conf.

Adding a check for existing ip-addresses should prevent the unwanted invocation of dhclient on already configured interfaces:
Code:
action "ifconfig $subsystem | grep inet; if [ $? -ne 0 ]; then /etc/rc.d/dhclient quietstart $subsystem; fi";
TrueOS had similar problems due to the wrong openRC service file being installed, which caused devd.conf to fire dhcpcd for all interfaces, constantly.... I used this devd.conf action on my TrueOS desktop systems to prevent dhcpcd being invoked on manually configured interfaces.
 

tobik@

Daemon
Developer

Reaction score: 1,378
Messages: 1,909

Hmmm, there's no dhclient_enable setting in /etc/defaults/rc.conf and more to the point there's no trace of it in /etc/rc.d/dhclient either which suggests it would have no effect. Am I wrong?
No, rcvar is set to nothing in /etc/rc.d/dhclient, so there is indeed no such setting.

If you don't want to edit /etc/devd.conf like sko suggested or need dhclient for other interfaces, you can always override the default rule for a specific interface e.g. create /usr/local/etc/devd/nodhclient_on_nfe0.conf
Code:
# Override the default link up rule and do not autostart dhclient on nfe0
notify 100 {
        match "system"          "IFNET";
        match "type"            "LINK_UP";
        media-type              "ethernet";
	match "subsystem"	"nfe0";
};
(Or if your feeling hacky and don't mind the inevitable log spam you could set dhclient_flags_nfe0="--foobar" (i.e. specify an invalid flag) so that dhclient can't start on nfe0 :p)
 
OP
OP
T

trev

Aspiring Daemon

Reaction score: 161
Messages: 784

Thanks all - I think I'll go with tobik@'s /usr/local/etc/devd/nodhclient_on_nfe0.conf which seems to be the more elegant and least likely to be overriden by rebuilds.
 

usdmatt

Daemon

Reaction score: 521
Messages: 1,399

The devd rule runs when any ethernet interface comes up. This runs a shell script under /etc/rc.d, which just exits if the interface isn't set for DHCP in /etc/rc.conf. The actual dhclient binary should not be starting (and I assume it isn't). As far as I'm aware it's always been like this with devd.
 
OP
OP
T

trev

Aspiring Daemon

Reaction score: 161
Messages: 784

This runs a shell sript under /etc/rc.d, which just exits if the interface isn't set for DHCP in /etc/rc.conf.
I definitely have no DHCP interfaces set in any rc.conf file.

Code:
$ grep -i dhcp /etc/rc.conf
$ grep -i dhcp /etc/defaults/rc.conf
dhclient_program="/sbin/dhclient"       # Path to dhcp client program.
dhclient_flags=""               # Extra flags to pass to dhcp client.
background_dhclient="NO"        # Start dhcp client in the background.
#background_dhclient_fxp0="YES" # Start dhcp client on fxp0 in the background.
defaultroute_delay="30"         # Time to wait for a default route on a DHCP interface.
 

usdmatt

Daemon

Reaction score: 521
Messages: 1,399

I think you're missing my point.

dhclient is not running on your system.

You have a devd rule just like every other FreeBSD system that matches an ethernet LINK_UP event. This is triggered every single time any ethernet interface comes up, regardless of how it's configured. This rule runs a script, /etc/rc.d/dhclient, which looks in rc.conf to see if it should run DHCP on the interface.

In your case it sees that you don't have DHCP set, so the script exits. (You still get a log entry from devd telling you it's matched a rule and triggered an event though)

If you did have DHCP set in rc.conf, the /etc/rc.d/dhclient script would go on to actually run /sbin/dhclient.

You do not have any problem and do not need to create manual devd rules to stop this happening.
 
Top