DHCP 서버 구축

동적 호스트 구성 프로토콜(Dynamic Host Configuration Protocol, DHCP)은 호스트 IP 구성 관리를 단순화하는 IP 표준이다. 동적 호스트 구성 프로토콜 표준에서는 DHCP 서버를 사용하여 IP 주소 및 관련된 기타 구성 세부 정보를 네트워크의 DHCP 사용 클라이언트에게 동적으로 할당하는 방법을 제공한다.1 위키백과에서 발췌

학교 WiFi나, 집의 공유기, 당신이 사용하는 LTE 휴대폰 등이 인터넷을 하기 위해서는 모든 장비들은 IP를 가지고 있어야 한다. 하지만 학교건, 집이건 지하철 WiFi건 내 노트북 IP는 뭐지? 혹은 내 휴대폰 IP는 몇 번이지? 하고 고민 해본 기억은 없을 것이다. 이렇게 네트워크에 연결된 장비들에 자동으로 IP주소를 할당 해주는 것이 동적 호스트 설정 프로토콜, DHCP이고 이 역할을 하는 것이 DHCP 서버이다.
이름은 거창한 듯 하지만 설치, 설정 과정은 매우 쉽다.

설치

haedong@haedong:~:]$ sudo yum install -y dhcp*
...중략...
Package 12:dhcp-common-4.2.5-82.el7.centos.x86_64 already installed and latest version
Package 12:dhcp-libs-4.2.5-82.el7.centos.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
...중략...
====================================================================================================================================
 Package                      Arch                    Version                                   Repository                     Size
====================================================================================================================================
Installing:
 dhcp                         x86_64                  12:4.2.5-82.el7.centos                    local_centos                  515 k
 dhcp-devel                   x86_64                  12:4.2.5-82.el7.centos                    local_centos                  108 k
 dhcpd-pools                  x86_64                  3.1-1.el7                                 local-epel                     53 k
 dhcping                      x86_64                  1.2-13.el7                                local-epel                     18 k
Transaction Summary
====================================================================================================================================
Install  4 Packages
Total download size: 693 k
Installed size: 1.6 M
Downloading packages:
(1/4): dhcpd-pools-3.1-1.el7.x86_64.rpm                                                                      |  53 kB  00:00:00
...중략...
Installed:
  dhcp.x86_64 12:4.2.5-82.el7.centos         dhcp-devel.x86_64 12:4.2.5-82.el7.centos         dhcpd-pools.x86_64 0:3.1-1.el7
  dhcping.x86_64 0:1.2-13.el7
Complete!

설정
DHCP 서버 구성요소를 설치한 뒤 /etc/dhcp/dhcpd.conf 파일을 수정한다.

# 다음을 참고해서 수정 한다.
#subnet 사용할_IP_대역(netmask 범위에 따라 달라진다) netmask 사용할_netmask  {
#        range 동적으로_할당해_줄_IP_범위(클라이언트는_이_범위_안의_IP를_할당받는다);
#        option subnet-mask 클라이언트에서_설정하게_될_netmask ;
#        option routers 클라이언트에서_설정하게_될_gateway;
#        option broadcast-address 브로드캐스트_주소;
#        option domain-name-servers 첫_번째_DNS, 두_번째_DNS;
#        default-lease-time 기본_임대_시간(초);
#        max-lease-time 최대_임대_시간(초);
#}
subnet 192.168.0.0 netmask 255.255.255.0 {
        range 192.168.0.100 192.168.0.200;
        option subnet-mask 255.255.255.0;
        option routers 192.168.0.254;
        option broadcast-address 192.168.0.255;
        option domain-name-servers 8.8.8.8, 168.126.63.1;
        default-lease-time 7200;
        max-lease-time 36000;
}

구동

haedong@haedong:~:]$ sudo chkconfig dhcpd on
알림: 'systemctl enable dhcpd.service'에 요청을 전송하고 있습니다.
Created symlink from /etc/systemd/system/multi-user.target.wants/dhcpd.service to /usr/lib/systemd/system/dhcpd.service.
haedong@haedong:~:]$ sudo service dhcpd start
Redirecting to /bin/systemctl start dhcpd.service

YUM repository 구축 – online

폐쇄망, 사내 활용 등을 위한 yum repository를 구축한다.
local repository 구축과 특별히 다른 점은 없다. 단지 웹(http, https) 을 통한 접근을 허용하는 경로를 추가하는 것으로 구축이 가능하다.
웹 서버가 구축 되어있어야 한다.

