OpenWrt Forum Archive

Topic: Static IP for a client?

The content of this topic has been archived on 25 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I'm trying to work out if I can set a static IP for a specific client (my desktop) using the udhcp server.  Looking at the options in the sample file, http://udhcp.busybox.net/udhcpd.conf doesn't seem possible.  Anyone done this?

On the ISC DHCPd, you do something like:
host chimay {
        hardware ethernet 00:0F:66:25:2D:EB;
                fixed-address 192.168.1.2;
                }

Doesn't seem possible with udhcp though.

Kinda makes port forwarding difficult if there's the possibility that the router might give out my IP to someone else...

So why use DHCP for the machine you are forwarding to? Why not just give it a static configuration outside of the range of the DHCP scope?

So why use DHCP for the machine you are forwarding to? Why not just give it a static configuration outside of the range of the DHCP scope?

Or use dnsmasq's DHCP-server.

Well potentially (though not actually, in this case) it could be a laptop that moves around between different networks.  You don't really want to be farting around with different configurations.  It should "just work".

try adding this to udhcpd.conf

statics_file /var/udhcpd.statics

add entries to udhcpd.statics in the following format

ip_address mac hostname

(i'm not sure if the hostname is strictly necessary)

That doesn't seem to work.  Bugger.

I could not make udhcpd assign static addresses.  Nor could I make it manage two separate subnets (I have disabled the bridge and treat the LAN and WLAN as separate subnets).

repvik suggested using the dnsmasq DHCP server.  The version of dnsmasq built in OpenWRT still has the DHCP support included so all that is necessary to use it is to disable the startup of udhcpd and create an /etc/dnsmasq.conf containing dhcp parameters (see the dnsmasq man page).

For example, here is my /etc/dnsmasq.conf:

# DHCP on WLAN and LAN interfaces
dhcp-range=WLAN,192.168.1.150,192.168.1.199,3600
dhcp-range=LAN,192.168.0.100,192.168.0.150,28800
dhcp-leasefile=/tmp/dhcpd.leases
# Particular systems should end up with fixed addresses...
dhcp-host=00:40:36:01:a3:f3,tivo,infinite
dhcp-host=00:c0:df:01:c7:da,carrera,infinite
dhcp-host=00:0d:56:79:bf:d8,laptop

I also have an /etc/hosts which defines the three hostnames used the file (tivo, carrera and laptop).

Graham

With either of these solutions is it possible to stop clients who don't have a static entry from being assigned an IP? Like the deny unknown-clients option in ISC dhcp?

Alternatively has anyone tried building ISC dhcp for OpenWRT? or is it too big?

From the dnsmasq v2.13 manual

-F, --dhcp-range=[network-id,]<start-addr>,<end-addr>[[,<netmask>],<broadcast>][,<default lease time>]
...
The end address may be replaced by the keyword static which tells dnsmasq to enable DHCP for the network specified, but not to dynamically allocate               IP addresses.
Only hosts which have static addresses given via dhcp-host or from /etc/ethers will be served.
...

Don't know if it works on v2.11. Can you test it ?

--
Nico

that works fine, it just refuses to acknowledge clients who's mac address it doesn't know about.

Today I wanted to use udhcpd as it's small, but also wanted to have some static leases. So, after digging half internet i was lost - some say that it's possible, but no manuals. So - good old diving into the sources helped.

In udhcpd.conf add:

static_lease    00:16:B6:5E:4D:35       192.168.0.253

Btw, be careful, as error checking seems to be missing in udhcpd, but first segfault signalized me that i'm on right trails wink

The discussion might have continued from here.