๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿ› ๏ธcode/DNS

[DNS] BIND๊ฐ€ ๋ฐ›์€ ์ฟผ๋ฆฌ ์ •๋ณด๋ฅผ ์›๊ฒฉ ์„œ๋ฒ„์˜ rsyslogd๋กœ ์ „์†กํ•˜๊ธฐ

  • ์š”์•ฝ
    • ๋ฐฐ๊ฒฝ
      • ์˜จํ”„๋ ˆ๋ฏธ์Šค ์ธํ”„๋ผ
      • Rocky Linux 9, BIND 9.16.23, rsyslogd 8.2102.0-113.el9_2
      • ๋กœ๊ทธ๋ฅผ ๋ณด๋‚ด๋Š” ๋„์ฐฉ์ง€ ์ฃผ์†Œ๋Š” LB
    • ์ ˆ์ฐจ
      • ์›๊ฒฉ ์„œ๋ฒ„
        • rsyslog์—์„œ ๋กœ๊ทธ๋ฅผ ์ˆ˜์‹ ํ•  ํฌํŠธ ์—ด์–ด ์ฃผ๊ธฐ
      • Cache DNS ์„œ๋ฒ„
        • rsyslog์—์„œ ๋กœ๊น… ์„ค์ • ์ถ”๊ฐ€
        • named ๋กœ๊ทธ ์„ธํŒ…
        • ํ•„์š”์— ๋”ฐ๋ผ, rsyslog๊ฐ€ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ์ฟผ๋ฆฌ์˜ ์ œํ•œ ์ˆ˜๋Ÿ‰์„ ์กฐ์ •
  • ๋ฐฐ๊ฒฝ
    • ํƒ€ ๋ถ€์„œ์˜ ์š”์ฒญ์œผ๋กœ, ๋‚ด๊ฐ€ ๊ด€๋ฆฌํ•˜๋Š” ์บ์‹œ DNS ์„œ๋ฒ„์—์„œ BIND ๋กœ๊ทธ๋ฅผ ๋กœ๊ทธ์Šคํƒœ์‹œ ์„œ๋ฒ„๋กœ ์˜๊ฒŒ ํ•  ์ผ์ด ์ƒ๊ฒผ๋‹ค. ๋ฐ›์€ ์ •๋ณด๋Š” ๋กœ๊ทธ์Šคํƒœ์‹œ ์„œ๋ฒ„ ์•ž ๋‹จ์— ์žˆ๋Š” LB์˜ IP ์ฃผ์†Œ์™€ ์‚ฌ์šฉ ํฌํŠธ(UDP 5063)์ด๋‹ค.
    • ๋‚ด๊ฐ€ ์‹œ์Šคํ…œ ๊ด€๋ฆฌ์ž์ด๋ฏ€๋กœ ๋ชจ๋“  ์„œ๋ฒ„์— ๋Œ€ํ•œ ์ ‘์†์€ ์ž์œ ๋กญ๊ฒŒ ๊ฐ€๋Šฅํ•จ.
  • ์ ˆ์ฐจ
    • ์›๊ฒฉ ์„œ๋ฒ„ - logstash-01/02
      • ๋ฃจํŠธ ๊ถŒํ•œ์œผ๋กœ /etc/rsyslog.conf๋ฅผ ์—ด๊ณ , ์•„๋ž˜ ์ฃผ์„์„ ํ™•์ธํ•œ๋‹ค.
        ...
        
        # Provides UDP syslog reception
        # for parameters see http://www.rsyslog.com/doc/imudp.html
        #module(load="imudp") # needs to be done just once
        #input(type="imudp" port="514")
        
        # Provides TCP syslog reception
        # for parameters see http://www.rsyslog.com/doc/imtcp.html
        #module(load="imtcp") # needs to be done just once
        #input(type="imtcp" port="514")
        
        ...โ€‹
      • ์›ํ•˜๋Š” ํ”„๋กœํ† ์ฝœ๊ณผ ํฌํŠธ์— ๋งž์ถ”์–ด, ๋‘ ์ฝ”๋“œ ๋ธ”๋Ÿญ ์ค‘ ํ•œ ๊ณณ์˜ ์ฃผ์„์„ ํ’€์–ด๊ณ  ํฌํŠธ๋ฅผ ์ง€์ •ํ•œ๋‹ค.
        ...
        
        # Provides UDP syslog reception
        # for parameters see http://www.rsyslog.com/doc/imudp.html
        module(load="imudp") # needs to be done just once
        input(type="imudp" port="5063")
        
        ...โ€‹
      • `systemctl restart rsyslogd`๋กœ ์žฌ๊ธฐ๋™ ํ›„, ์•„๋ž˜์™€ ๊ฐ™์ด ํฌํŠธ ๊ฐœ๋ฐฉ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•œ๋‹ค.
        $ netstat -unlp | grep 5063
        udp        0      0 0.0.0.0:5063   0.0.0.0:*   1777459/java
        udp6       0      0 :::5063        :::*        1792701/rsyslogdโ€‹
        ์ž๋ฐ”๋„ ์—ด๋ฆฐ ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ €๊ฒŒ ๋กœ๊ทธ์Šคํƒœ์‹œ๋”๋ผ. /usr/share/logstash/jdk/bin/java๊ฐ€ ๋„๋Š” ๊ฒƒ์ด๋‹ค.
    • ์บ์‹œ DNS ์„œ๋ฒ„ - cdns-01/02
      • named ์„ค์ •์„ ๊ณ ์น˜๊ธฐ ์ „์—, ์—ฌ๊ธฐ์„œ๋„ rsyslog ์„ค์ •์„ ์†๋Œ€์•ผ ํ•œ๋‹ค. ์ด ์„œ๋ฒ„๋Š” /etc/rsyslog.conf์— ์†์„ ๋Œ€๋Š” ๋Œ€์‹  /etc/rsyslog.d/bind-log.conf๋ฅผ ์ƒ์„ฑํ•ด ๋‘๊ณ  ์•„๋ž˜ ๊ตฌ๋ฌธ์„ ์ถ”๊ฐ€ํ–ˆ๋‹ค.
        local0.*        @192.168.0.5:5063โ€‹
         
        • local0: ์—ฌ๋ถ„์˜ ๋กœ๊ทธ ๋ฉ”์‹œ์ง€๋ฅผ ์œ„ํ•ด ๋‚จ์€ local0~7 ์ค‘ ํ•˜๋‚˜. ๊ธฐ์กด์— local0์„ ์จ ๋‘์—ˆ๋‹ค๋ฉด ๋‹ค๋ฅธ ๊ฑฐ ์“ฐ๋ฉด ๋  ๊ฑฐ ๊ฐ™๋‹ค. ์‚ฌ์‹ค ์—ฌ๊ธฐ๊นŒ์ง€๋งŒ ์ดํ•ดํ–ˆ๊ณ , ์ •ํ™•ํžˆ ์ด ๋ถ€๋ถ„์— ์–ด๋Š ๋…€์„๋“ค์ด ๋“ค์–ด๊ฐ€๋Š”์ง€๋Š” ์ข€๋” ๋ด์•ผ ํ•œ๋‹ค..
        • 192.168.0.5: ๋กœ๊ทธ์Šคํƒœ์‹œ LB์˜ IP
      • ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋ฃจํŠธ ๊ถŒํ•œ์œผ๋กœ /etc/named.conf๋ฅผ ์—ด๊ณ , ๋กœ๊น… ์„ธํŒ…์„ ์•„๋ž˜์™€ ๊ฐ™์ด ํ•ด ์ค€๋‹ค. named.d ๋””๋ ‰ํ† ๋ฆฌ ์•ˆ์— ๋ณ„๋„์˜ .conf ํŒŒ์ผ ํ•˜๋‚˜ ๋งŒ๋“ค๊ณ  ํ•ด ์ค˜๋„ ์ข‹๋‹ค. queries_rsyslog ์ฑ„๋„์˜ syslog ํ•ญ๋ชฉ์— ์œ„์—์„œ ์ž…๋ ฅํ•œ local0๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜๋ผ.
        // syslog ์ฟผ๋ฆฌ ๋กœ๊ทธ ๋ณด๋‚ด๋Š” ์„ธํŒ…๋งŒ ํ•˜๊ณ  ์‹ถ์„ ๋•Œ
        logging {
                channel queries_rsyslog {
                        syslog local0;
                        print-time yes;
                        print-category yes;
                        print-severity yes;
                        severity info;
                };
        
                category queries { queries_rsyslog; };
        };
        
        // ๊ทธ ์™ธ์— ๋กœ์ปฌ์— ์Œ“๋Š” ๋กœ๊ทธ๋„ ๊ฐ™์ด ์ถ”๊ฐ€ํ•˜๊ณ  ์‹ถ์„ ๋•Œ
        logging {
                channel default_log {
                        file "/var/named/log/default.log" versions 50 size 20m;
                        print-time yes;
                        print-severity yes;
                        print-category yes;
                        severity info;
                };
        
                channel queries_log {
                        file "/var/named/log/queries.log" versions 50 size 20m;
                        print-time yes;
                        print-category yes;
                        print-severity yes;
                        severity info;
                };
        
                channel query_errors_log {
                        file "/var/named/log/query_errors.log" versions 50 size 20m;
                        print-time yes;
                        print-category yes;
                        print-severity yes;
                        severity info;
                };
        
                channel queries_rsyslog {
                        syslog local0;
                        print-time yes;
                        print-category yes;
                        print-severity yes;
                        severity info;
                };
        
                category default { default_log; };
                category queries { queries_log; queries_rsyslog; };
                category query-errors { query_errors_log; };
                category lame-servers { null; };
        };โ€‹
      • ๋งˆ์ง€๋ง‰์œผ๋กœ, ์บ์‹œ DNS ์ธก์˜ rsyslog๊ฐ€ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋ฉ”์‹œ์ง€์˜ ์ตœ๋Œ€ ์ˆ˜๋ฅผ ์กฐ์ ˆํ•œ๋‹ค. ์‚ฌ๋ก€๋Š” ์•„๋ž˜์— ์ ๋Š”๋‹ค.
        ...
        
        #### MODULES ####
        
        ...
        
        module(load="imjournal" 
               RateLimit.Interval="30"      # 30์ดˆ ์•ˆ์— ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋Š” ๋ฉ”์‹œ์ง€ ์ˆ˜๋ฅผ
               RateLimit.Burst="20000"      # 2๋งŒ ๊ฐœ๋กœ ์ง€์ •ํ•œ๋‹ค.
               StateFile="imjournal.state")
               
        ...โ€‹
      • ๋งˆ์ณค์œผ๋ฉด rsyslogd์™€ named๋ฅผ ์ฐจ๋ก€๋กœ ์žฌ๊ธฐ๋™ํ•ด ์ฃผ์ž. ๊ทธ ๋‹ค์Œ, ๋ชจ๋‹ˆํ„ฐ๋ง ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ํ™•์ธํ•˜๋ฉด ๋œ๋‹ค.
        ์ฃผ์˜: named๋Š” `named-checkconf` ๋ช…๋ น์œผ๋กœ ์šฐ์„  ์˜ค๋ฅ˜ ์—†๋Š”์ง€ ํ™•์ธํ•ด ์ฃผ์ž. ๊ทธ๋ฆฌ๊ณ  ๋กœ๊ทธ ๋‚จ๊ธฐ๋Š” ๊ฑด reload๋งŒ ํ•ด์„œ๋Š” ์‹œ์ž‘๋˜์ง€ ์•Š๋”๋ผ. ๊ทธ๋ž˜์„œ ์ด์ค‘ํ™” ๋œ ๋‹ค๋ฅธ ํ•œ ์„œ๋ฒ„๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋„๋Š” ๊ฑฐ ํ™•์ธํ•œ ์ƒํƒœ์—์„œ restart๋ฅผ ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.
  • ์ด์Šˆ ์‚ฌ๋ก€ - ์‹œ๊ฐ„ ๋‹น ์†ก์‹  ๊ฐ€๋Šฅํ•œ ๋ฉ”์‹œ์ง€ ์ตœ๋Œ€ ์ˆ˜ ์ดˆ๊ณผ๋กœ ์ธํ•œ ์†ก์‹  ์‹คํŒจ
    • ์บ์‹œ DNS ์„œ๋ฒ„์—์„œ tcpdump๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋กœ๊ทธ์Šคํƒœ์‹œ๋กœ ๊ฐ€๋Š” udp 5063 ํ†ต์‹  ํŒจํ‚ท์„ ํ™•์ธํ•˜๋˜ ๋„์ค‘ ๋ฐœ๊ฒฌํ–ˆ๋‹ค. ์ด ์บ์‹œ DNS ์„œ๋ฒ„๋“ค์€ ๋ถ„๋‹น ์ˆ˜์ฒœ ๊ฐœ์˜ DNS ์ฟผ๋ฆฌ๋ฅผ ๋ฐ›์•„๋“ค์ด๊ธฐ ๋•Œ๋ฌธ์— ์‹ค์‹œ๊ฐ„์œผ๋กœ rsyslog๊ฐ€ ์˜๋Š” ๋ฉ”์‹œ์ง€ ์–‘๋„ ๊ทธ๋งŒํผ ๋˜์–ด์•ผ ํ•˜๋Š”๋ฐ, 10๋ถ„ ๊ฐ„๊ฒฉ์œผ๋กœ ๋ฉ”์‹œ์ง€ ์˜๊ธฐ๋ฅผ ๋ฉˆ์ถ”๋”๋‹ˆ 5~10๋ถ„ ๊ฐ„ ์•„๋ฌด๋Ÿฐ ํŒจํ‚ท์ด ์žกํžˆ์งˆ ์•Š์•˜๋‹ค.
      ...
      Dec 28 16:47:18 cdns-01 rsyslogd[1020665]: imjournal: 16464 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 16:57:19 cdns-01 rsyslogd[1020665]: imjournal: 14487 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 17:07:20 cdns-01 rsyslogd[1020665]: imjournal: 24646 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 17:17:21 cdns-01 rsyslogd[1020665]: imjournal: 18538 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 17:27:22 cdns-01 rsyslogd[1020665]: imjournal: 15630 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 17:37:23 cdns-01 rsyslogd[1020665]: imjournal: 18411 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 17:47:24 cdns-01 rsyslogd[1020665]: imjournal: 17545 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 17:57:25 cdns-01 rsyslogd[1020665]: imjournal: 15574 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 18:07:26 cdns-01 rsyslogd[1020665]: imjournal: 25922 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 18:17:27 cdns-01 rsyslogd[1020665]: imjournal: 19361 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      Dec 28 18:27:28 cdns-01 rsyslogd[1020665]: imjournal: 18518 messages lost due to rate-limiting (20000 allowed within 600 seconds)
      ...โ€‹
    • ๊ณต์‹ ๋ฌธ์„œ๋ฅผ ํ™•์ธํ•ด ๋ณด๋‹ˆ, 600์ดˆ(10๋ถ„) ๋‹น 2๋งŒ ๊ฐœ์˜ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋‚ผ ์ˆ˜ ์žˆ๋„๋ก ํ•˜๋Š” ๊ฒŒ ๊ธฐ๋ณธ ์„ค์ •์ด๋‹ค.(์•„๋ž˜ ๊ด€๋ จ ์›น์‚ฌ์ดํŠธ ์ฐธ์กฐ) ์ด ๋ถ€๋ถ„์„ ์œ„์—์„œ /etc/rsyslog.conf๋ฅผ ์ˆ˜์ •ํ•˜์—ฌ ๋ฐ”๊พธ์–ด์ค€ ๊ฒƒ์ด๊ณ .

    • ํ•œ ๊ฐ€์ง€ ๋” ๊ณต์œ ํ•  ๊ฒƒ์€, Interval์„ 600์ดˆ ๊ทธ๋Œ€๋กœ ๋‘๊ณ  Burst๋งŒ 100๋งŒ ์ด๋ ‡๊ฒŒ ์˜ฌ๋ฆฌ๋ฉด ์ ์šฉ์ด ์ œ๋Œ€๋กœ ์•ˆ ๋œ๋‹ค๋Š” ๊ฒƒ์ด๋‹ค. ์‹ค์ œ๋กœ ๊ฐ๊ฐ 600, 1000000์œผ๋กœ ์„ค์ •ํ•œ ๊ฒฐ๊ณผ ์•„๋ž˜์™€ ๊ฐ™์ด ๋กœ๊ทธ๊ฐ€ ๋‚จ์•˜๋‹ค.
      2024.01.02 ์ถ”๊ฐ€: RateLimit.Burst์˜ ์ตœ๋Œ€ ๊ฐ’์€ 65535์ด๋‹ค. ๋‚˜๋ž‘ ๋น„์Šทํ•œ ๋ฌธ์ œ๋ฅผ ๊ฒช์€ ์‚ฌ๋žŒ์ด ๋ ˆ๋“œํ–‡ ํฌํƒˆ์— ๋ณด์—ฌ์„œ ๋งํฌ ์˜ฌ๋ฆฐ๋‹ค. https://access.redhat.com/solutions/5185431
      ...
      Dec 29 00:08:43 cdns-01 rsyslogd[1105947]: imjournal: 38299 messages lost due to rate-limiting (50000 allowed within 600 seconds)
      Dec 29 00:18:44 cdns-01 rsyslogd[1105947]: imjournal: 34645 messages lost due to rate-limiting (50000 allowed within 600 seconds)
      Dec 29 00:28:45 cdns-01 rsyslogd[1105947]: imjournal: 33048 messages lost due to rate-limiting (50000 allowed within 600 seconds)
      Dec 29 00:38:46 cdns-01 rsyslogd[1105947]: imjournal: 33978 messages lost due to rate-limiting (50000 allowed within 600 seconds)
      Dec 29 00:48:47 cdns-01 rsyslogd[1105947]: imjournal: 32122 messages lost due to rate-limiting (50000 allowed within 600 seconds)
      Dec 29 00:58:48 cdns-01 rsyslogd[1105947]: imjournal: 31290 messages lost due to rate-limiting (50000 allowed within 600 seconds)
      Dec 29 01:08:49 cdns-01 rsyslogd[1105947]: imjournal: 39145 messages lost due to rate-limiting (50000 allowed within 600 seconds)
      Dec 29 01:18:50 cdns-01 rsyslogd[1105947]: imjournal: 31488 messages lost due to rate-limiting (50000 allowed within 600 seconds)
      ...โ€‹
    • ๊ทธ๋ž˜์„œ ์œ„์—์„œ ์„ค์ •ํ•œ ๊ฒƒ์ฒ˜๋Ÿผ, 30์ดˆ ๋‹น 2๋งŒ ๊ฐœ๋กœ ํ•œ ๊ฒƒ์ด๋‹ค. ์‹ค์ œ๋กœ ๊ฐ ์บ์‹œ DNS ์„œ๋ฒ„๊ฐ€ ๋ณดํ†ต 30์ดˆ ๋‹น ๋ฐ›๋Š” ์ฟผ๋ฆฌ์˜ ์–‘์ด 5์ฒœ ๊ฐœ๊ฐ€ ์ข€ ์•ˆ ๋˜๋Š” ์ˆ˜์ค€์ด์—ˆ๊ณ , ์„œ๋ฒ„ ํ•˜๋‚˜๊ฐ€ ์ฃฝ๋Š” ๊ฒƒ ๋ฐ ์ฟผ๋ฆฌ ํญ์ฆ์„ ๊ฐ์•ˆํ•ด์„œ 30์ดˆ ๋‹น 2๋งŒ์œผ๋กœ ์žก์•˜๋‹ค. ์•„๋ž˜์— ์‹ค์ œ๋กœ ์บ์‹œ DNS ์„œ๋ฒ„์˜ ๋ชจ๋‹ˆํ„ฐ๋ง ๊ฒฐ๊ณผ๋ฅผ ๊ณต์œ ํ•œ๋‹ค.

    • ์บ์‹œ DNS๊ฐ€ ๋ฐ›๋Š” A ์ฟผ๋ฆฌ
    • ๋™ ์‹œ๊ฐ„๋Œ€์— ์บ์‹œ DNS๊ฐ€ ๋„คํŠธ์›Œํฌ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํƒ€๊ณ  ๋ฐ–์œผ๋กœ ๋ณด๋‚ธ ๋น„ํŠธ ์ˆ˜.
      ์ดˆ๋ก์ƒ‰ - 600์ดˆ ๋‹น 2๋งŒ ๊ฐœ ๋ฉ”์‹œ์ง€ ์†ก์‹  ์ œํ•œ์ด ์žˆ์Œ์„ ๋ชจ๋ฅธ ์ฑ„ ์†ก์‹ ์„ ์‹œ์ž‘ํ•œ ์‹œ์ . 
      ๋นจ๊ฐ• - 600์ดˆ ๋‹น 100๋งŒ ๊ฐœ๋กœ ์„ค์ •ํ•œ ์‹œ์ . ์ผ๋‹จ ํฌ๊ฒŒ ์žก์•˜๊ณ  00์‹œ~02์‹œ์˜ ์ฟผ๋ฆฌ ์œ ์ž…๋„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์„ ์ค„ ์•Œ์•˜์ง€๋งŒ, ์ƒ์ˆ ํ•œ ๋Œ€๋กœ 5๋งŒ ๊ฐœ๊ฐ€ ํ•œ๊ณ„์˜€๋‹ค.
      ํŒŒ๋ž‘ - ์ตœ์ข… ๊ฐ’์ธ 30์ดˆ ๋‹น 2๋งŒ ๊ฐœ๋กœ ์ˆ˜์ •ํ•œ ์‹œ์ 
    • ์œ„ ์Šคํฌ๋ฆฐ์ƒท์—์„œ 28์ผ ์˜คํ›„ ~ 29์ผ ์ƒˆ๋ฒฝ๊นŒ์ง€๋ฅผ ํ™•๋Œ€ํ•œ ๊ฒƒ. ์ € ๋š๋š ๋–จ์–ด์ง€๋Š” ์ˆœ๊ฐ„๋“ค์ด ์„ค์ • ๋ฏธ์Šค๋กœ ์ธํ•ด ๋ฉ”์‹œ์ง€๊ฐ€ ์•ˆ ๊ฐ”๋˜ ๊ธฐ๊ฐ„๋“ค์ด๋‹ค.
  • ๊ด€๋ จ ์›น์‚ฌ์ดํŠธ