musicboy
Posts: 15
Joined: Fri Feb 14, 2014 6:52 pm

Configuring dhcpcd in Raspbian Stretch

Tue Aug 22, 2017 7:37 pm

Hi all,

I'm trying to set up my Pi Zero W as an access point, as per the official tutorial here:
https://www.raspberrypi.org/documentati ... s-point.md

However, I'm having some trouble getting dhcpcd to play nice.

After adding the following to /etc/network/interfaces :

Code: Select all

allow-hotplug wlan0  
iface wlan0 inet static  
    address 192.168.0.1
    netmask 255.255.255.0
    network 192.168.0.0
When I do

Code: Select all

sudo service dhcpcd restart
I get the following:

Code: Select all

Job for dhcpcd.service failed because the control process exited with error code. 
See "systemctl status dhcpcd.service" and "journalctl -xe" for details.
The relevant bit of the output of those commands is this:

Code: Select all

Not running dhcpcd because /etc/network/interfaces defines some interfaces that will use a DHCP client or static address.
dhcpcd.service: Control process exited, code=exited status=6
Any help much appreciated!

SurferTim
Posts: 1767
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Configuring dhcpcd in Raspbian Stretch

Wed Aug 23, 2017 11:51 am

Use /etc/dhcpcd.conf to assign static IPs in Jessie or Stretch.

Code: Select all

interface wlan0
static ip_address=192.168.0.1/24

jerry7580
Posts: 3
Joined: Mon Jan 25, 2016 11:00 pm

Re: Configuring dhcpcd in Raspbian Stretch

Mon Aug 28, 2017 8:52 pm

I am also having this same issue. I have an access point up and working under Jessie and started with that configuration under Stretch. If you have yours working, I could sure use your suggestions. Thanks!

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

Re: Configuring dhcpcd in Raspbian Stretch

Tue Aug 29, 2017 12:59 am

What model of RPi do you have? Is it on-board WiFi or a WiFi USB dongle?
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

musicboy
Posts: 15
Joined: Fri Feb 14, 2014 6:52 pm

Re: Configuring dhcpcd in Raspbian Stretch

Tue Aug 29, 2017 9:45 am

jerry7580 wrote:
Mon Aug 28, 2017 8:52 pm
I am also having this same issue. I have an access point up and working under Jessie and started with that configuration under Stretch. If you have yours working, I could sure use your suggestions. Thanks!
Apologies but I eventually gave up as I was gifted a mini hotspot gizmo by a friend that also has internet bridged mode.

I wish you the best of luck, and if you do get it working it would certainly be worth writing a blog post on!

danherd
Posts: 1
Joined: Wed Aug 30, 2017 11:14 am

Re: Configuring dhcpcd in Raspbian Stretch

Wed Aug 30, 2017 11:20 am

This is driving me crazy. How on earth do you create an access point in Raspbian stretch?

As was mentioned above, the official guide doesn't help, because the minute you add the static IP information for wlan0 to /etc/network/interfaces, dhcpcd won't restart - even if you add:

Code: Select all

denyinterfaces wlan0
to /etc/dhcpcd.conf.

I tried setting the static IP for wlan0 in /etc/dhcpcd.conf, but this doesn't seem to work with hostapd.

SurferTim
Posts: 1767
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Configuring dhcpcd in Raspbian Stretch

Wed Aug 30, 2017 1:34 pm

I have my RPi3 working as an AP with one caveat. The dnsmasq service will not start on boot.
Edit: Fixed boot problem. See new /etc/dnsmasq.conf below.

DO NOT MODIFY /etc/network/interfaces FILE!

My /etc/dhcpcd.conf addition:

Code: Select all

interface wlan0
static ip_address=192.168.4.1/24
static routers=192.168.4.1
static domain_name_servers=8.8.8.8
My /etc/dnsmasq.conf file

Code: Select all

interface=wlan0
domain-needed
bogus-priv
dhcp-range=192.168.4.8,192.168.4.250,12h
My /etc/hostapd/hostapd.conf file

Code: Select all

