별의 공부 블로그 🧑🏻‍💻
728x90
728x170

DHCP 서버 설정 (dhcpd.conf)

DHCP 서버

  • 클라이언트에게 자동으로 IP 주소, Gateway 주소, Name Server 주소 등을 할당 해주는 서버
  • 보통 가정에서 ISP(Internet Service Provider) 업체를 통해 인터넷 서비스를 이용하는 경우에 기본적으로 사용되고 있다.
  • IPv4 체계의 IP 주소 고갈 문제를 해결할 수 있다. 
  • 하나의 인터넷 회선을 공유하는 매스커레이드 환경에서 자동으로 클라이언트에게 IP 주소를 할당해 줄 수 있다.
  • 하드 디스크가 없는 원격 호스트에서 이더넷 카드로 부팅할 때 사용할 수 있다.

 

문제 해결 전략

  • DHCP 서버 설정 파일의 내용을 채우는 문제가 출제된다.
  • DHCP 서버는 dhcp 라는 이름으로 설치되므로, 'rpm -ql dhcp' 명령으로 관련 파일을 검색한다.
    • 'rpm -qc dhcp' 명령으로 주요 환경 설정 파일의 위치를 찾는다.
더보기
  • 관련 파일 검색하기
$ rpm -ql dhcp
/etc/NetworkManager
/etc/NetworkManager/dispatcher.d
/etc/NetworkManager/dispatcher.d/12-dhcpd
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/dhcp/scripts
/etc/dhcp/scripts/README.scripts
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/usr/bin/omshell
/usr/lib/systemd/system/dhcpd.service
/usr/lib/systemd/system/dhcpd6.service
/usr/lib/systemd/system/dhcrelay.service
/usr/sbin/dhcpd
/usr/sbin/dhcrelay
/usr/share/doc/dhcp-4.2.5
/usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
/usr/share/doc/dhcp-4.2.5/dhcpd6.conf.example
/usr/share/doc/dhcp-4.2.5/ldap
/usr/share/doc/dhcp-4.2.5/ldap/README.ldap
/usr/share/doc/dhcp-4.2.5/ldap/dhcp.schema
/usr/share/doc/dhcp-4.2.5/ldap/dhcpd-conf-to-ldap
/usr/share/man/man1/omshell.1.gz
/usr/share/man/man5/dhcpd.conf.5.gz
/usr/share/man/man5/dhcpd.leases.5.gz
/usr/share/man/man8/dhcpd.8.gz
/usr/share/man/man8/dhcrelay.8.gz
/usr/share/systemtap/tapset/dhcpd.stp
/var/lib/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

 

  • 관련 환경설정 파일 검색하기
$ rpm -qc dhcp
/etc/dhcp/dhcpd.conf
/etc/dhcp/dhcpd6.conf
/etc/openldap/schema/dhcp.schema
/etc/sysconfig/dhcpd
/var/lib/dhcpd/dhcpd.leases
/var/lib/dhcpd/dhcpd6.leases

 

  • DHCP의 환경 설정 파일은 /etc/dhcp/dhcpd.conf 이며, 안의 내용을 살펴보면 /usr/share/doc/dhcp*/dhcpd.conf 파일이나 'man 5 dhcpd.conf' 를 실행하라는 문구를 확인할 수 있다.
더보기
$ cat /etc/dhcp/dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.example
#   see dhcpd.conf(5) man page
#

 

$ man 5 dhcpd.conf

 

  • 설정과 관련된 내용은 /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example(또는 .sample) 에서 확인할 수 있다.
더보기
$ cat /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#

# option definitions common to all supported networks...
option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

default-lease-time 600;
max-lease-time 7200;

# Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none;

# If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative;

# Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection).
log-facility local7;

# No service will be given on this subnet, but declaring it helps the 
# DHCP server to understand the network topology.

subnet 10.152.187.0 netmask 255.255.255.0 {
}

# This is a very basic subnet declaration.

subnet 10.254.239.0 netmask 255.255.255.224 {
  range 10.254.239.10 10.254.239.20;
  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
}

