waterloo3122 / open-source-docs

Apache License 2.0
0 stars 0 forks source link

Centos7 install and config DHCP server #100

Open waterloo3122 opened 5 years ago

waterloo3122 commented 5 years ago

1 install

yum install dhcp

2 configure

cat /etc/dhcp/dhcpd.conf

log-facility local7;
subnet 192.168.2.0 netmask 255.255.255.0 {
        range 192.168.2.11 192.168.2.239;
        option domain-name-servers 192.168.2.254;
        option domain-name "ceph-in.tk";
        option routers 192.168.2.254;
        option broadcast-address 192.168.2.255;
        default-lease-time 3600;
        max-lease-time 7200;
 }

systemctl start dhcpd.service

systemctl enable dhcpd.service

3 指定监听的网卡 specify nics listened on

cp /usr/lib/systemd/system/dhcpd.service /etc/systemd/system/

vim /etc/systemd/system/dhcpd.service add your interface names to ExecStart ExecStart=/usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhcpd --no-pid your_interface_name(s)

systemctl --system daemon-reload systemctl restart dhcpd

4 log to /var/log/dhcpd.log

vim /etc/rsyslog.conf I have change local7.* /var/log/boot.log to local7.* /var/log/dhcpd.log

systemctl stop rsyslog 
systemctl start rsyslog 
systemctl stop dhpcd
systemctl start dhpcd

5 check logs

tailf /var/log/messages tailf /var/log/dhcpd.log

6 reference

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/sec-dhcp-configuring-server

waterloo3122 commented 5 years ago

get hostname via dhcp server

修改dhcpd.conf

cat /etc/dhcp/dhcpd.conf

log-facility local7;

subnet 192.168.2.0 netmask 255.255.255.0 {
        range 192.168.2.11 192.168.2.239;
        option domain-name-servers 192.168.2.254;
        option domain-name "ceph-in.tk";
        option routers 192.168.2.254;
        option broadcast-address 192.168.2.255;
        default-lease-time 3600;
        max-lease-time 7200;
        # node0
        host node0 {
                hardware ethernet FA:2E:CD:7A:69:94;
                fixed-address 192.168.2.14;
                option host-name "node0";
                }
        # Ceph-testbed
        host testbed {
                hardware ethernet EE:7C:2B:7E:CA:AD;
                fixed-address 192.168.2.11;
                option host-name "testbed";
                }
}

下面这步骤貌似可以不用

echo unset old_host_name > /etc/dhcp/dhclient-enter-hooks.d/unset_old_hostname

清空/etc/hostname, 因为/etc/hostname seems to has prority over dhcp answer so leave it empty

> /etc/hostname

reboot

reference

https://askubuntu.com/questions/104918/how-to-get-the-hostname-from-a-dhcp-server