dhcpcd-discuss

Re: How to prevent bringing interface up on system startup and be able to bring it up manually

Роман Мещеряков

Sat Apr 15 12:33:41 2017

Hi Roy,
 
Thank you for quick response!
 
> Why?
 
RPi-based system I'm developing will get it's internet access via Ethernet interface and will not need Wi-Fi at all. Ethernet interface will be connected to Wi-Fi router which will connect to internet using USB 3G/4G modem attached to it.
But in the process of development it's convenient to get internet on RPi via built-in Wi-Fi. But I prefer Wi-Fi to be down by default in order to be sure it will not create mess in network routes or by other means. I think for complicated systems it's generally good idea to keep unused components disabled. Also from security point of view: enabled Wi-Fi is potential security hole.
 
>But in answer to your question, you should be able to do this.
>In dhcpcd.conf put:
>allowinterfaces eth0

>This makes dhcpcd start eth0 only.
>You can then go onto start wlan0 like so
>dhcpcd -n wlan0
 
I tried this with dhcpcd 6.7.1, but it didn't work: after issuing "dhcpcd -n wlan0" nothing happened, wlan0 remained down.
I supposed this could be fixed already in a newer dhcpcd version, so I installed version 6.10.1-1 manually from here. Things changed a bit: now after issuing "rebind" wlan0 is bringed up, but it has no IPv4 address assigned.
It is also strange that despite "debug" option in /etc/dhcpcd.conf there are no "wlan0" mentions in /var/log/syslog after issuing "dhcpcd --rebind wlan0".
You can see commands I typed and their output in the "commands.txt" file attached. Also attached /etc/dhcpcd.conf and /etc/network/interfaces used.
 
-- 
Kind regards, Roman Mescheryakov
 
 
 
14.04.2017, 22:13, "Roy Marples" <roy@xxxxxxxxxxxx>:

Hi

On 14/04/17 15:43, Роман Мещеряков wrote:

 I have Raspberry Pi (RPi) mini-PC with Raspbian OS which is adaptation
 of Debian. RPi model 3 B has 2 built-in network interfaces: Ethernet
 (eth0) and Wi-Fi (wlan0). As far as I know, in Raspbian it is dhcpcd
 that manages network configuration.


By default this is the case.
 

 I need to configure it in such a way that on system startup only eth0 is
 brought up. At the same time I need opportunity to bring up wlan0 at any
 time with simple command like “ifconfig wlan0 up” or “ifup wlan0”. I
 read “man dhcpcd.conf” and tried using “denyinterfaces wlan0”
 configuration option, but this seems to make wlan0 completely out of
 dhcpcd’s control. Is it possible to configure dhcpcd to get the result
 desired?


Why?

With both brought up and connected, dhcpcd should prefer eth0 over wlan0
all the time. Although both will have IP addresses, routes and gateways,
eth0 will have the lower metric to ensure it gets all the traffic - the
premise being that wired is faster than wireless (this isn't 100%, but
is a good default).

But in answer to your question, you should be able to do this.
In dhcpcd.conf put:
allowinterfaces eth0

This makes dhcpcd start eth0 only.
You can then go onto start wlan0 like so
dhcpcd -n wlan0

This should notify dhcpcd via it's control socket to start wlan0 and
should bring it up.
 

 dhcpcd version installed in Raspbian by default is 6.7.1.


That's getting old now, but no reason why it shouldn't work.

Roy

