Setting static IP address to UDHCP client

ENzero

New Member
Credits
0
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 172.16.0.2

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.
 


Lazydog

Member
Credits
0
Is 172.16.0.2 part of your DHCP scope? If it is why not simple reserve that ip for this device? If it's not why not set the IP Address statically on the device itself?
 

ENzero

New Member
Credits
0
Thanks for responding @Lazydog !

Is 172.16.0.2 part of your DHCP scope? If it is why not simple reserve that ip for this device? If it's not why not set the IP Address statically on the device itself?
I am testing my udhcpc device against random access points like phones. So I don't have a single specific dhcp server to configure.

So i do not add any additional configuration to udhcpc and just set the network configurations?
 

Lazydog

Member
Credits
0
I'm not sure how udhcp works but normally you wouldn't set an ip as the dhcp server would give that to you.
 

ENzero

New Member
Credits
0
Just found out the reason why it was not working. I was setting an IP address outside of its range. dhcpc can only accept Ip requests from client within its range.
 

mal-2

New Member
Credits
0
I'm not sure if I understand everything. Has the client in the dhcp environment to ignore the server and assign it's own static address or should the dhcp server provide for as specific client always the same IP?

In general I would anyway recommend man /etc/networks. In this file you can configure the link behavior like if it should be activated on startup, when you plug a cable in, if it has a static IP oder a dhcp server and so on.

But if you need server side assigned IPs I'm not familiar with udhcpc but for example with dnsmasq you can provide to connecting clients different tokens depending of the clients attributes. And when you have identified a client as desired you can set an IP address to the token. As there are the craziest attributes to look for theres practically no limit in defining some IP ranges / subnets etc.
 


Members online


Top