在CentOS系统中,通常使用dnsmasq或isc-dhcp-server作为DHCP服务器。以下是如何为CentOS DHCP添加静态IP的步骤:
使用 dnsmasq
-
安装
dnsmasq:sudo yum install dnsmasq -
配置
dnsmasq:
编辑/etc/dnsmasq.conf文件,添加以下内容:interface=eth0 # 替换为你的网络接口名称 dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,12h dhcp-host=192.168.1.101,client-hostname,"hostname" # 添加静态IP -
重启
dnsmasq:sudo systemctl restart dnsmasq
使用 isc-dhcp-server
-
安装
isc-dhcp-server:sudo yum install isc-dhcp-server -
配置
isc-dhcp-server:
编辑/etc/dhcp/dhcpd.conf文件,添加以下内容:subnet 192.168.1.0 netmask 255.255.255.0 { range 192.168.1.100 192.168.1.200; option routers 192.168.1.1; option subnet-mask 255.255.255.0; option domain-name-servers 8.8.8.8, 8.8.4.4; } host client-hostname { hardware ethernet 00:11:22:33:44:55; # 替换为客户端的MAC地址 fixed-address 192.168.1.101; } -
配置网络接口:
编辑/etc/sysconfig/dhcpd文件,设置INTERFACESv4参数:INTERFACESv4="eth0" # 替换为你的网络接口名称 -
启动
isc-dhcp-server:sudo systemctl start dhcpd -
设置开机自启动:
sudo systemctl enable dhcpd
验证配置
无论使用哪种方法,都可以通过以下命令验证DHCP服务器是否正常工作:
sudo systemctl status dnsmasq # 如果使用dnsmasq
# 或者
sudo systemctl status dhcpd # 如果使用isc-dhcp-server
同时,可以通过客户端设备连接到DHCP服务器并检查分配的IP地址是否正确。
通过以上步骤,你可以在CentOS系统中为DHCP添加静态IP。