I have a Linux machine on raspberry that function as an access point.

Linux raspberrypi 3.18.7-v7+ #755 SMP PREEMPT Thu Feb 12 17:20:48 GMT 2015 armv7l GNU/Linux

And I have a DHCP server on it. in the /etc/network/interfaces I've defined a static IP address however whenever I start it I get an IP which is not the static one but rather from the DHCP server. This behavior is not consistent and sometimes I get the static IP.

this is a module as part of a project that function sometimes as an AP and sometimes as Client based on parameters in a script. some of the cases when changing back to AP it gets the IP wrong although the conf files are as below in all cases.

this is my hostapd.conf

ssid=my ssid

this is my interfaces file

auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static


ddns-update-style none;
default-lease-time 600;
max-lease-time 7200;
log-facility local7;
subnet netmask {
  option broadcast-address;
  option routers;
  default-lease-time 600;
  max-lease-time 7200;
  option domain-name "domain";

ifconfig wlan0

wlan0     Link encap:Ethernet  HWaddr 74:da:38:26:9f:d6
          inet addr:  Bcast:  Mask:
          RX packets:129 errors:0 dropped:5369 overruns:0 frame:0
          TX packets:0 errors:0 dropped:726 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:65760423 (62.7 MiB)  TX bytes:12737873 (12.1 MiB)

ifquery wlan0


ping to was changed to and got destination unreachable ping to works

the eth0 didn't get an IP.

  • Please add the output of ip addr (or ifconfig). – Daniel B Aug 6 '15 at 13:39
  • I've added the ifconfig data. – Guy Ephraim Aug 6 '15 at 13:49
  • also this behavior is not consistent, sometimes I do get the static ip - added to the question body. – Guy Ephraim Aug 6 '15 at 13:50
  • "I have a Linux machine" - which distribution? Do you have network-manager service running or a similar service that is doing some auto configuration. – albal Aug 6 '15 at 14:23
  • it runs on a raspberry - added uname -a – Guy Ephraim Aug 6 '15 at 14:34

Make sure that your eth0 and wlan0 are on different IP address ranges, and that your DHCP server only listens on the wlan0 device. Also, make sure that it doesn't contain a leased address for the wlan0 MAC address.

Then, make sure that no other services touching wlan0 are active (I am thinking of NetworkManager, wicd and similar services). Also, you need to somehow guarantee that, when switching from "Client Mode" to "AP Mode", no race conditions can happen. Otherwise, a stray DHCP client from the client mode may decide to change the IP address back.

  • the wlan0 get a leased address, this is the root of the problem but I've specified an explicit static IP address in the interfaces file. how can I prevent it from happening? – Guy Ephraim Sep 2 '15 at 10:33

There was a race condition between the DHCP client and the "AP mode". meaning that I got an IP from my own DHCP.

I fixed it by providing the static IP I wanted, to the DHCP server with a constraint to limit it to my MAC Address only.

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.