Wednesday, November 5, 2008

Set Endian Firewall ส่ง Log ไปเก็บไว้ที่ Log Server

Endian Firewall เวอร์ชั่น 2.2 RC3 ใช้ syslog-ng เป็นตัวจัดการ log ทำให้สามารถส่ง log จากเครื่อง endian ไปยัง Log Server เพื่อจัดเก็บตาม พรบ. ได้อย่างมีประสิทธิภาพเยี่ยม ในบทความนี้จะแสดงวิธีการ config แบบย่อ ๆ โดยมีรูปแบบการจัดวาง server ดังนี้

1. Endian Firewall เป็นตัวกั้นกลางระหว่าง network ภายในกับ internet
2. Router ที่ต่อเข้า internet เป็น ZyXEL 660H ต่อผ่าน RED ของ Endian โดย set เป้น Bridge
3. Log Server ตั้งอยู่ที่ network ภายใน มีหมายเลข IP=192.168.2.249 ใช้ FC9 เป็น OS ใช้ syslog-ng
เป็นตัวจัดการ Log

ในที่นี้้จะกำหนดให้ endian เป็น gateway ของระบบ และเป็นตัวผลิต log กำหนดให้ FC9 เป็น Log Server

..... หลังจากที่ท่านได้ติดตั้ง endian และ FC เสร็จแล้วทุกอยางผ่านหมด server ทั้งสองสามารถคุยกันได้แล้วต่อไปเรามาเริ่ม config โดยเริ่มจากเครื่อง Log Server ก่อน โดยแก้ไขไฟล์ /etc/syslog-ng/syslog-ng.conf ดังนี้

ส่วนที่เพิ่มเติม ตอนท้ายไฟล

# Log from Endian Server
source s_endialserver {
udp(ip("0.0.0.0") port(514));
};

destination d_logserver {
file("/var/log/$R_YEAR$R_MONTH$DAY.log"
owner(root) group(adm) perm(665)
create_dirs(yes) dir_perm(0775));
};

log {
source(s_endianserver);
destination(d_logserver);
};


รูปแบบไฟล์เก็บ log จะมีรูปแบบ 20081103.log คือ ปีเดือนวัน

เสร็จจากเครื่อง log server แล้ว คราวนี้ก็ไป set ที่ endian firewall ต่อกันนะครับ

endian มีการเซ็ต log ผ่าน gui ที่หัวข้อ Logs->Settings แต่ว่าการใช้ gui นี้ยังไม่ประสบความสำเร็จตามที่ประสงค์ได้ จึงได้หันมาใช้การเซ็ตผ่านไฟล์ตรง ๆ ดีกว่าดูเข้าท่าและมีรายละเอียดเยอะดี

เก็บอะไรบ้าง ?
log ที่เราจะให้ endian ผลิตให้และนำไปเก็บไว้ที่ log server ได้แก่
1. Mail : จากใคร ไปถึงใคร หัวข้ออะไร สถานะเป็นอย่างไร โดยเก็บจาก /var/log/maillog
2. Authenticated การใช้ internet เก็บจาก squid
3. เส้นทางการเดินของ data นั้น ๆ เก็บจาก iptables

ขั้นตอน ;
1. ตรวจสอบไฟล์และไดเรกทอรี /etc/syslog/
configuration ในที่นี้คือ syslog.conf
/etc/syslog/syslog.d/
ไฟล์ที่สำคัญคือ firewall.tmp1,squid.tmp1,smtp.tmp1

1. แก้ไข template ไฟลื firewall.tmp1 โดยเพิ่ม
#firewall
destination logserver { udp("192.168.2.249" port(514)); };
destination d_firewall {
file("/var/log/firewall" owner("root") group("nobody") perm(0640));
};
filter f_firewall {
facility(local2);
};
log {
source(s_sys);
filter(f_firewall);
destination(d_firewall);
destination(logserver);};
};
2. แก้ไขไฟล์ squid.tmp1

#squid access
destination logserver {udp("192.168.2.249" port(514));};
destination d_squid_access {
file("/var/log/squid/access.log" owner("root") group("nobody") perm(0640));
};
destination d_squid_access_short {
file("/var/log/squid/access.log_short" template("\\$MSGONLY\n") owner("root") group("nobody") perm(0640));
};
filter f_squid {
facility(local6) and priority(info) and program(squid);
};
log {
source(s_sys);
filter(f_squid);
destination(d_squid_access);
destination(d_squid_access_short);
destination(logserver);};

};

3. แก้ไขไฟล์ smtp.tmp1

#mail
destination logserver { udp("192.168.2.249" port(514)); };
destination d_mail {
file("/var/log/maillog" owner("root") group("nobody") perm(0640));
};
destination d_mail_short {
file("/var/log/maillog_short" template("\\$MSGONLY\n") owner("root") group("root") perm(0640));
};
filter f_filter4 {
facility(mail) and not match('connect from localhost\[127.0.0.1\]');
};
log {
source(s_sys);
filter(f_filter4);
destination(d_mail);
destination(d_mail_short);
destination(logserver);};


Reboot endian firewall หรือจะโหลด /etc/init.d/syslog-ng reload ก้ได้
ลองกลับไปตรวจสอบดู log server ดูควรจะมี log ที่ส่งมาจาก endian server ให้ได้ชมแล้ว....

mrt2514
บ.ไอทีทิปเปิลพลัส จำกัด

0 comments:

Twitter Delicious Facebook Digg Stumbleupon Favorites More