In a router , you can create and configure multiple DHCP pools each one with its own default route and dns server . And because the DHCP pool configuration is not specific to an interface in a router, I want to understand from which pool a device will pick its IP address . Is it random ? Or is it based on the address used by device to connect to the DHCP server ?
While configuring DHCP pool " default gateway information is configured for example
Switch(config) ip DHCP pool vlan30
Switch(config)# network 192.168.10.0 255.255.255.0
Switch(config)#ip default gateway 192.168.10.1
This last command tell the device to allocate ips from this DHCP scope for pc using default gateway 192.168.10.1
I believe pool is chosen by the incoming interface of the router or DHCP relay. Router match pool which addresses are matching incoming interface network/netmask. Several pools on a router(R1) may not be tied to R1 interfaces because DHCP packet can be received through router/DHCP relay(R2). In that case relayed packet will also have a field of incoming interface of R2 and R1 will do same choosing.
On a DHCP server (which may be integrated in a router), you can configure multiple scopes with one or more address pools each. Each scope matches a local interface subnet or is used with a relay, which in turn is used for address matching (per option 82, sometimes policies are used).
DHCP options like DNS server and routers are usually configured on a scope (or globally), not on an address pool (hence server options and scope options).
Scope matching is unambiguous for a server. When there are multiple address pools in a scope, the server selects from any one of them at will.
You've actually complicated matters somewhat by making a few incorrect statements so I'll pick through your question on an individual basis.
In a router , you can create and configure multiple DHCP pools each one with its own default route
- DHCP pools will not have a default 'route'. The DHCP server will communicate a default 'gateway' to clients which I believe is what you meant. That default gateway can be the router itself (usually the IP interface that the router has within the subnet that the pool is intended for) or the gateway provided could be another IP address or even another device. For example, a Windows Server acting as a DHCP server may advise clients that the default gateway is a router IP address.
and dns server.
- DHCP pools do not have their own DNS server. DHCP and DNS are two different services. A DHCP pool will generally advise clients what DNS server to use, though. That may be the same device providing the DHCP pool (e.g. a router) in which case that router is acting as a DNS proxy as well as a DHCP server. Alternatively, clients could be advised to use a different DNS server - this could even be an external DNS server e.g. 18.104.22.168 at Google.
And because the DHCP pool configuration is not specific to an interface in a router
- Yes it is. Generally speaking, a single device (e.g. a router) will provide one DHCP pool per subnet and in turn the router will have one IP address (interface) within that subnet.
I want to understand from which pool a device will pick its IP address
- The 'correct' configuration would normally be for a router to have one DHCP pool per subnet which in turn would have a VLAN assignment and therefore client devices will obtain an IP address from the DHCP pool assigned to the VLAN that they are connected to.
The only times that you are likely to see multiple DHCP pools within the same subnet (sequentially, not overlapping) is where resiliency for DHCP assignment is desired.
For example, you could have two different Windows Server DHCP servers providing IP addresses on the same subnet, one providing 192.168.1.100-150 and the other providing 192.168.151-200 just as an example. That way clients can still obtain an address if one is offline.
- Is it random ? No. You'll find networking isn't a random science.
- Or is it based on the address used by device to connect to the DHCP server ? No, because you've created a chicken-or-the-egg paradox here. If the DHCP assignment was based on the device address, how would the device have an address if it hadn't talked to the DHCP server yet? DHCP pool allocation is based on these things:
- Client device communicates on a VLAN.
- DHCP pool is available on the SUBNET associated with that VLAN.
- DHCP scope/pool has been created for that SUBNET on the DHCP server.
- DHCP server has an IP interface on that SUBNET that is able to communicate via a physical interface to the VLAN of the client device in question.