http 디렉토리를 확인하고 그곳에 리포지터리 파일을 복사한다.

[root@class14 ~]# vi /etc/httpd/conf/httpd.conf
 # 다음 내용을 찾는다.
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"

#
# Relax access to content within /var/www.
#
<Directory "/var/www">
    AllowOverride None
    # Allow open access:
    Require all granted
</Directory>

생성한 repodata 디렉토리가 있는 디렉토리를 /var/www/html 에 복사한다.
이전 포스트에서 /home/repo-data/ 에 rpm 패키지를 넣고 repodata를 생성했었다.

[root@class14 ~]# cp -r /home/repo-data /var/www/html
 # 또는 심볼릭 링크를 만들어준다.
[root@class14 ~]# ln -s /home/repo-data /var/www/html/repo-data

repo 파일 생성
※ local repository에 대한 repo 파일을 만드는 것과 다르지 않다. url만 다를 뿐이다.

[centos:/home:]# vi /etc/yum.repos.d/haedongg_net.repo
 #여기부터 붙여넣기 한다.
[haedong_net-repo]
name=haedongg_net-repo
baseurl=http://www.haedongg.net/repo-data
 # createrepo 명령으로 생성된 repodata 가 있는 디렉토리를 지정한다.
 # http로 시작하는 것에 유의하자. 
enabled=1
gpgcheck=0

Apache http 서버 구축 – #1. 설치

HTTP 데몬(HTTP Daemon), 즉 httpd는 웹 서버의 백그라운드에서 실행되어, 들어오는 서버 요청을 대기하는 소프트웨어 프로그램이다. 이 데몬은 자동으로 요청에 응답하며 HTTP를 사용하여 인터넷을 경유, 하이퍼텍스트, 멀티미디어 문서들을 서비스한다. HTTPd는 HTTP daemon의 준말이다. (예: 웹 서버)

yum 명령으로 패키지를 설치한다.

[root@class14 ~]# yum install -y httpd
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
epel/x86_64/metalink                                                                                                                                                                | 2.8 kB  00:00:00
 * base: mirror.kakao.com
 base                                                                                                                                                                                | 3.6 kB  00:00:00
(1/7): base/7/x86_64/group_gz                                                                                                                                                       | 153 kB  00:00:00
중략
(7/7): epel/x86_64/primary_db                                                                                                                                                       | 6.9 MB  00:00:03
Resolving Dependencies
--> Running transaction check
중략
---> Package httpd.x86_64 0:2.4.6-93.el7.centos will be an update
--> Processing Dependency: httpd-tools = 2.4.6-93.el7.centos for package: httpd-2.4.6-93.el7.centos.x86_64
--> Running transaction check
---> Package httpd-devel.x86_64 0:2.4.6-80.el7.centos will be updated
중략--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================================================
 Package                                           Arch                                        Version                                                     Repository                                 Size
===========================================================================================================================================================================================================
Updating:
 httpd                                             x86_64                                      2.4.6-93.el7.centos                                         base                                      2.7 M
Updating for dependencies:
 httpd-devel                                       x86_64                                      2.4.6-93.el7.centos                                         중략
Transaction Summary
===========================================================================================================================================================================================================
Upgrade  1 Package (+4 Dependent packages)

Total download size: 4.4 M
Downloading packages:
No Presto metadata available for base
(1/5): httpd-devel-2.4.6-93.el7.centos.x86_64.rpm                                                                                                                                   | 198 kB  00:00:00
중략
(5/5): httpd-2.4.6-93.el7.centos.x86_64.rpm                                                                                                                                         | 2.7 MB  00:00:00
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                       19 MB/s | 4.4 MB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : httpd-tools-2.4.6-93.el7.centos.x86_64                                                                                                                                                 1/10
중략
  Verifying  : httpd-manual-2.4.6-80.el7.centos.noarch                                                                                                                                               10/10
Updated:
  httpd.x86_64 0:2.4.6-93.el7.centos
Dependency Updated:
  httpd-devel.x86_64 0:2.4.6-93.el7.centos           httpd-manual.noarch 0:2.4.6-93.el7.centos           httpd-tools.x86_64 0:2.4.6-93.el7.centos           mod_ssl.x86_64 1:2.4.6-93.el7.centos
Complete!
[root@class14 ~]# rpm -qa | grep httpd
httpd-manual-2.4.6-93.el7.centos.noarch
httpd-2.4.6-93.el7.centos.x86_64
httpd-tools-2.4.6-93.el7.centos.x86_64
httpd-devel-2.4.6-93.el7.centos.x86_64

