dhcpd - yusukew62/docs GitHub Wiki

dhcpd

dhcpサーバ設定

dhcpサーバのインストール

# yum install dhcp

dhcpd.confのサンプルコンフィグファイルをコピー

# cp -p /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/

172.16.1.x/24のネットワーク帯をDHCPで払い出すようにする
00:0C:29:79:90:9FのNICには固定で172.16.1.30を払い出す

# diff -wu dhcpd.conf.org dhcpd.conf
--- dhcpd.conf.org      2016-05-12 04:22:47.000000000 +0900
+++ dhcpd.conf  2017-02-24 04:53:54.645873392 +0900
@@ -3,3 +3,16 @@
 #   see /usr/share/doc/dhcp*/dhcpd.conf.sample
 #   see 'man 5 dhcpd.conf'
 #
+subnet 172.16.1.0 netmask 255.255.255.0 {
+    range 172.16.1.4 172.16.1.254;
+    default-lease-time 600;
+    max-lease-time 7200;
+    option routers 172.16.1.1;
+    option domain-name-servers 172.16.1.1;
+
+    host test {
+        hardware ethernet 00:0C:29:79:90:9F;
+        fixed-address 172.16.1.30;
+        option host-name "test";
+    }
+}

サービス起動、chkconfig設定

# service dhcpd start
# chkconfig dhcp on

dhcpクライアント設定

インタフェース設定ファイルの記述
eth1のインタフェースにDHCPでアドレスを割り当てる

# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=dhcp

eth1のインタフェースを立ち上げる

# ifup eth1

eth1 のIP情報を検出中... 完了。

eth1の情報を確認

# ifconfig eth1
eth1      Link encap:Ethernet  HWaddr 00:0C:29:79:90:9F
          inet addr:172.16.1.4  Bcast:172.16.1.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe79:909f/64 Scope:Link
          inet6 addr: 240b:12:2000:6300:20c:29ff:fe79:909f/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:11 errors:0 dropped:0 overruns:0 frame:0
          TX packets:11 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1838 (1.7 KiB)  TX bytes:1354 (1.3 KiB)

# ethtool eth1
Settings for eth1:
        Supported ports: [ TP ]
        Supported link modes:   1000baseT/Full
                                10000baseT/Full
        Supported pause frame use: No
        Supports auto-negotiation: No
        Advertised link modes:  Not reported
        Advertised pause frame use: No
        Advertised auto-negotiation: No
        Speed: 10000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: off
        MDI-X: Unknown
        Supports Wake-on: uag
        Wake-on: d
        Link detected: yes

ログ

サーバログ

DHCPリース情報
dhcpd.leasesにリース情報が記載されている

# cat /var/lib/dhcpd/dhcpd.leases
# The format of this file is documented in the dhcpd.leases(5) manual page.
# This lease file was written by isc-dhcp-4.1.1-P1

server-duid "\000\001\000\001 A\310Q\000\014)V\257\344";

lease 172.16.1.4 {
  starts 4 2017/02/23 16:29:27;
  ends 5 2017/02/24 04:29:27;
  cltt 4 2017/02/23 16:29:27;
  binding state active;
  next binding state free;
  hardware ethernet 00:0c:29:79:90:9f;
  client-hostname "test2";
}
lease 172.16.1.4 {
  starts 4 2017/02/23 16:29:27;
  ends 5 2017/02/24 04:29:27;
  cltt 4 2017/02/23 16:29:27;
  binding state active;
  next binding state free;
  hardware ethernet 00:0c:29:79:90:9f;
  client-hostname "test2";
}

DHCPクライアントへのIPアドレス払い出しログ

# cat /var/log/messages
Feb 24 01:29:26 dhcp01 dhcpd: DHCPDISCOVER from 00:0c:29:79:90:9f via eth1
Feb 24 01:29:27 dhcp01 dhcpd: DHCPOFFER on 172.16.1.4 to 00:0c:29:79:90:9f (test2) via eth1
Feb 24 01:29:27 dhcp01 dhcpd: DHCPREQUEST for 172.16.1.4 (172.16.1.3) from 00:0c:29:79:90:9f (test2) via eth1
Feb 24 01:29:27 dhcp01 dhcpd: DHCPACK on 172.16.1.4 to 00:0c:29:79:90:9f (test2) via eth1
Feb 24 01:29:27 dhcp01 dhcpd: DHCPREQUEST for 172.16.1.4 (172.16.1.3) from 00:0c:29:79:90:9f (test2) via eth0
Feb 24 01:29:27 dhcp01 dhcpd: DHCPACK on 172.16.1.4 to 00:0c:29:79:90:9f (test2) via eth0

リース期間延長のレスポンス

# cat /var/log/messages
Feb 24 03:19:30 dhcp01 dhcpd: DHCPREQUEST for 172.16.1.4 from 00:0c:29:79:90:9f (test2) via eth1
Feb 24 03:19:30 dhcp01 dhcpd: DHCPACK on 172.16.1.4 to 00:0c:29:79:90:9f (test2) via eth1

固定IP払い出しレスポンス

# cat /var/log/messages
Feb 24 04:49:49 dhcp01 dhcpd: Dynamic and static leases present for 172.16.1.10.
Feb 24 04:49:49 dhcp01 dhcpd: Remove host declaration test2 or remove 172.16.1.10
Feb 24 04:49:49 dhcp01 dhcpd: from the dynamic address pool for 172.16.1.0/24
Feb 24 04:49:49 dhcp01 dhcpd: DHCPREQUEST for 172.16.1.10 from 00:0c:29:79:90:9f via eth1
Feb 24 04:49:49 dhcp01 dhcpd: DHCPACK on 172.16.1.10 to 00:0c:29:79:90:9f via eth1

クライアントログ

DHCPサーバへのIPアドレス払い出し依頼ログ

# cat /var/log/messages
Feb 24 01:29:25 test2 dhclient[65429]: DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 3 (xid=0x1711051c)
Feb 24 01:29:25 test2 dhclient[65429]: DHCPOFFER from 172.16.1.3
Feb 24 01:29:25 test2 dhclient[65429]: DHCPREQUEST on eth1 to 255.255.255.255 port 67 (xid=0x1711051c)
Feb 24 01:29:25 test2 dhclient[65429]: DHCPNAK from 192.168.1.1 (xid=0x1711051c)
Feb 24 01:29:25 test2 dhclient[65429]: DHCPACK from 172.16.1.3 (xid=0x1711051c)
Feb 24 01:29:27 test2 NET[65474]: /sbin/dhclient-script : updated /etc/resolv.conf
Feb 24 01:29:27 test2 dhclient[65429]: bound to 172.16.1.4 -- renewal in 19069 seconds.

リース期間延長のリクエスト

# cat /var/log/messages
Feb 24 03:19:29 test2 dhclient[66083]: DHCPREQUEST on eth1 to 172.16.1.3 port 67 (xid=0x6c193061)
Feb 24 03:19:29 test2 dhclient[66083]: DHCPACK from 172.16.1.3 (xid=0x6c193061)

DHCPサーバからのDNSサーバ名取得
/sbin/dhclient-scriptで生成されたと記載

# cat /var/log/messages
Feb 24 04:53:32 test2 NET[3972]: /sbin/dhclient-script : updated /etc/resolv.conf

# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
nameserver 172.16.1.1

参考