Assigning a fixed IP address to a machine in a DHCP network
I want to assign a fixed private IP address to a server so that local computers can always access it.
Currently, the DHCP address of the server is something like 192.168.1.66
.
Should I simply assign the server this same IP as fixed and configure the router so that it will exclude this IP from the ones available for DHCP?
Or are there some ranges of IP that are traditionally reserved for static addresses?
My beginner's question doesn't relate to commands but to general principles and good practices.
Practical case (Edit 1 of 2)
Thank you for the many good answers, especially the very detailed one from Liam.
I could access the router's configuration.
Router's overview panel:
========================
Connectivity type is set to DHCP and PPoE.
(...)
Network panel
=============
IPv4 address distribution (DHCP)
--------------------------------
Enable DHCP on LAN : Off
DHCP range starts at IP address : 192.168.1.33
DHCP range ends at IP address : 192.168.1.35
(...)
Nota bene: There is also an IPv6 section.
When booting any computer, it obtains its IPv4 address in DHCP.
The IP and the MAC addresses that I can see with the ipconfig all
command in Windows match those in the list of connected devices that the router displays, so that I can confirm who is who.
The list of connected devices is something like
Description IP address MAC address
«Unknown» 192.168.1.xx (static) 01:02:03:04:05:06
«Unknown» 192.168.1.yy (static) 07:08:09:10:11:12
Things that I don't understand:
- Although all IP addresses are all obtained in DCHP, they are displayed as by the router as if they are static addresses.
- The router's setting "Enable DHCP on LAN" is set on "Off" but the IP addresses are obtained in DHCP.
- IP addresses attributed to the computers are outside of the very narrow
DHCP range of
192.168.1.33
to192.68.1.35
On any Windows computer connected in DCHP, ipconfig /all
shows something like:
IPv4 Address ........ 192.168.1.xx (preferred)
Default Gateway ........ 192.168.1.1 (= IP of the router)
DHCP server ............ 192.168.1.5
I'm missing something, but what?
Practical case (Edit 2 of 2)
Solution found.
For details, see my answer to Michal's comment at the bottom of this message.
I must admit that the way the router display things keeps some parts a mystery.
The router seems to be using DHCP by default, but remembers the devices that were connected to it (probably using their mac address). It could be the reason why it lists the IPs as static although they're dynamic. There was also Cisco router at 192.168.1.4
which appeared for some business communications service, but I had no credentials to access it.
Determine the IP address that is assigned to your server and then go onto the DHCP and set a DHCP reservation for that server.
DHCP services differ across many possible implementations, and there are no ranges of IP that are traditionally reserved for static addresses; it depends what is configured in your environment. I'll assume we're looking at a typical home / SOHO setup since you mention your router is providing the DHCP service.
Should I simply assign the server this same IP as fixed and configure the router so that it will exclude this IP from the ones available for DHCP?
I would say that is not best practice. Many consumer routers will not have the ability to exclude a single address from within the DHCP range of addresses for lease (known as a 'pool'). In addition, because DHCP is not aware that you have "fixed" the IP address at the server you run the risk of a conflict. You would normally either:
- set a reservation in DHCP configuration so that the server device is always allocated the same address by the DHCP service, or
- set the server device with a static address that is outside the pool of addresses allocated by the DHCP service.
To expand on these options:
Reservation in DHCP
If your router allows reservations, then the first, DHCP reservation option effectively achieves what you have planned. Note the significant difference: address assignment is still managed by the DHCP service, not "fixed" on the server. The server still requests a DHCP address, it just gets the same one every time.
Static IP address
If you prefer to set a static address, you should check your router's (default) configuration to determine the block of addresses used for DHCP leases. You will normally be able to see the configuration as a first address and last address, or first address and a maximum number of clients. Once you know this, you can pick a static address for your server.
An example would be: the router is set to allow a maximum of 128 DHCP clients with a first DHCP IP address of 192.168.1.32. Therefore a device could be assigned any address from 192.168.1.32 up to and including 192.168.1.159. Your router will use a static address outside this range (generally the first or last address .1 or .254) and you can now pick any other available address for your server.
TL;DR
It depends on the configuration of your DHCP service. Check the settings available to you for DHCP then either reserve an address in DHCP or pick a static address that is not used by DHCP - don't cross the streams.
It's not a bad habit to divide your subnet to DHCP pool range and static ranges, but of course you can do what JohnA wrote - use reservation for your server, but first case is IMHO clearer, because you are not messing up your DHCP server with unused extra settings (it could be confusing then for another admins who are not aware of that the server is static). if using DHCP pool + static pool, then just don't forget to add your static server to DNS (create A/AAAA record for it).