Setting static IP address with UDHCP client

I am using udhcp client for an embedded device. I am trying to add a feature to set a static IP, Netmask, DNS, and gateway address.

I am trying to set it through the "-r" argument (request):

/sbin/udhcpc -A 3 -f -s /tmp/udhcpc_wlan0_sh -i wlan0 -r

It does not seem to work. I try to connect my device to an access point and it still used the dhcp deamon provide address.

I was wondering if there are any additional things that I need to do to enable static address.

  -r IP           Request this IP address 

dhcp = dynamic.... the assignment is from upstream.

change the interface proto to static or ring up whoever manages the dhcp server responsible for assigning the address to your dhcp client and ask them to assign a reservation.

As wulfy23 mentioned, it is up to the DHCP server to decide whether it will give you the requested IP or a different one. So, if you want a "mostly" static IP via DHCP, you should reserve an IP for the client's MAC address on the server (if it's under your control).

There's one more thing to keep in mind, though. If you have already configured the server to give the client the specific address, it might still be possible that the server will assign a different address in case there is an active leave for a different client with the same address or - at least with some servers - if it still has an active lease for the client with a different address and it may give the actively leased address again to the client instead of the reserved one. In either case, it usually helps to flush the lease database of the DHCP server. How you do that, depends on the server, but if it's OpenWrt based a simple reboot should suffice.