pi@volnaya5:~/ColourDreams/Soft $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:70:af:2e
          inet addr:192.168.2.100  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::ba66:d3af:5c7f:7490/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:81 errors:0 dropped:0 overruns:0 frame:0
          TX packets:139 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:8373 (8.1 KiB)  TX bytes:23629 (23.0 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:232 errors:0 dropped:0 overruns:0 frame:0
          TX packets:232 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:19152 (18.7 KiB)  TX bytes:19152 (18.7 KiB)

pi@volnaya5:~/ColourDreams/Soft $ date
Сб апÑ? 15 15:03:41 MSK 2017
pi@volnaya5:~/ColourDreams/Soft $ dhcpcd --rebind wlan0
control_open: Permission denied
open `/var/run/dhcpcd-wlan0.pid': Permission denied
dhcpcd-6.10.1 starting
wlan0: interface not found or invalid
dhcpcd exited
pi@volnaya5:~/ColourDreams/Soft $ date
Сб апÑ? 15 15:03:58 MSK 2017
pi@volnaya5:~/ColourDreams/Soft $ sudo dhcpcd --rebind wlan0
sending commands to master dhcpcd process
send OK
pi@volnaya5:~/ColourDreams/Soft $ tail -n 100 /var/log/syslog
<old entries cut>
2017-04-15T15:01:28.348646+03:00 volnaya5 dhcpcd[609]: eth0: DAD completed for 192.168.2.100
2017-04-15T15:01:28.349495+03:00 volnaya5 dhcpcd[609]: eth0: leased 192.168.2.100 for 604800 seconds
2017-04-15T15:01:28.350321+03:00 volnaya5 dhcpcd[609]: eth0: renew in 302400 seconds, rebind in 529200 seconds
2017-04-15T15:01:28.351346+03:00 volnaya5 dhcpcd[609]: eth0: writing lease `/var/lib/dhcpcd5/dhcpcd-eth0.lease'
2017-04-15T15:01:28.352197+03:00 volnaya5 dhcpcd[609]: eth0: adding IP address 192.168.2.100/24
2017-04-15T15:01:28.352834+03:00 volnaya5 dhcpcd[609]: eth0: adding route to 192.168.2.0/24
2017-04-15T15:01:28.353501+03:00 volnaya5 dhcpcd[609]: eth0: adding default route via 192.168.2.254
2017-04-15T15:01:28.354133+03:00 volnaya5 dhcpcd[609]: eth0: ARP announcing 192.168.2.100 (1 of 2), next in 2.0 seconds
2017-04-15T15:01:28.354815+03:00 volnaya5 dhcpcd[609]: eth0: executing `/lib/dhcpcd/dhcpcd-run-hooks' BOUND
2017-04-15T15:01:28.355873+03:00 volnaya5 avahi-daemon[446]: Joining mDNS multicast group on interface eth0.IPv4 with address 192.168.2.100.
2017-04-15T15:01:28.356866+03:00 volnaya5 avahi-daemon[446]: New relevant interface eth0.IPv4 for mDNS.
2017-04-15T15:01:28.357720+03:00 volnaya5 avahi-daemon[446]: Registering new address record for 192.168.2.100 on eth0.IPv4.
2017-04-15T15:01:28.430119+03:00 volnaya5 systemd[1]: master_player.service holdoff time over, scheduling restart.
2017-04-15T15:01:28.431199+03:00 volnaya5 systemd[1]: Stopping Projection Lab master player service...
2017-04-15T15:01:28.432040+03:00 volnaya5 systemd[1]: Starting Projection Lab master player service...
2017-04-15T15:01:28.432820+03:00 volnaya5 systemd[1]: master_player.service start request repeated too quickly, refusing to start.
2017-04-15T15:01:28.433684+03:00 volnaya5 systemd[1]: Failed to start Projection Lab master player service.
2017-04-15T15:01:28.434393+03:00 volnaya5 systemd[1]: Unit master_player.service entered failed state.
2017-04-15T15:01:28.501453+03:00 volnaya5 dhcpcd[609]: eth0: sending Router Solicitation
2017-04-15T15:01:28.502307+03:00 volnaya5 dhcpcd[609]: eth0: removing route to 192.168.2.0/24
2017-04-15T15:01:29.218996+03:00 volnaya5 weavedConnectd[568]: initialize proxy client target 127.0.0.1 port 65535
2017-04-15T15:01:29.219813+03:00 volnaya5 weavedConnectd[568]: 29692> Weaved Registration Code Provided (checkhash e6:3d)
2017-04-15T15:01:29.396175+03:00 volnaya5 weavedConnectd[671]: initialize proxy client target 127.0.0.1 port 22
2017-04-15T15:01:29.397040+03:00 volnaya5 weavedConnectd[671]: 29693> Weaved Registration Code Provided (checkhash 14:ed)
2017-04-15T15:01:29.419490+03:00 volnaya5 weavedConnectd[568]: 29694> local IP address changed to 192.168.2.100
2017-04-15T15:01:29.420206+03:00 volnaya5 weavedConnectd[568]: 29694> local IP address changed to 192.168.2.100
2017-04-15T15:01:29.596638+03:00 volnaya5 weavedConnectd[671]: 29695> local IP address changed to 192.168.2.100
2017-04-15T15:01:29.597510+03:00 volnaya5 weavedConnectd[671]: 29695> local IP address changed to 192.168.2.100
2017-04-15T15:01:29.713329+03:00 volnaya5 ntpd[498]: Listen normally on 5 eth0 192.168.2.100 UDP 123
2017-04-15T15:01:29.714104+03:00 volnaya5 ntpd[498]: peers refreshed
2017-04-15T15:01:30.350817+03:00 volnaya5 dhcpcd[609]: eth0: ARP announcing 192.168.2.100 (2 of 2)
2017-04-15T15:01:31.791266+03:00 volnaya5 ntpd_intres[531]: DNS 0.debian.pool.ntp.org -> 95.104.192.10
2017-04-15T15:01:32.031219+03:00 volnaya5 ntpd_intres[531]: DNS 1.debian.pool.ntp.org -> 91.206.16.3
2017-04-15T15:01:32.151752+03:00 volnaya5 ntpd_intres[531]: DNS 2.debian.pool.ntp.org -> 91.233.133.238
2017-04-15T15:01:32.201242+03:00 volnaya5 ntpd_intres[531]: DNS 3.debian.pool.ntp.org -> 185.22.60.71
2017-04-15T15:01:32.503201+03:00 volnaya5 dhcpcd[609]: eth0: sending Router Solicitation
2017-04-15T15:01:36.507686+03:00 volnaya5 dhcpcd[609]: eth0: sending Router Solicitation
2017-04-15T15:01:36.509084+03:00 volnaya5 dhcpcd[609]: eth0: no IPv6 Routers available
2017-04-15T15:01:37.201394+03:00 volnaya5 weavedConnectd[568]: Server Connection changed to state 1
2017-04-15T15:01:37.411183+03:00 volnaya5 weavedConnectd[671]: Server Connection changed to state 1
pi@volnaya5:~/ColourDreams/Soft $ dhcpcd --version
dhcpcd 6.10.1
Copyright (c) 2006-2016 Roy Marples
pi@volnaya5:~/ColourDreams/Soft $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:70:af:2e
          inet addr:192.168.2.100  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::ba66:d3af:5c7f:7490/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:417 errors:0 dropped:0 overruns:0 frame:0
          TX packets:462 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:32451 (31.6 KiB)  TX bytes:73684 (71.9 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:232 errors:0 dropped:0 overruns:0 frame:0
          TX packets:232 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:19152 (18.7 KiB)  TX bytes:19152 (18.7 KiB)

wlan0     Link encap:Ethernet  HWaddr b8:27:eb:25:fa:7b
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:1 errors:0 dropped:1 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:60 (60.0 B)  TX bytes:0 (0.0 B)

pi@volnaya5:~/ColourDreams/Soft $
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
#clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# Trace debug messages
debug

# Automatically bring up only eth0
allowinterfaces eth0

Attachment: interfaces
Description: Binary data


Follow-Ups:
Re: How to prevent bringing interface up on system startup and be able to bring it up manuallyРоман Мещеряков
References:
How to prevent bringing interface up on system startup and be able to bring it up manuallyРоман Мещеряков
Re: How to prevent bringing interface up on system startup and be able to bring it up manuallyRoy Marples
Archive administrator: postmaster@marples.name