dhcpdのインストール方法

DHCPサーバであるdhcpdのインストール方法をまとめました。

MACアドレス52:54:00:2c:c8:b9のマシンに対し、IPアドレス192.168.11.251を配布します。

デフォルトゲートウェイとDNSは192.168.11.1のマシンを使います。


1 Fedora 22

$ sudo dnf install -y dhcp-server
$ sudo su -c 'cat << EOF >> /etc/dhcp/dhcpd.conf
subnet 192.168.11.0 netmask 255.255.255.0 {
  option domain-name-servers 192.168.11.1;
  option routers 192.168.11.1;
  host test {
    hardware ethernet 52:54:00:2c:c8:b9;
    fixed-address 192.168.11.251;
  }
}
EOF'
$ sudo systemctl enable dhcpd.service
$ sudo systemctl start dhcpd.service

2 CentOS 7

$ sudo yum install -y dhcp
$ sudo su -c 'cat << EOF >> /etc/dhcp/dhcpd.conf
subnet 192.168.11.0 netmask 255.255.255.0 {
  option domain-name-servers 192.168.11.1;
  option routers 192.168.11.1;
  host test {
    hardware ethernet 52:54:00:2c:c8:b9;
    fixed-address 192.168.11.251;
  }
}
EOF'
$ sudo systemctl enable dhcpd.service
$ sudo systemctl start dhcpd.service

3 Debian 8

$ sudo apt-get install -y isc-dhcp-server
$ sudo su -c 'cat << EOF >> /etc/dhcp/dhcpd.conf
subnet 192.168.11.0 netmask 255.255.255.0 {
  option domain-name-servers 192.168.11.1;
  option routers 192.168.11.1;
  host test {
    hardware ethernet 52:54:00:2c:c8:b9;
    fixed-address 192.168.11.251;
  }
}
EOF'
$ sudo sed -i -e 's/$INTERFACES=""/INTERFACES="eth0"/g' \
/etc/default/isc-dhcp-server
$ sudo systemctl enable isc-dhcp-server.service
$ sudo systemctl start isc-dhcp-server.service

4 Ubuntu 14.04

sysv-rc-confでisc-dhcp-serverをUbuntu 14.04起動時に動作するようにします。

$ sudo apt-get install -y isc-dhcp-server
$ sudo su -c 'cat << EOF >> /etc/dhcp/dhcpd.conf
subnet 192.168.11.0 netmask 255.255.255.0 {
  option domain-name-servers 192.168.11.1;
  option routers 192.168.11.1;
  host test {
    hardware ethernet 52:54:00:2c:c8:b9;
    fixed-address 192.168.11.251;
  }
}
EOF'
$ sudo sed -i -e 's/$INTERFACES=""/INTERFACES="eth0"/g' \
/etc/default/isc-dhcp-server
$ sudo apt-get install -y sysv-rc-conf
$ sudo sysv-rc-conf isc-dhcp-server on
$ sudo /etc/init.d/isc-dhcp-server start