大网数据广告活动
服务器运维问答

Assigning a fixed IP address to a machine in a DHCP network

· 52CE 我爱测

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 fi…

问题原文

原帖链接 · OuzoPower · CC BY-SA 4.0

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 to 192.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.

社区高分解答

原帖链接 · Liam · CC BY-SA 3.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-04-04)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。