# This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend.

subnet 10.254.239.32 netmask 255.255.255.224 {
  range dynamic-bootp 10.254.239.40 10.254.239.60;
  option broadcast-address 10.254.239.31;
  option routers rtr-239-32-1.example.org;
}

# A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {
  range 10.5.5.26 10.5.5.30;
  option domain-name-servers ns1.internal.example.org;
  option domain-name "internal.example.org";
  option routers 10.5.5.1;
  option broadcast-address 10.5.5.31;
  default-lease-time 600;
  max-lease-time 7200;
}

# Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.

host passacaglia {
  hardware ethernet 0:0:c0:5d:bd:95;
  filename "vmunix.passacaglia";
  server-name "toccata.fugue.com";
}

# Fixed IP addresses can also be specified for hosts.   These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host fantasia {
  hardware ethernet 08:00:07:26:c0:a5;
  fixed-address fantasia.fugue.com;
}

# You can declare a class of clients and then do address allocation
# based on that.   The example below shows a case where all clients
# in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet.

class "foo" {
  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
}

shared-network 224-29 {
  subnet 10.17.224.0 netmask 255.255.255.0 {
    option routers rtr-224.example.org;
  }
  subnet 10.0.29.0 netmask 255.255.255.0 {
    option routers rtr-29.example.org;
  }
  pool {
    allow members of "foo";
    range 10.17.224.10 10.17.224.250;
  }
  pool {
    deny members of "foo";
    range 10.0.29.10 10.0.29.230;
  }
}

 

문제 유형

① DHCP 클라이언트에게 할당되는 옵션(option) 입력하기

  • 설정과 관련된 내용은 /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example(또는 .sample) 에서 확인할 수 있다.
option 내용
routers 게이트웨이를 지정할 때 사용
subnet-mask 서브넷 마스크를 지정할 때 사용
domain-name 도메인 네임을 지정할 때 사용
domain-name-servers 도메인 네임 서버 IP 주소를 지정할 때 사용
broadcast-address 브로드캐스트 주소를 지정할 때 사용

 

subnet 192.168.1.0 netmask 255.255.255.0 {
    range 192.168.1.2 192.168.1.254
    option routers 192.168.0.1
    option subnet-mask 255.255.255.0
    option domain-name "starrykss.org";
    option domain-name-servers ns1.starrykss.org;
    option routers 192.168.1.1;
    option broadcast-address 192.168.1.255;
    default-lease-time 600;
    max-lease-time 7200;
}

 

  • 기타 항목
항목 내용
default-lease-time - 임대를 요청하는 클라이언트가 특정한 만료 시간을 요청하지 않았을 경우에 할당되는 시간
- 단위 : 초(Second)
max-lease-time - 임대를 요청한 클라이언트가 IP 주소를 가지고 있을 수 있는 최대 시간
- 단위 : 초(Second)
- Dynamic Bootp 는 적용받지 않음.

 

ddns-update-style none;
subnet 192.168.100.0 netmask 255.255.255.0 {
(  range  ) 192.168.100.101 192.168.100.199;
option (  domain_name_servers  ) ns.linuxmaster.org;
option (  domain-name  ) "linuxmaster.org";
option (  routers  ) 192.168.100.254;
default-lease-time 3600;
max-lease-time 7200;

 

 

② MAC 주소 지정하기

예제 : 맥(MAC) 주소 가 08:00:07:26:c0:a5l 인 시스템에는 192.168.1.22번 IP 주소를 할당하시오.
  • man 5 dhcpd.conf 명령어를 입력하면 설정하는 방법을 예시를 통해 확인할 수 있다.
host starrykss_pc {
    hardware ethernet 08:00:07:26:c0:a5l
    fixed-address 192.168.1.22;
}

 

728x90
그리드형(광고전용)
⚠️AdBlock이 감지되었습니다. 원할한 페이지 표시를 위해 AdBlock을 꺼주세요.⚠️
starrykss
starrykss
별의 공부 블로그 🧑🏻‍💻


📖 Contents 📖