[精讚] [會員登入]
162

[DNS] 把Named 產生的log放到遠端伺服器

把named的log放到log server以符合資安的需求。

分享此文連結 //n.sfs.tw/16378

分享連結 [DNS] 把Named 產生的log放到遠端伺服器@新精讚
(文章歡迎轉載,務必尊重版權註明連結來源)
2024-06-07 01:26:55 最後編修
2024-03-19 16:46:58 By 張○○
 

自動目錄

此例是把named的log放到logserver。

OS

CentOS Linux release 7.4.1708 (Core)   &&
Rocky Linux release 9.3 (Blue Onyx)

修改named.conf

named.conf 在options{} 後加上以下 設定[1]

logging {
.. <部分省略>
         channel lamer-log {
                 file "data/lamer-log" versions 3 size 100m;
                 severity info;
                 print-severity yes;
                 print-time yes;
                 print-category yes;
         };
         channel query-log {
                 file "data/query-log" versions 20 size 100m;
                 severity info;
                 print-severity yes;
                 print-time yes;
                 print-category yes;
         };
...
         category lame-servers { lamer-log; };
         category queries { query-log;};
 };

file "data/lamer-log" versions 3 size 100m;

此範例log檔會存在 /var/named/data/ 的目錄下,檔名會是 lamer-log、 lamer-log.0、 lamer-log.1 共存 3份,每份最大100mb循環寫入

重啟named

# service named restart

 

修改 rsyslog.conf

修改rsyslog.conf [3]

加入模組 imfile

CentOS Linux release 7.4.1708 (Core)

$ModLoad imfile

Rocky Linux release 9.3 (Blue Onyx)

module(load="imfile")

 

新增檔案 /etc/rsyslog.d/named.conf

input(type="imfile" File="/var/named/data/query-log" Tag="ddnss-querylog" Facility="local3" Ruleset="nreporter")
input(type="imfile" File="/var/named/data/lamer-log" Tag="ddnss-lamerlog" Facility="local3" Ruleset="nreporter")
ruleset(name="nreporter"){ action(type="omfwd" Target="192.168.53.147" Port="514" Protocol="udp") }

重啟 rsyslog

# service rsyslog restart

如此就能把LOGS 送到遠端的機器192.168.53.147中。

我是這樣想的,結果LOG SERVER一直沒有收到資料,原來是SELINUX的問題…

 

SELINUX

Selinux 如果不關掉的話,在啟動rsyslog時就會出錯[4]

python: SELinux is preventing in:imfile from read access on the file query-log.#012#012*****  Plugin catchall (100. confidence) suggests   **************************#012#012If you believe that in:imfile should be allowed read access on the query-log file by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'in:imfile' --raw | audit2allow -M my-inimfile#012# semodule -i my-inimfile.pp#012

audit中的錯誤

type=AVC msg=audit(1710820132.783:14087335): avc:  denied  { getattr } for  pid=22562 comm="in:imfile" path="/var/named/data/query-log" dev="dm-0" ino=34444606 scontext=system_u:system_r:syslogd_t:s0 tcontext=system_u:object_r:named_cache_t:s0 tclass=file

AVC stands for Access Vector Cache. [2]

 

依上面的指示下指令

# ausearch -c 'in:imfile' --raw | audit2allow -M my-inimfile
# semodule -i my-inimfile.pp

查看

# audit2allow -a

#============= syslogd_t ==============
#!!!! This avc is allowed in the current policy
allow syslogd_t named_cache_t:file { getattr ioctl open read };

 

以上就能正確的將NAMED產生的LOG傳到LOG SERVER了。

 

參考資料

[1] BIND Queries log to Remote Syslog Server https://www.linuxquestions.org/questions/linux-server-73/bind-queries-log-to-remote-syslog-server-4175669371/

[2] https://wiki.gentoo.org/wiki/SELinux/Tutorials/Where_to_find_SELinux_permission_denial_details

[3] https://www.npartnertech.com/upload/Download/N-Partner_Linux_BIND(DNS)_syslog-TW-004.pdf

[4] https://access.redhat.com/documentation/zh-tw/red_hat_enterprise_linux/6/html/security-enhanced_linux/sect-security-enhanced_linux-selinux_contexts_labeling_files-persistent_changes_semanage_fcontext

 

 

END

你可能感興趣的文章

[Linux] 使用tarball安裝下載PERL的tar檔模組 在Linux下,perl下載的pm模組,不使用cpan的安裝方法

[Centos6 7] 掛載磁碟 只是掛載新磁碟

[bc] linux 的計算機bc 如何計算帶小數點的指數 用 bc 來計算帶小數點的指數,得轉個彎才行

[Centos7] HTTPS/SSL憑證的SELINUX設置 把申請來的憑證檔放到指定的位置後,沒辦法啟動,怎麼辦?

SELinux 常用指令和檔案 在Redhat系列中,Centos5以後加入了selinux,他並沒有這麼可怕,不必每次看到Selinux ,就想把他

[Centos8] 網頁化的系統管理介面 cockpit Centos8 提供一個網頁化的管理介面,稱為駕駛艙,值得一試

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

[Win7] 燒錄 iso 檔 在Windows7 中內建燒錄程式,可以直接把檔案拉到光碟機裡,再執行燒錄。

好用的3+2碼郵遞區號查詢系統推薦 網路上找到用地址輸入判斷3+2碼郵遞區號的辨識率不高,除了這個網站…

詭異的創業思維 創業的思維中,有多少銀彈,有多少技術,有多少人脈,有多少時間等等,每個都要考慮進去,以熱忱建立的關係脆弱的像蘇打餅乾一樣..

海棉寶寶超泡杯演奏的sweet victory 章魚哥和海棉寶寶在超泡杯的演奏歌曲

[PHP]解決ksort新增的SORT_NATURAL|SORT_FLAG_CASE方法 php>=5.4中ksort函數多了SORT_NATURAL 和 SORT_FLAG_CASE 旗標,對舊版的PHP中要怎麼辦?