서비스 구동

 # 별도의 설정 없이 구동을 하면 기본 값으로 실행된다.
[root@class14 ~]# service start httpd
Redirecting to /bin/systemctl start httpd.service
 # 또는
[root@class14 ~]# systemctl start httpd.service

서비스 구동 확인

[root@class14 ~]# netstat -nltp | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      2411/httpd
 # 또는
[root@class14 ~]# netstat -nltp | grep httpd
tcp6       0      0 :::80                   :::*                    LISTEN      2411/httpd
tcp6       0      0 :::443                  :::*                    LISTEN      2411/httpd
[root@class14 ~]#
웹브라우저로 접속 성공한 모습.

접속이 안될 경우
※ 다양한 원인이 있을 수 있으나 linux 방화벽 (iptables, firewalld)에 의해 막히는 경우가 많다.

[root@class14 ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
 # 또는
[root@class14 ~]# service iptables stop
 # CentOS6 이하, CentOS7 이상에서 firewalld 를 삭제하고 iptables를 구동 했을 때

YUM repository 구축 – local

이전 포스트에서 설명 한 것처럼 설정된 repository에서 패키지를 다운로드하고 설치하는데 도움을 준다.
이를 위해서는 언급 한 것과 같이 RPM패키지들과 이들 정보를 가진 repository가 필요하다.
일반적인 환경에서는 공용 repositoy (Kakao, naver, KAIST)등에서 제공하는 mirror 사이트를 이용하면 되지만, 폐쇠망 이나, 네트워크 상태가 좋지 않은 경우를 대비해 로컬(서버에 저장)이나, 내부망에 repository를 구축 할 수도 있다.

생각보다 구축 방법은 단순하다.
1. RPM패키지 파일 다운로드
2. repository 정보 생성
3. repo 파일 생성(구축된 repository 서버 정보 기록)
4. 네트워크 접근을 허용할 경우위한 http 서버 구축

로컬 리포지터리 생성

※CentOS7.8 (모든 패키지 포함) 미디어 파일을 이용한 구축의 예

필요 패키지 설치

 # repository 구축을 위한 필수 패키지 다운로드
[centos:/home:]# yum install createrepo yum-utils
Loaded plugins: fastestmirror, langpacks
중략
 * updates: mirror.kakao.com
base                                                                                                                                       | 3.6 kB  00:00:00
중략
(5/5): updates/7/x86_64/primary_db                                                                                                         | 4.5 MB  00:00:01

==================================================================================================================================================================
 Package                               Arch                               Version                                       Repository                           Size
==================================================================================================================================================================
Updating:
 yum-utils                             noarch                             1.1.31-54.el7_8                               updates                             122 k

Transaction Summary
==================================================================================================================================================================
Upgrade  1 Package
후략

설치미디어 파일 다운로드

 # 설치 미디어 파일 다운로드
[centos:/home:]#  wget http://mirror.navercorp.com/centos/7.8.2003/isos/x86_64/CentOS-7-x86_64-Everything-2003.iso

iso 파일 마운트

[centos:/home:]# mkdir /mnt/centos
[centos:/home:]# mount CentOS-7-x86_64-Everything-2003.iso /mnt/centos
mount: /dev/loop0 is write-protected, mounting read-only

repodata 생성

[centos:/home:]# mkdir /home/repo-data
 # 패키지 파일을 복사할 디렉토리 생성.
 # 마운트 한 ISO 파일 경로를 직접 지정할 수도 있지만, 이 경우 마운트 정보를 변경 해야 한다.
[centos:/home:]# cp /mnt/centos/Packages/*.rpm /home/repo-data/
 # 패키지 파일 복사 centos 7.8.2003 iso 기준으로 10070개 rpm 파일이 존재한다.

[centos:/home:]# createrepo /home/repo-data/
Spawning worker 0 with 2518 pkgs
Spawning worker 1 with 2518 pkgs
Spawning worker 2 with 2517 pkgs
Spawning worker 3 with 2517 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

repo 파일 생성

[centos:/home:]# vi /etc/yum.repos.d/local.repo
 #여기부터 붙여넣기 한다.
[haedongg_local-repo]
name=haedongg_local-repo
baseurl=file:////home/repo-data
 # createrepo 명령으로 생성된 repodata 가 있는 디렉토리를 지정한다.
enabled=1
gpgcheck=0