interface=wlan0
driver=nl80211
ssid=RPiNet
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=mypassphrase
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
Edit /etc/default/hostapd and change this:

Code: Select all

DAEMON_CONF="/etc/hostapd/hostapd.conf"
The next section is required only if you are wanting to access the internet through the ethernet connection.

Edit /etc/sysctl.conf and uncomment

Code: Select all

net.ipv4.ip_forward=1
My iptables rules. Replace ethX with your ethernet interface name from ifconfig.

Code: Select all

sudo iptables -t nat -A  POSTROUTING -o ethX -j MASQUERADE
sudo iptables -A FORWARD -i ethX -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o ethX -j ACCEPT
Edit: Changed masquerade to MASQUERADE.
Last edited by SurferTim on Tue Sep 05, 2017 9:50 pm, edited 1 time in total.

jerry7580
Posts: 3
Joined: Mon Jan 25, 2016 11:00 pm

Re: Configuring dhcpcd in Raspbian Stretch

Thu Aug 31, 2017 3:15 pm

I am using a Raspberry Pi Zero W and tried following the instructions in the post above. Still not working for me. Here is what I get with #systemctl status -l hostapd.service:

Code: Select all

  hostapd.service - LSB: Advanced IEEE 802.11 management daemon
   Loaded: loaded (/etc/init.d/hostapd; generated; vendor preset: enabled)
   Active: active (exited) since Thu 2017-08-31 09:51:23 CDT; 2min 10s ago
     Docs: man:systemd-sysv-generator(8)
 Process: 482 ExecStart=/etc/init.d/hostapd start (code=exited, status=0/SUCCES
   CGroup: /system.slice/hostapd.service

Aug 31 09:51:21 Garage systemd[1]: Starting LSB: Advanced IEEE 802.11 management
Aug 31 09:51:23 Garage hostapd[482]: Starting advanced IEEE 802.11 management: h
Aug 31 09:51:23 Garage systemd[1]: Started LSB: Advanced IEEE 802.11 management
I have Access Point all set up and working on this same Zero W under Raspbian Jessie but cannot get it working under Raspbian Stretch.

SurferTim
Posts: 1767
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Configuring dhcpcd in Raspbian Stretch

Thu Aug 31, 2017 4:02 pm

I had a problem just now. I had to restart both services to get the AP SSID to come up.

Code: Select all

sudo service dnsmasq restart
sudo service hostapd restart
After that, a cold boot shows the AP up and running. Let me know if that helps you.
Don't know the reason for the fail. I'll check again later.

Edit: Which version of Raspian are you using? I'm testing Stretch on both PIXEL and Lite.

Edit2: One thing I had not done on this fresh install is run rpi-update.

Code: Select all

sudo rpi-update
I'll shut it down for a while and see how it does.

SurferTim
Posts: 1767
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Configuring dhcpcd in Raspbian Stretch

Thu Aug 31, 2017 7:16 pm

I left it down for a couple hours, and it booted up clean.The SSID is showing and the internet is accessible. Tried both Pixel and Lite, and both work fine.

Jarrod
Posts: 16
Joined: Sat Sep 02, 2017 5:57 am

Re: Configuring dhcpcd in Raspbian Stretch

Sat Sep 02, 2017 6:02 am

I've created a new AP on Pi Zero W with hostapd/dnsmasq working under Jessie in under 20 minutes start to finish.

I'm going on three hours with Stretch and cannot for the life of me figure it out. How does wpa_supplicant.conf play into all this? dhcpcd is barking about that file but I'm not setting the machine up as a client to another network - it's the AP. I moved wpa_supplicant.conf out of the way entirely but that broke everything.

I'm really, really nonplussed about the new networking system (or should I say three competing systems) in Stretch.

SurferTim
Posts: 1767
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Configuring dhcpcd in Raspbian Stretch

Sat Sep 02, 2017 12:36 pm

Can you post your /etc/network/interfaces file contents? Stretch uses a different setup there than Jessie did. You should also post the contents of /etc/dhcpcd.conf.

edit: For the others here, my AP has booted up ok since I did the rpi-update.

Jarrod
Posts: 16
Joined: Sat Sep 02, 2017 5:57 am

Re: Configuring dhcpcd in Raspbian Stretch

Sat Sep 02, 2017 5:39 pm

Interfaces was stock, untouched from the Stretch install. Everything else was as you posted above with the exception of wpa_supplicant.conf (which I don't think you mentioned). There were complaints about wpa_supplicant in the dhcpcd syslog output. Not sure precisely what went wrong but I suspect there was an interaction there that caused my issue. I since gave up and went back to Jessie. Thanks for offering to help, but I've had enough of the horrible networking stack in Stretch to last me for awhile.

Specifically, who decided that dhcpcd was the place to configure static IP addresses? If DHCP is involved in assigning a static IP then this should be setup on the server, not the client. The client should not dictate the configuration of the network - only the information that it seeks from the server. That is completely counterintuitive and frankly dangerous.

I assume it was a smart person, done for reasons. But with no documentation or justification I'm left to wonder and curse under my breath.

SurferTim
Posts: 1767
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Configuring dhcpcd in Raspbian Stretch

Sat Sep 02, 2017 8:45 pm

I didn't mention wpa_supplicant because it should be left alone. Mine is empty except the default interface setup.

Code: Select all

country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
All I add to /etc/dhcpcd.conf for an AP is this:

Code: Select all

interface wlan0
static ip_address=192.168.4.1/24
After a reboot it shows wlan0 has 192.168.4.1 in ifconfig.

Jarrod
Posts: 16
Joined: Sat Sep 02, 2017 5:57 am

Re: Configuring dhcpcd in Raspbian Stretch

Sat Sep 02, 2017 10:15 pm

Thank you that clears it up. I did a headless setup where you put wpa_supplicant.conf and a file called ssh in the /boot directory before installing the sd card and performing first boot on the pi. First boot then puts your /boot/supplicant.conf into /etc/wpa_supplicant/wpa_supplicant.conf, thus blowing away the default, and enables sshd so you can log in remotely and configure.

That is probably what caused my issue, I will try again with a different SD card.

DirkS
Posts: 9460
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Configuring dhcpcd in Raspbian Stretch

Sat Sep 02, 2017 11:04 pm

Jarrod wrote:
Sat Sep 02, 2017 10:15 pm
Thank you that clears it up. I did a headless setup where you put wpa_supplicant.conf and a file called ssh in the /boot directory before installing the sd card and performing first boot on the pi. First boot then puts your /boot/supplicant.conf into /etc/wpa_supplicant/wpa_supplicant.conf, thus blowing away the default, and enables sshd so you can log in remotely and configure.

That is probably what caused my issue, I will try again with a different SD card.
If you do it on another computer (e.g. Windows PC) they should be put in the root directory of the first partition (the only accessible partition on a Windows machine)

Jarrod
Posts: 16
Joined: Sat Sep 02, 2017 5:57 am

Re: Configuring dhcpcd in Raspbian Stretch

Sun Sep 03, 2017 2:14 am

I've successfully built the AP on a Pi Zero W with Stretch now. Thanks to SurferTim for the advice. It seems that wpa_supplicant.conf needs to have the default contents and in particular no networks defined. dhcpcd looks carefully at this file, I believe due to hooks in the new GUI and CLI interfaces for configuring Wifi. It seems that if there is a network defined in wpa_supplicant and also a static IP defined for wlan0 in dhcpcd.conf, dhcpcd opts to deactivate the interface altogether. This was not the case in Jessie. Jessie would simply ignore wpa_supplicant.conf if you had a static ip defined for wlan0 in /etc/network/interfaces as outlined in the official docs for bringing up an AP.

sjdaniels
Posts: 8
Joined: Tue Sep 05, 2017 6:32 pm

Re: Configuring dhcpcd in Raspbian Stretch

Tue Sep 05, 2017 6:34 pm

I tried "sudo iptables -t nat -A POSTROUTING -o ethX -j masquerade" as instructed and receive...

[email protected]:~ $ sudo iptables -t nat -A POSTROUTING -o ethX -j masquerade
iptables v1.6.0: Couldn't load target `masquerade':No such file or directory

Try `iptables -h' or 'iptables --help' for more information.
[email protected]:~ $

Any ideas?

SurferTim
Posts: 1767
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Configuring dhcpcd in Raspbian Stretch

Tue Sep 05, 2017 9:49 pm

Yes. That was my typo. masquerade should be MASQUERADE. Insure to change ethX to the interface name.

Code: Select all

sudo iptables -t nat -A POSTROUTING -o ethX -j MASQUERADE
I edited my post above to correct the error.

biasha
Posts: 10
Joined: Thu Sep 07, 2017 9:54 am

Re: Configuring dhcpcd in Raspbian Stretch

Thu Sep 07, 2017 10:09 am

Jarrod wrote:
Sun Sep 03, 2017 2:14 am
I've successfully built the AP on a Pi Zero W with Stretch now.
cool!
Jarrod wrote:
Sun Sep 03, 2017 2:14 am
wpa_supplicant.conf needs to have the default contents and in particular no networks defined.
not cool...

I have 2 wifi interfaces. I use 1st to connect to the Internet and other for an Access Point.
Obviously I need network to be defined in the wpa_supplicant.conf to be able to connect though 1st interface.

SurferTim
Posts: 1767
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Configuring dhcpcd in Raspbian Stretch

Thu Sep 07, 2017 11:50 am

biasha wrote:I have 2 wifi interfaces. I use 1st to connect to the Internet and other for an Access Point.
Obviously I need network to be defined in the wpa_supplicant.conf to be able to connect though 1st interface.

Seriously, there is a special place in hell for the one who's pushed Stretch in the way she did it.
Then you have a special case. Use your wlanX (internet connected) interface in your setup as if it was the ethernet interface. In your case, you will need an entry in wpa_supplicant.conf and probably in /etc/network/interfaces also.

Jarrod
Posts: 16
Joined: Sat Sep 02, 2017 5:57 am

Re: Configuring dhcpcd in Raspbian Stretch

Thu Sep 07, 2017 2:28 pm

You may need to figure out how to tweak wpa_supplicant (the program, not config file) to only consider your internet-connected wlan interface and not touch the AP interface. Not sure how to do that but it should be possible once you figure out how init calls that. The manpage indicates that wpa_supplicant takes the interface name as an argument (-i option) so you should just need to modify the script that invokes it to just use wlan1, assuming you have wlan0 setup as the AP. In theory :-)

SurferTim
Posts: 1767
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Configuring dhcpcd in Raspbian Stretch

Thu Sep 07, 2017 2:38 pm

Create a new wpa_supplicant.conf file and name it /etc/wpa_supplicant/wpa_supplicant2.conf (or similar).

Then in /etc/network/interfaces,

Code: Select all

auto wlan1

allow-hotplug wlan1

iface wlan1 inet manual
   wpa-conf /etc/wpa_supplicant/wpa_supplicant2.conf

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

Re: Configuring dhcpcd in Raspbian Stretch

Thu Sep 07, 2017 2:46 pm

SurferTim wrote:
Thu Sep 07, 2017 2:38 pm
Create a new wpa_supplicant.conf file and name it /etc/wpa_supplicant/wpa_supplicant2.conf (or similar).

Then in /etc/network/interfaces,

Code: Select all

auto wlan1

allow-hotplug wlan1

iface wlan1 inet manual
   wpa-conf /etc/wpa_supplicant/wpa_supplicant2.conf
I think dhcpcd would also try to start wpa_supplicant. Really, you'd want to configure the network fully in /etc/network/interfaces
https://www.debian.org/doc/manuals/debi ... own_legacy

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

Re: Configuring dhcpcd in Raspbian Stretch

Thu Sep 07, 2017 2:48 pm

Actually, just checked the wpa_supplicant hook for dhcpcd, and it will try to load a wpa_supplicant.conf file named /etc/wpa_supplicant/wpa_supplicant-"$interface".conf first. So, you can configure everything without switching to ifupdown.

Return to “Networking and servers”