Ok, so i might have messed up a bit my system and now i am unable to set a static ip through /etc/dhcpcd.conf

I'm running raspbian stretch on pi zero w

here is what i have done: I followed this link https://www.raspberrypi.org/documentation/configuration/wireless/access-point.md to set pi as access point then it turned out not exactly what i want as i only need to have DHCP server running on the pi, so i attempted to undo the changes I made I did

 sudo apt-get remove hostapd dnsmasq

, however if i run

sudo systemctl status hostapd

i see its still active!

basically i have undone every step i made in that tutorial except these two which i couldn't figure out how to undo that or reset to default so not sure if its source of problem here..

Add a masquerade for outbound traffic on eth0:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

Save the iptables rule.

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"

my /etc/dhcpcd.conf:

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

# Use the hardware address of the interface for the Client ID.
# 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.

# Persist interface configuration when dhcpcd exits.

# 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

# Example static IP configuration:
#interface eth0
#static ip_address=
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=
#static domain_name_servers= fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
#profile static_eth0
#static ip_address=
#static routers=
#static domain_name_servers=

# fallback to static profile on eth0
#interface eth0
#fallback static_eth0

interface wlan0
  static ip_address=
  nohook wpa_supplicant

output of ifconfig:

    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet  netmask
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 370  bytes 34870 (34.0 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 370  bytes 34870 (34.0 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet  netmask  broadcast
            inet6 fe80::ede7:ac03:2417:f53d  prefixlen 64  scopeid 0x20<link>
            ether 86:03:1c:a1:7e:d9  txqueuelen 1000  (Ethernet)
            RX packets 1616  bytes 149330 (145.8 KiB)
            RX errors 0  dropped 4  overruns 0  frame 0
            TX packets 1722  bytes 269309 (262.9 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    wlan0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            ether b8:27:eb:e9:6f:91  txqueuelen 1000  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

 I don't know why it is not setting the static ip address on interface wlan0?!


outpu of systemctl status dhcpcd.service

● dhcpcd.service - dhcpcd on all interfaces
   Loaded: loaded (/lib/systemd/system/dhcpcd.service; enabled; vendor preset: enabled)
  Drop-In: /etc/systemd/system/dhcpcd.service.d
   Active: active (running) since Tue 2019-02-12 08:33:46 UTC; 4min 1s ago
  Process: 241 ExecStart=/usr/lib/dhcpcd5/dhcpcd -q -w (code=exited, status=0/SUCCESS)
 Main PID: 398 (dhcpcd)
   CGroup: /system.slice/dhcpcd.service
           ├─345 wpa_supplicant -B -c/etc/wpa_supplicant/wpa_supplicant.conf -iwlan0 -Dnl80211,wext
           └─398 /sbin/dhcpcd -q -w

Feb 12 08:33:39 raspi-goggles dhcpcd[241]: wlan0: probing address
Feb 12 08:33:39 raspi-goggles dhcpcd[241]: wlan0: carrier lost
Feb 12 08:33:39 raspi-goggles dhcpcd[241]: wlan0: deleting address fe80::987c:c17a:851a:c67c
Feb 12 08:33:40 raspi-goggles dhcpcd[241]: usb0: probing for an IPv4LL address
Feb 12 08:33:46 raspi-goggles dhcpcd[241]: usb0: using IPv4LL address
Feb 12 08:33:46 raspi-goggles dhcpcd[241]: usb0: adding route to
Feb 12 08:33:46 raspi-goggles dhcpcd[241]: usb0: adding default route
Feb 12 08:33:46 raspi-goggles dhcpcd[241]: forked to background, child pid 398
Feb 12 08:33:46 raspi-goggles systemd[1]: Started dhcpcd on all interfaces.
Feb 12 08:33:49 raspi-goggles dhcpcd[398]: usb0: no IPv6 Routers available
Warning: dhcpcd.service changed on disk. Run 'systemctl daemon-reload' to reload units.

update 2: I found out something that might be interesting:

if I add valid network credentials to /etc/wpa_supplicant/wpa_supplicant.conf such as:


the static ip in /etc/dhcpcd.conf works however, if i put wrong values for network t doesn't. I don't really understand why is that, but I don't want to use vlaid credentials because I am not expecting the Pi to be connected to another LAN, I only want to give it a static ip and run a dhcp server on it and enable wifi p2p where other devices can connect to it.

  • FYI: The link to the tutorial you initially followed is broken, can you edit your question. – Roger Jones Feb 12 at 15:13
  • 1
    fixed it, sorry about that. – Mohyddin Feb 12 at 16:08

I have been following a similar tutorial and can speak from my attempts at this. My suggestion would be to reflash your PI and start over. It can honestly be easier going through and redoing the tutorial than fixing the problem. There my be more issues then just the dhcpcd not working.

1.You can flush Iptable rules.

sudo iptables -t nat -F

-F flushes your Iptable nat rules. Also note that this is not why your not getting a wlan0 static IP. The Iptable rules are for forwarding ethernet network traffic to you wlan AP. You only need this if you want connection to the internet, otherwise you don't need if for just an AP.

2.Manually you can try to stop hostapd.

sudo service hostapd stop

3.There could be a legacy DNS issues that I find interferes with RPI3 stretch dhcpcd. Check your version with : dpkg -s dnsmasq versions 2.77 and above are ok. If not then try the command:

sudo apt-get purge dns-root-data

4.You may want to add a router to your Dhcpcd.conf

nohook wpa_supplicant
interface wlan0
static ip_address=
static routers=

What do you get from systemctl status dhcpcd.service ?

I have also built a shell script tool to automate this for me becuase all of the issues I was running into.

  • I updated with output of systemctl status dhcpcd.service, i have also tried all the steps you have mentioned, i might go for reflashing the pi, but i alo found out something maybe worth looking into, i will add as an update too – Mohyddin Feb 12 at 18:57

Seems you are really mixing up things. Following the tutorial you have linked step by step then there is running a DHCP server (dnsmasq) on the RasPi. That's what you want. You have to ensure that there is no other DHCP server running on your network, maybe on a available internet router. Then you have to disable that one.

With your update 2 you tell that you attempt to use wpa_supplicant as client connection on interface wlan0. This doesn't make sense because wlan0 is already occupied by hostapd for the access point. If you want to use wlan0 as access point and as client connection you have to define an additional virtual interface ap0 on it but this is another approach than covered by the linked tutorial.

So I suggest to start over from scratch with a fresh flashed Raspbian Stretch Lite and follow the linked tutorial step by step. As far as I see it should do what you want. If you want to have a more complicated setup you may have a look at Setting up a Raspberry Pi as an access point - the easy way.

Update to answer questions from the comment:
To create a DHCP server you can use dnsmasq or isc-dhcp-server but this is the only common ground. dnsmasq is a lightweight DHCP server easy to configure but doing only the most common things for DHCP. isc-dhcp-server is a heavyweight covering all possibilities and often used by internet provider. So because you are not so familiar with networking you should use dnsmasq. Only if it doesn't cover a need for you you must use isc-dhcp-server.

If you want to only run a DHCP server on the RasPi then you must have a connection to the network that it should serve with ip addresses. You have to decide how do you want to connect. With a RPi0W you can only use WiFi: connected as wifi station to a remote access point, or the RasPi spawns its on subnet as access point, so other devices can connect to it.

You want to use a peer-to-peer (p2p) network. Here are also two possibilities in general. You can use an ad-hoc (IBSS) network or WiFi-Direct connections. Both are different peer-to-peer solutions (WiFi-Direct isn't really one).

So what connection to the network do you want to use to serve ip addresses from the DHCP server?

  • as station to a remote access point?
  • as self made access point?
  • as ad-hoc connection?
  • as WiFi-Direct connection?

Depending on your answers the solution differ. For WiFi-Direct I cannot help you at the moment. Im just working on it.

  • sorry I'm not an expert when it comes to networking, so as you suggest looks like I'll end up re-flashing the pi and starting from scratch, but I still have some unclear things, hope you can clarify, I assume dnsmasq and isc-dhcp-server are similar so i could use one or the other?and if I want to have the pi just having a dhcp server running and wifi p2p enabled? is the link I mentioned still useful as someone else has pointed out to me that this link is for configuring pi as an access point and what I need is just dhcp server running do you have any resources I can check for doing so? cheers! – Mohyddin Feb 12 at 22:46
  • @Mohyddin I have updated my answer. – Ingo Feb 13 at 0:05
  • thanks, yes, unfortunately I need this for WiFi Direct, good luck with your project! if it works for you, could you please share how you did thart? I will do so too, once I manage to get it working! – Mohyddin Feb 13 at 11:38
  • @Mohyddin We can examine it together with your other question Setting up Wifi direct (wifi p2p) and DHCP server. It's perfect to answer that step by step. We have already started with wpa_supplicant.conf. – Ingo Feb 13 at 12:32
  • 1
    sure! let's move the discussion over there, so that it will be all in one place, and we keep can updating with any working progress over there. – Mohyddin Feb 13 at 16:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.