반응형

설명

CentOS8에서 Grafana와 Prometheus, Node exporter 등을 설치하여 모니터링을 구성해 보겠습니다. 설치로 들어가기 전에 잠깐 아래 Grafana에서 제공된 이미지를 보면, Grafana와 Prometheus, Node exporter의 관계를 이해할수 있습니다. 조금 단순화해보면, Node에서 수집한 각종 자료를 Prometheus가 저장하고, 이렇게 저장된 자료들을 Web UI인 Grafana에서 보고 모니터링을 할수 있습니다.

 

설치 환경

  • OS: VirtualBox VM (4 cores)
  • RAM: 8GB
  • HDD: 50GB
  • IP Address: 192.168.56.153

 

SELinux 비활성화

이 페이지에서 SELinux는 다루지 않으므로 비활성화 하겠습니다.

[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

 

 

Firewall

Firewall에 Grafana와 Prometheus는 서비스 항목이 있어서 바로 등록이 가능하지만, Node exporter는 별도 서비스를 생성해서 등록해야만 합니다. Grafana의 서비스 포트는 3000번이며 Prometheus는 9090번, Node exporter는 9100번을 사용합니다.

### Firewall에 Grafana 서비스 추가 ###
[root@localhost ~]# firewall-cmd --permanent --add-service=grafana
success

### Firewall에 Prometheus 서비스 추가 ###
[root@localhost ~]# firewall-cmd --permanent --add-service=prometheus
success


### Firewall에 Node exporter를 신규 서비스로 등록  ###
[root@localhost ~]# firewall-cmd --permanent --new-service=node_exporter
success

### Firewall에 Node exporter의 포트정보 등록  ###
[root@localhost ~]# firewall-cmd --permanent --service=node_exporter --add-port=9100/tcp
success


### Firewall에 Node exporter 서비스 추가 ###
[root@localhost ~]# firewall-cmd --permanent --add-service=node_exporter
success

### Firewall에 적용 ###
[root@localhost ~]# firewall-cmd --reload
success

### Firewall에서 적용상태 확인 ###
[root@localhost ~]# firewall-cmd --list-services
cockpit dhcpv6-client grafana node_exporter prometheus ssh

 

 

Repository

Grafana와 Prometheus/Node exporter의 Repository를 별도 구성합니다. Grafana의 경우 CentOS8에서도 패지키를 제공하지만, Grafana에서 제공하는 패키지 업데이트가 빠르기 때문에 별도로 구성하는 것이 좋습니다.

### Grafana Repository 추가 ###
[root@localhost ~]# echo -e "\
[grafana]
name=grafana
baseurl=https://packages.grafana.com/oss/rpm
repo_gpgcheck=1
enabled=1
gpgcheck=1
gpgkey=https://packages.grafana.com/gpg.key
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
" >> /etc/yum.repos.d/grafana.repo

 

### Prometheus/Node exporter Repository 추가 ###
[root@localhost ~]# echo -e "\
[prometheus]
name=prometheus
baseurl=https://packagecloud.io/prometheus-rpm/release/el/\$releasever/\$basearch
repo_gpgcheck=1
enabled=1
gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkey
       https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm
gpgcheck=1
metadata_expire=300
" >> /etc/yum.repos.d/prometheus.repo

 

 

패키지 설치

Grafana Repository 추가가 완료되었다면, Grafana 패키지를 설치합니다.

### Grafana 패키지 설치 ###
[root@localhost ~]# dnf -y install grafana node_exporter prometheus2

 

 

서비스 활성화 및 시작

Grafana와 Prometheus, Node exporter 등의 패키지 설치가 완료되었다면, 서비스를 활성화 시킨후 시작합니다. 서비스 시작후에 상태를 확인하여 서비스에 문제가 없는지까지 확인합니다.

### 자동시작을 위해 서비스 등록 ###
[root@localhost ~]# systemctl enable grafana-server node_exporter prometheus
Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service...
Created symlink /etc/systemd/system/multi-user.target.wants/node_exporter.service...
Created symlink /etc/systemd/system/multi-user.target.wants/prometheus.service...

### 서비스 활성화 ###
[root@localhost ~]# systemctl start grafana-server node_exporter prometheus

### 활성화된 서비스 확인 ###
[root@localhost ~]# systemctl systemctl status grafana-server node_exporter prometheus --no-pager
● grafana-server.service - Grafana instance
   Loaded: loaded (/usr/lib/systemd/system/grafana-server.service; enabled; vendor preset: disabled)
   Active: active (running) since ...
...
● node_exporter.service - Prometheus exporter for machine metrics, written in Go with pluggable metric collectors.
   Loaded: loaded (/usr/lib/systemd/system/node_exporter.service; enabled; vendor preset: disabled)
   Active: active (running) since ...
...
● prometheus.service - The Prometheus monitoring system and time series database.
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since ...

서비스가 정상적으로 시작되었다면, 아래와 같이 서비스 포트가 정상적으로 열려 있는지 확인합니다.

### Grafana/Prometheus/Node exporter 등의 서비스 포트 확인 ###
[root@localhost ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      955/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      955/sshd
tcp6       0      0 :::3000                 :::*                    LISTEN      2302/grafana-server
tcp6       0      0 :::9090                 :::*                    LISTEN      2304/prometheus
tcp6       0      0 :::9100                 :::*                    LISTEN      2303/node_exporter

 

 

Grafana와 Prometheus 연결

「http://IP:3000」 로 접속합니다. 초기 로그인 정보는 admin/admin입니다. 로그인이 정상적으로 이루어지면 바로 패스워드를 변경할수 화면으로 이동되므로, 새로운 패스워드로 변경합니다.

로그인후, 좌측 메뉴에서 Configuration > Data sources > Add data source > Prometheus 순으로 이동합니다.

HTTP의 URL 항목에서 Prometheus에 접속할수 있는 「http://IP:9090」 형식의 URL을 입력합니다.

페이지 하단에 있는 「Save & test」 버튼을 클릭하여 「Data source is working」 메세지가 출력되는지 확인합니다. 이 메세지가 출력되었다면, Grafana와 Prometheus가 정상적으로 연결되었음을 의미합니다.

브라우저에서 「http://IP:9090」과 같은 URL을 입력하면 별도로 Prometheus에 접속할수도 있습니다.

 

 

Prometheus와 Node exporter 연결

Prometheus와 Node exporter의 연결은 Prometheus의 환경 파일에 Node exporter의 정보를 기입하는 것으로 가능합니다. 「job_name: "node_exporter"」와 같이 별도의 「job」을 생성하고 Prometheus 서비스를 재시작합니다.

### Prometheus 환경파일 편집 ###
vi /etc/prometheus/prometheus.yml

------------------------------------------------------------------------------------------------

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"]

  - job_name: "node_exporter"
    static_configs:
      - targets: ["192.168.56.153:9100"]

 

### Prometheus 서비스 재시작 ###
[root@localhost ~]# systemctl restart prometherus

### Prometheus 서비스 상태확인 ###
[root@localhost ~]# systemctl status prometheus
● prometheus.service - The Prometheus monitoring system and time series database.
   Loaded: loaded (/usr/lib/systemd/system/prometheus.service; enabled; vendor preset: disabled)
   Active: active (running) since ...
...

 

 

Grafana에서 Node exporter로 서버 정보 보기

Grafana 사이트에서 Node exporter와 관련된 Dashboard를 검색하여 마음에 드는 것을 선택한후 JSON 파일을 다운로드합니다. 이 페이지에서는 최근에 Grafana에 등록된 JSON 파일을 다운로드하여 사용합니다.

node-exporter-for-prometheus-dashboard-en-v20201010_rev9.json
0.10MB

Node exporter용 Dashboard JSON 파일을 다운로드 받았다면, Grafana의 좌측 메뉴에서 Dashboard > Manage > Import > Upload JSON file 순으로 클릭하여 다운로드 받은 파일을 업로드 합니다. 업로드가 완료되었다면, 「VictoriaMetrics」 항목에서 「Prometheus」를 선택한후 「Import」 버튼을 클릭합니다.

설정상에 문제가 없다면 아래와 같이 Node exporter를 통해 수집되는 서버 정보를 볼수 있습니다.

반응형
반응형

간혹 윈도우에서 "네트워크 드라이브 끊기"가 안될 때가 있습니다. 원인은 여러가지가 있겠지만, 보통 연결한 네트워크 드라이브의 경로가 변경되거나 존재하지 안을 때에 발생하는데요, 윈도우 탐색기에서 "네트워크 드라이브 끊기"를 실행해도 시간만 잡아먹고 네트워크 드라이브가 끊어지지 안을 때는, 아래와 같이 "커맨드 프롬프트"에서 연결된 네트워크 드라이브를 끊을 수 있습니다.

 

"net use Z: /delete"에서 "Z:"는 삭제할 네트워크 드라이브를 의미하므로, 실수로 다른 네트워크 드라이브를 삭제하지 안도록, 삭제 전에 한번 더 확인후 삭제하도록 합니다.

C:\>net use
New connections will be remembered.

Status       Local     Remote                         Network
-------------------------------------------------------------------------------
OK           Z:        \\file-3.bobocomi.com\backup   Microsoft Windows Network
The command completed successfully.


C:\>net use Z: /delete
There are open files and/or incomplete directory searches pending on the connection to Z:.

Is it OK to continue disconnecting and force them closed? (Y/N) [N]: Y
Z: was deleted successfully.


C:\>net use
New connections will be remembered.
반응형
반응형

CentOS에 기본 방화벽으로 올라가는 firewalld의 개인적으로 자주 사용하는 명령어들을 소개합니다. 설명에 사용되는 환경은 CentOS 8 최소설치입니다. (별도 안내 없이 필요한 경우 내용이 수정될 수 있습니다)




Built in service 리스트에 있는 서비스를 방화벽에 추가하기


「--get-services」 옵션을 사용하면, 내장형 서비스들을 볼 수 있습니다. 「--info-service=」 옵션에 서비스명을 더하여 실행하면 해당 서비스의 프로토콜 및 포트와 같은 정보를 볼 수 있습니다. 필요하다면, 이런 서비스를 활성화되어 있는 존에 추가하여 방화벽을 설정할 수 있습니다.


[root@localhost ~]# firewall-cmd --get-services

RH-Satellite-6 amanda-client amanda-k5-client ...



[root@localhost ~]# firewall-cmd --info-service=dns

dns

  ports: 53/tcp 53/udp

  protocols:

  source-ports:

  modules:

  destination:

  includes:

  helpers:



[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=dns

success



[root@localhost ~]# firewall-cmd --reload

success



[root@localhost ~]# firewall-cmd --list-services

cockpit dhcpv6-client dns ssh



[root@localhost ~]# firewall-cmd --list-all

public (active)

  target: default

  icmp-block-inversion: no

  interfaces: ens32

  sources:

  services: cockpit dhcpv6-client dns ssh

  ports:

  protocols:

  masquerade: no

  forward-ports:

  source-ports:

  icmp-blocks:

  rich rules:




Built in service 리스트에 없는 서비스를 방화벽에 추가하기


firewalld를 사용하다보면, 방화벽에 추가하고 싶은 서비스가 「Built in service」 리스트에 없는 경우가 있습니다. 방화벽에 해당 서비스 포트를 지정해서 추가할수도 있습니다만, 임의로 서비스를 등록해서 방화벽에 추가할수도 있습니다.


그럼, 방화벽의 서비스 리스트에서 임의로 서비스를 추가하는 방법에 대해서 알아 보겠습니다. 추가할 대상 서비스는 「rabbitmq」로 합니다. 임의로 생성하는 서비스는 사용되는 포트만 추가한 후, 마지막으로 방화벽에 임의 생성한 서비스를 등록해 보겠습니다.


[root@localhost ~]# firewall-cmd --get-services | grep rabbitmq

Nothing...



[root@localhost ~]# firewall-cmd --permanent --new-service=rabbitmq

success



[root@localhost ~]# firewall-cmd --permanent --service=rabbitmq --add-port=5671/tcp

success



[root@localhost ~]# firewall-cmd --permanent --add-service=rabbitmq

success



[root@localhost ~]# firewall-cmd --reload

success



[root@localhost ~]# firewall-cmd --get-services | grep rabbitmq

... rabbitmq ...



[root@localhost ~]# firewall-cmd --info-service=rabbitmq

rabbitmq

  ports: 5671/tcp

  protocols:

  source-ports:

  modules:

  destination:

  includes:

  helpers:



[root@localhost ~]# firewall-cmd --list-all

public (active)

  target: default

  icmp-block-inversion: no

  interfaces: ens32

  sources:

  services: cockpit dhcpv6-client dns rabbitmq ssh

  ports:

  protocols:

  masquerade: no

  forward-ports:

  source-ports:

  icmp-blocks:

  rich rules:




읽어 주셔서 감사합니다.

반응형

'Server > Linux' 카테고리의 다른 글

[리눅스] UMASK 명령어  (0) 2021.11.18
wget에서 인증서 에러  (0) 2021.11.09
[BIND] CentOS 7에서 DNS 설치  (0) 2020.07.17
CURL 또는 LYNX로 웹 사이트의 헤더 정보 확인하기  (0) 2019.07.02
Linux tar  (0) 2019.06.26
반응형

설명


YUM(Yellowdog Updater Modified)은 RPM 패키지를 관리하는 관리툴입니다.




Usage


yum [options] COMMAND or yum COMMAND [options]




Command - history


명령어로 히스토리를 확인할 수 있으며, 특정 ID의 상세정보 확인 및 필요하다면 설치된 패키지를 삭제할 수도 있습니다. 아래는 히스토리를 참조하는 것과 상세정보 출력, 그리고 해당 ID를 삭제하는 순서로 실행해본 결과입니다.

[root@localhost ~]# yum history

ID     | Command line             | Date and time    | Action(s)      | Altered

-------------------------------------------------------------------------------

     7 | install yum-utils        | 2020-07-31 16:36 | Install        |    1

     6 | -y install epel-release  | 2020-07-31 16:15 | Install        |    1

     5 | -y install bind bind-chr | 2020-07-30 15:09 | Install        |    7

     4 | -y install policycoreuti | 2020-07-30 15:06 | Install        |    6

     3 | -y update                | 2020-07-30 14:43 | I, U           |  215 EE

     2 | install net-tools        | 2020-07-30 10:26 | Install        |    1

     1 |                          | 2020-07-30 10:10 | Install        |  404 EE


[root@localhost ~]# yum history info 2

Transaction ID : 2

Begin time     : Thu 30 Jul 2020 10:26:47 AM KST

Begin rpmdb    : 401:1541256abb0af06e22f82ab3f5d807c669d1c337

End time       : Thu 30 Jul 2020 10:26:48 AM KST (1 seconds)

End rpmdb      : 402:0f48d81360bfb849c0b61df3411ce05bd59476f1

User           : root <root>

Return-Code    : Success

Releasever     : 8

Command Line   : install net-tools

Packages Altered:

    Install net-tools-2.0-0.51.20160912git.el8.x86_64 @BaseOS


[root@localhost ~]# yum history undo 2

Last metadata expiration check: 0:03:42 ago on Fri 31 Jul 2020 05:33:57 PM KST.

Undoing transaction 2, from Thu 30 Jul 2020 10:26:47 AM KST

    Install net-tools-2.0-0.51.20160912git.el8.x86_64 @BaseOS

Dependencies resolved.

================================================================================================

 Package           Architecture       Version                      Repository             Size

================================================================================================

Removing:

 net-tools         x86_64             2.0-0.51.20160912git.el8     @BaseOS               1.0 M


Transaction Summary

================================================================================================

Remove  1 Package


Freed space: 1.0 M

Is this ok [y/N]: y

...

Removed:

  net-tools-2.0-0.51.20160912git.el8.x86_64


Complete!


[root@localhost ~]# yum history

ID     | Command line             | Date and time    | Action(s)      | Altered

-------------------------------------------------------------------------------

     8 | history undo 2           | 2020-07-31 17:37 | Removed        |    1

     7 | install yum-utils        | 2020-07-31 16:36 | Install        |    1

     6 | -y install epel-release  | 2020-07-31 16:15 | Install        |    1

     5 | -y install bind bind-chr | 2020-07-30 15:09 | Install        |    7

     4 | -y install policycoreuti | 2020-07-30 15:06 | Install        |    6

     3 | -y update                | 2020-07-30 14:43 | I, U           |  215 EE

     2 | install net-tools        | 2020-07-30 10:26 | Install        |    1

     1 |                          | 2020-07-30 10:10 | Install        |  404 EE




Command - repolist


아래와 같은 명령어로 리포지토리 전체 리스트와 활성화된 리스트, 비활성화된 리스트를 확인할 수 있습니다.


[root@localhost ~]# yum repolist --all

repo id                         repo name                                              status

AppStream                       CentOS-8 - AppStream                                   enabled

AppStream-source                CentOS-8 - AppStream Sources                           disabled

BaseOS                          CentOS-8 - Base                                        enabled

BaseOS-source                   CentOS-8 - BaseOS Sources                              disabled

Devel                           CentOS-8 - Devel WARNING! FOR BUILDROOT USE ONLY!      disabled

HighAvailability                CentOS-8 - HA                                          disabled

PowerTools                      CentOS-8 - PowerTools                                  disabled

base-debuginfo                  CentOS-8 - Debuginfo                                   disabled

c8-media-AppStream              CentOS-AppStream-8 - Media                             disabled

c8-media-BaseOS                 CentOS-BaseOS-8 - Media                                disabled

centosplus                      CentOS-8 - Plus                                        disabled

centosplus-source               CentOS-8 - Plus Sources                                disabled

cr                              CentOS-8 - cr                                          disabled

extras                          CentOS-8 - Extras                                      enabled

extras-source                   CentOS-8 - Extras Sources                              disabled

fasttrack                       CentOS-8 - fasttrack                                   disabled


[root@localhost ~]# yum repolist --enabled

repo id                         repo name

AppStream                       CentOS-8 - AppStream

BaseOS                          CentOS-8 - Base

extras                          CentOS-8 - Extras


[root@localhost ~]# yum repolist --disabled

repo id                         repo name

AppStream-source                CentOS-8 - AppStream Sources

BaseOS-source                   CentOS-8 - BaseOS Sources

Devel                           CentOS-8 - Devel WARNING! FOR BUILDROOT USE ONLY!

HighAvailability                CentOS-8 - HA

PowerTools                      CentOS-8 - PowerTools

base-debuginfo                  CentOS-8 - Debuginfo

c8-media-AppStream              CentOS-AppStream-8 - Media

c8-media-BaseOS                 CentOS-BaseOS-8 - Media

centosplus                      CentOS-8 - Plus

centosplus-source               CentOS-8 - Plus Sources

cr                              CentOS-8 - cr

extras-source                   CentOS-8 - Extras Sources

fasttrack                       CentOS-8 - fasttrack




활용 - 외부 리포지터리 추가후 활성화 및 비활성화


외부 리포지토리인 EPEL을 설치하고 활성화 유무를 확인히 봅니다.


[root@localhost ~]# yum -y install epel-release

Last metadata expiration check: 1:37:37 ago on Fri 31 Jul 2020 02:37:49 PM KST.

Dependencies resolved.

================================================================================================

 Package                   Architecture            Version          Repository             Size

================================================================================================

Installing:

 epel-release              noarch                  8-8.el8          extras                 23 k


Transaction Summary

================================================================================================

Install  1 Package


...

Complete!


[root@localhost ~]# yum repolist --all | grep epel

epel                           Extra Packages for Enterprise Linux 8 -  enabled

epel-debuginfo                 Extra Packages for Enterprise Linux 8 -  disabled

epel-modular                   Extra Packages for Enterprise Linux Modu enabled

epel-modular-debuginfo         Extra Packages for Enterprise Linux Modu disabled

epel-modular-source            Extra Packages for Enterprise Linux Modu disabled

epel-playground                Extra Packages for Enterprise Linux 8 -  disabled

epel-playground-debuginfo      Extra Packages for Enterprise Linux 8 -  disabled

epel-playground-source         Extra Packages for Enterprise Linux 8 -  disabled

epel-source                    Extra Packages for Enterprise Linux 8 -  disabled

epel-testing                   Extra Packages for Enterprise Linux 8 -  disabled

epel-testing-debuginfo         Extra Packages for Enterprise Linux 8 -  disabled

epel-testing-modular           Extra Packages for Enterprise Linux Modu disabled

epel-testing-modular-debuginfo Extra Packages for Enterprise Linux Modu disabled

epel-testing-modular-source    Extra Packages for Enterprise Linux Modu disabled

epel-testing-source            Extra Packages for Enterprise Linux 8 -  disabled


비활성화되어 있는 리포지토리 활성화해 보겠습니다. 직접 리포지터리 파일을 편집할 수도 있지만, 간단한 명령어로도 활성화가 가능합니다. 명령어는 별도의 「yum-utils」라는 패키지가 필요하므로 설치한 후 실행해 보겠습니다.


[root@localhost ~]# yum repolist --all | grep epel-source

epel-source                    Extra Packages for Enterprise Linux 8 -  disabled


[root@localhost ~]# yum -y install yum-utils

Last metadata expiration check: 0:04:11 ago on Fri 31 Jul 2020 04:32:00 PM KST.

Dependencies resolved.

================================================================================================

 Package                   Architecture            Version          Repository             Size

================================================================================================

Installing:

 yum-utils                 noarch                  4.0.12-3.el8     BaseOS                 66 k


Transaction Summary

================================================================================================

Install  1 Package


...

Complete!


[root@localhost ~]# yum-config-manager --enable epel-source


[root@localhost ~]# yum repolist --all | grep epel-source

epel-source                    Extra Packages for Enterprise Linux 8 -  enabled


「--disable」 옵션을 붙여서 다시 비활성화 할수도 있습니다.


[root@localhost ~]# yum-config-manager --disable epel-source


[root@localhost ~]# yum repolist --all | grep epel-source

epel-source                    Extra Packages for Enterprise Linux 8 -  disabled



읽어주셔서 감사합니다.

반응형
반응형

설명


이 페이지에서는 CentOS에서 방화벽 설정에 사용된는 ipset 설정에 대해서 살펴보겠습니다.




ipset


설정할 수 있는 「ipset」 타입을 보여 줍니다. 알아보기 쉽게 적당히 개행처리하였습니다. 그럼 많이 사용하는 타입인 hash:ip와 hash:net에 대해서 알아 보겠습니다.


[root@localhost ~]# firewall-cmd --get-ipset-types


hash:ip 

hash:ip,mark 

hash:ip,port 

hash:ip,port,ip 

hash:ip,port,net 

hash:mac 

hash:net 

hash:net,iface 

hash:net,net 

hash:net,port 

hash:net,port,net



ipset - hash:ip type


hash:ip는 IP와 Network 주소를 지원합니다. IPv4의 경우는 CIDR prefix value가 1에서 32 사이여야만 한다는 조건이 있기 때문에 단일 네트워크 또는 단일 네트워크의 IP를 추가할 때 유용할 수 있습니다. IPv6의 경우는 1에서 128 까지로 제한됩니다.


hash:ip 타입으로 ipset 추가하고, 이어서 Network 주소 및 IP를 추가해 보겠습니다.


[root@localhost ~]# firewall-cmd --permanent --new-ipset=test_internal_https --type=hash:ip

「--new-ipset=」에 적당히 네이밍을 합니다.


[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entry=192.168.56.0/27

[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entry=192.168.56.33

[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entry=192.168.56.34

[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entry=192.168.56.35

[root@localhost ~]# firewall-cmd --reload


위에서 추가한 ipset 정보를 확인합니다.


[root@localhost ~]# firewall-cmd --get-ipsets

test_internal_https

[root@localhost ~]# firewall-cmd --ipset=test_internal_https --get-entries
192.168.56.0/27
192.168.56.33
192.168.56.34
192.168.56.35


ipset에 추가한 단일 엔트리의 유무도 확인할 수 있습니다.


[root@localhost ~]# firewall-cmd --ipset=test_internal_https --query-entry=192.168.56.35

yes


[root@localhost ~]# firewall-cmd --ipset=test_internal_https --query-entry=192.168.56.40

no


다음은 엔트리를 삭제해 보겠습니다. 그런다음 파일에서 엔트리를 추가해 보겠습니다.


[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entry=192.168.56.0/27

[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entry=192.168.56.33

[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entry=192.168.56.34

[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entry=192.168.56.35

[root@localhost ~]# firewall-cmd --reload


[root@localhost ~]# firewall-cmd --ipset=test_internal_https --get-entries

Nothing...


[root@localhost ~]# echo -e "192.168.56.33\n192.168.56.34\n192.168.56.35\n192.168.56.0/27" > /root/test_internal_https_hash_ip.txt


[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --add-entries-from-file=/root/test_internal_https_add_hash_ip.txt


[root@localhost ~]# firewall-cmd --reload


[root@localhost ~]# firewall-cmd --ipset=test_internal_https --get-entries

192.168.56.33

192.168.56.34

192.168.56.35

192.168.56.0/27


파일로 일부 엔트리를 삭제해 보고, ipset 자체를 삭제해 보겠습니다.


[root@localhost ~]# echo "192.168.56.34" > /root/test_internal_https_rem_hash_ip.txt


[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_https --remove-entries-from-file=/root/test_internal_https_rem_hash_ip.txt


[root@localhost ~]# firewall-cmd --reload


[root@localhost ~]# firewall-cmd --ipset=test_internal_https --get-entries

192.168.56.33

192.168.56.35

192.168.56.0/27


[root@localhost ~]# firewall-cmd --permanent --delete-ipset=test_internal_https


[root@localhost ~]# firewall-cmd --reload


[root@localhost ~]# firewall-cmd --get-ipsets

Nothing...



ipset - hash:net type


hash:net는 복수의 네트워크 주소를 추가할수 있습니다. hash:ip 타입을 지정하는 부분 외에 설정 방법이 거의 같으므로, ipset 생성과 엔트리 추가 외의 부분은 생략하겠습니다.


[root@localhost ~]# firewall-cmd --permanent --new-ipset=test_internal_snmp --type=hash:net

「--new-ipset=」에 적당히 네이밍을 합니다.


[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_snmp --add-entry=192.168.56.0/24

[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_snmp --add-entry=192.168.57.0/24

[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_snmp --add-entry=192.168.58.0/24

[root@localhost ~]# firewall-cmd --permanent --ipset=test_internal_snmp --add-entry=192.168.59.0/24

[root@localhost ~]# firewall-cmd --reload


위에서 추가한 ipset 정보를 확인합니다.


[root@localhost ~]# firewall-cmd --get-ipsets

test_internal_snmp

[root@localhost ~]# firewall-cmd --ipset=test_internal_snmp --get-entries
192.168.56.0/24
192.168.57.0/24
192.168.58.0/24
192.168.59.0/24


생성한 ipset의 정보를 확인합니다.


[root@localhost ~]# firewall-cmd --info-ipset=test_internal_snmp

test_internal_snmp

  type: hash:net

  options:

  entries: 192.168.56.0/24 192.168.57.0/24 192.168.58.0/24 192.168.59.0/24




읽어 주셔서 감사합니다.

반응형
반응형

설명


이 페이지에서 BIND(네임서버) 버전 정보 감추기에 대해서 알아 봅니다.




BIND 버전 확인


서버에 설치된 「BIND」의 버전은 「named」 명령어로 확인할 수 있습니다.


[root@localhost ~]# named -v

BIND 9.11.13-RedHat-9.11.13-5.el8_2 (Extended Support Version) <id:ad4df16> 


그럼 외부에서 「dig」 명령어로 「BIND」 버전을 확인해 보겠습니다. 「dig」 명령어가 실행된 결과를 보면, 「version.bind.」에 버전이 표시되어 있습니다. 「dig」 명령어에서 「@192.168.56.151」는 BIND(네임서버)를 의미합니다. 「ch(chaos)」는 클래스의 한 종류이며, 「txt」는 레코드의 한 종류입니다. 


[root@localhost ~]# dig @192.168.56.151 ch txt version.bind 

; <<>> DiG 9.11.13-RedHat-9.11.13-5.el8_2 <<>> @192.168.56.151 chaos txt version.bind

; (1 server found)

;; global options: +cmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55039

;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; WARNING: recursion requested but not available


;; OPT PSEUDOSECTION:

; EDNS: version: 0, flags:; udp: 4096

; COOKIE: 25885307f837b3435f87f2765f167f7594a2f03bb150a659 (good)

;; QUESTION SECTION:

;version.bind.                  CH      TXT


;; ANSWER SECTION:

version.bind.           0       CH      TXT     "9.11.13-RedHat-9.11.13-5.el8_2"


;; AUTHORITY SECTION:

version.bind.           0       CH      NS      version.bind.


;; Query time: 0 msec

;; SERVER: 192.168.56.151#53(192.168.56.151)

;; WHEN: Tue Jul 21 14:39:01 KST 2020

;; MSG SIZE  rcvd: 126




BIND 버전 감추기


「BIND」의 환경설정 파일인 「named.conf」에 「version "unknown"」을 추가한 후, 서비스를 재기동한 후, 「dig」 명령어를 실행해보면 버전 정보가 「unknown」으로 표시됩니다.


[root@localhost ~]# vi /etc/named.conf

options {
        version "unknown";
        listen-on port 53       { 127.0.0.1; };
        listen-on-v6 port 53    { ::1; };
...
...

[root@localhost ~]# systemctl restart named

[root@localhost ~]# dig @192.168.56.151 ch txt version.bind
; <<>> DiG 9.11.13-RedHat-9.11.13-5.el8_2 <<>> @192.168.56.151 chaos txt version.bind
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39438
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: e38ec1637a3cd6a3e32423bc5f1682405076f4a499bcb4e4 (good)
;; QUESTION SECTION:
;version.bind.                  CH      TXT

;; ANSWER SECTION:
version.bind.           0       CH      TXT     "unknown"

;; AUTHORITY SECTION:
version.bind.           0       CH      NS      version.bind.

;; Query time: 0 msec
;; SERVER: 192.168.56.151#53(192.168.56.151)
;; WHEN: Tue Jul 21 14:50:56 KST 2020
;; MSG SIZE  rcvd: 103



읽어 주셔서 감사합니다.

반응형
반응형

설명


이 페이지에서는 nc 명령어로 특정 파일을 서버에서 서버로 전송(백업)하는 내용을 다룹니다. NC로 파일을 전송할 때 포트를 지정하므로 방화벽에서 이미 오픈되어 있는 포트를 사용하거나, 일시적으로 해당 포트의 오픈이 필요합니다.




환경


OS: CentOS 8(VM)



패키지 설치


[root@localhost ~]# yum -y install nmap-ncat tar



NC Server


파일을 저장하려고하는 서버에 아래와 같이 nc 명령어를 실행합니다. 「-l」 옵션은 수신대기 상태를 의미하며, 「-p」 옵션은 특정 포트 지정을 의미합니다. 그 뒤의 「tar -xvf -」 명령어는 수신되는 파일을 압축해재해서 「-C」 옵션에서 지정한 디렉토리에 저장하는 것을 의미합니다.


[root@localhost ~]# nc -l -p 10000 | tar xvf - -C /root/backup




NC Client


위에서 수신대기 상태로 실행된 nc에 파일을 전송하는 명령어입니다. 「tar cfp -」는 「test.txt」 파일을 압축하고, 그 뒤에 나오는 「192.168.56.151」 서버에 파일을 전송합니다.


[root@localhost ~]# tar cfp - test.txt | nc 192.168.56.151 10000



읽어주셔서 감사합니다.

반응형
반응형

설명


CentOS 8에서 네임서버 설정을 변경하는 방법에 대해서 설명합니다.




네임서버 변경 


네임서버를 변경하는 방법은 「resolv.conf」 파일에서 직접변경하는 방법과 NIC 정보를 담고 있는 「ifcfg-enp0sx」 파일에서 「DNSx」 항목의 설정을 변경하는 방법이 있습니다. 우선 ifcfg-enp0sx」 파일의 설정을 변경해서 네임서버 정보를 변경하는 방법에 대해서 설명합니다.


이전에는 「/etc/resolv.conf」 파일을 편집하였다면, CentOS 8에서는 「ifcfg-enp0sx」 파일의 「DNS」 항목을 편집하여 네임서버 정보를 변경할 수 있습니다.


[root@localhost ~]# cat /etc/resolv.conf

# Generated by NetworkManager

nameserver 10.42.255.203

nameserver 10.42.255.204


[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

TYPE="Ethernet"

PROXY_METHOD="none"

BROWSER_ONLY="no"

BOOTPROTO="none"

DEFROUTE="yes"

IPV4_FAILURE_FATAL="no"

IPV6INIT="yes"

IPV6_AUTOCONF="yes"

IPV6_DEFROUTE="yes"

IPV6_FAILURE_FATAL="no"

IPV6_ADDR_GEN_MODE="stable-privacy"

NAME="enp0s3"

UUID="49186b71-e909-4ea7-8aa7-fa35e66b3d91"

DEVICE="enp0s3"

ONBOOT="yes"

IPADDR="192.168.56.151"

PREFIX="24"

GATEWAY="192.168.56.1"

DNS1="192.168.56.151"

DNS2="192.168.56.152"

DNS3="8.8.8.8"

IPV6_PRIVACY="no"


[root@localhost ~]# systemctl restart NetworkManager


[root@localhost ~]# cat /etc/resolv.conf

# Generated by NetworkManager

nameserver 192.168.56.151

nameserver 192.168.56.152

nameserver 8.8.8.8


설정파일이 아닌 서비스 중인 DNS 설정 값을 확인하려면 명령어 「resolvectl status」로 확인할 수도 있습니다.


[root@localhost ~]# resolvectl status

Global

       LLMNR setting: yes

MulticastDNS setting: yes

  DNSOverTLS setting: no

      DNSSEC setting: allow-downgrade

    DNSSEC supported: yes

  Current DNS Server: 192.168.56.151

         DNS Servers: 192.168.56.151

                      192.168.56.152

                      8.8.8.8

...

...

Link 2 (enp0s3)

      Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6

       LLMNR setting: yes

MulticastDNS setting: no

  DNSOverTLS setting: no

      DNSSEC setting: allow-downgrade

    DNSSEC supported: yes

  Current DNS Server: 192.168.56.151

         DNS Servers: 192.168.56.151

                      192.168.56.152

                      8.8.8.8

          DNS Domain: ~.


두번째 방법인 이전 버전에서와 같이 「resolv.conf」 파일에서 네임서버 정보를 관리하는 방법입니다. 설정 방법은 「Networkmanager.conf」 파일의 「main」 항목에 「dns=none」를 추가하여 「resolv.conf」 파일에서 네임서버 정보가 관리되도록 설정합니다.


[root@localhost ~]# vi /etc/resolv.conf

# Generated by NetworkManager

nameserver 192.168.56.151

nameserver 192.168.56.152

nameserver 1.1.1.1


[root@localhost ~]# vi /etc/NetworkManager/NetworkManager.conf

...

...

[main]

#plugins=ifcfg-rh

dns=none


[logging]

...

...

#level=TRACE

#domains=ALL


[root@localhost ~]# systemctl restart NetworkManager



[root@localhost ~]# cat /etc/resolv.conf

# Generated by NetworkManager

nameserver 192.168.56.151

nameserver 192.168.56.152

nameserver 1.1.1.1


[root@master ~]# resolvectl status

Global

       LLMNR setting: yes

MulticastDNS setting: yes

  DNSOverTLS setting: no

      DNSSEC setting: allow-downgrade

    DNSSEC supported: yes

  Current DNS Server: 192.168.56.151

         DNS Servers: 192.168.56.151

                      192.168.56.152

                      1.1.1.1

...

...

Link 2 (enp0s3)

      Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6

       LLMNR setting: yes

MulticastDNS setting: no

  DNSOverTLS setting: no

      DNSSEC setting: allow-downgrade

    DNSSEC supported: yes

  Current DNS Server: 192.168.56.151

         DNS Servers: 192.168.56.151

                      192.168.56.152

          DNS Domain: ~.


읽어 주셔서 감사합니다.

반응형

+ Recent posts