在CentOS系統中配置DHCP中繼代理,可以讓你將DHCP請求從一個子網轉發到另一個子網的DHCP服務器。以下是詳細的步驟:
CentOS默認不包含DHCP中繼代理軟件包,你需要手動安裝它??梢允褂靡韵旅顏戆惭b:
sudo yum install dhcp-relay
安裝完成后,你需要配置DHCP中繼代理。編輯/etc/sysconfig/dhcp-relay文件:
sudo vi /etc/sysconfig/dhcp-relay
在文件中添加或修改以下內容:
# DHCP Relay configuration file
# List of relay agents to start.
# Format: RELAYAGENT=interface[,interface]...
RELAYAGENT=eth0
# IP address of the DHCP server to relay requests to.
# Format: SERVER=IP_ADDRESS
SERVER=192.168.1.100
# IP address of the DHCP server to relay requests to (for IPv6).
# Format: SERVER=IP_ADDRESS
#SERVER=fe80::1
# List of options to pass to the DHCP server.
# Format: OPTION=option,value
OPTION=router,192.168.1.1
OPTION=dns-server,192.168.1.2
OPTION=domain-name-servers,192.168.1.2
# List of interfaces to listen on.
# Format: LISTEN=interface[,interface]...
LISTEN=eth0
# List of interfaces to ignore.
# Format: IGNORE=interface[,interface]...
IGNORE=lo
配置完成后,啟動并啟用DHCP中繼代理服務:
sudo systemctl start dhcp-relay
sudo systemctl enable dhcp-relay
你可以使用tcpdump或wireshark來驗證DHCP請求是否被正確轉發到DHCP服務器。
sudo tcpdump -i eth0 port 67 or port 68
eth0)。如果你有防火墻規則,確保允許DHCP請求通過。例如,使用firewalld:
sudo firewall-cmd --permanent --add-service=dhcp
sudo firewall-cmd --reload
如果SELinux處于 enforcing 模式,你可能需要配置SELinux策略以允許DHCP中繼代理正常工作。你可以臨時將SELinux設置為 permissive 模式來測試:
sudo setenforce 0
如果一切正常,你可以創建一個自定義的SELinux策略模塊來永久允許DHCP中繼代理。
通過以上步驟,你應該能夠在CentOS系統中成功配置DHCP中繼代理。