การ config squid3 ให้เก็บชื่อ hostname ของ client ใน access.log

mrgill   | March 13, 2010   |   351 Views

วันก่อนพี่ที่บริษัทผมโทรมาสอบถามเรื่องโปรเจ็คตัวนึงที่กำลังทำกันอยู่ซึ่งเกี่ยวข้องกับการเก็บ log ไฟล์ของ squid 3 ว่าสามารถทำให้มันเก็บ log ชื่อ hostname + ip ได้ไหมเพราะถ้าเป็นไอพีอย่างเดียว คนที่มีความรู้ด้านไอทีก็สามารถเข้าไปเปลี่ยนไอพีของเครื่อง client ได้ ซึ่งตอนนั้นผมก็ยังไม่มีเวลาศึกษา จนกลับมาจากงานอบรมที่ชัยภูมิก็มานั่งทำการบ้านที่พี่เค้าสั่งมาจนได้คำตอบดังนี้

หากคุณต้องการให้ squid เก็บ log ทั้ง hostname + ip ตามตัวอย่างด่านล้าง

root@proxy:/etc/squid3# tail -f /var/log/squid3/access.log mrgill-laptop 192.168.1.34 - - [13/Mar/2010:23:12:29 +0700] "GET http://imrgill.com/wp-admin/index.php? HTTP/1.1" 200 1008 "http://imrgill.com/wp-admin/index.php?page=stats" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2pre) Gecko/20100311 Ubuntu/9.10 (karmic) Namoroka/3.6.2pre GTB6" TCP_MISS:DIRECT mrgill-laptop 192.168.1.34 - - [13/Mar/2010:23:12:29 +0700] "GET http://imrgill.com/wp-admin/index.php? HTTP/1.1" 200 1780 "http://imrgill.com/wp-admin/index.php?page=stats" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2pre) Gecko/20100311 Ubuntu/9.10 (karmic) Namoroka/3.6.2pre GTB6" TCP_MISS:DIRECT mrgill-laptop 192.168.1.34 - - [13/Mar/2010:23:12:30 +0700] "GET http://imrgill.com/wp-content/plugins/flickr-gallery/flickr-gallery.css? HTTP/1.1" 304 260 "http://imrgill.com/wp-admin/index.php?page=stats" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.2pre) Gecko/20100311 Ubuntu/9.10 (karmic) Namoroka/3.6.2pre GTB6" TCP_REFRESH_UNMODIFIED:DIRECT

ให้คุณตั้งค่า squid3.conf ดังนี้

#เอา # หน้าบรรทัด logformat combined ออกแล้วเพิ่ม %>A เข้าไปหน้า %>a logformat combined %>A %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %h" "%{User-Agent}>h" %Ss:%Sh #กำหนด logformat เป็น combined access_log /var/log/squid3/access.log combined #กำหนด log_ip_on_direct เป็น off log_ip_on_direct off #กำหนด log_fqdn เป็น on log_fqdn on

แต่มีข้อแม้ว่า proxy server ของเราต้อง resolv hostname จาก dns server ของเราได้ด้วยนะครับ หมายถึงต้องมีชื่อเครื่อง client ใน dns server ของเราด้วย ถ้าใครไม่มี dns ก็สามารถ map เครื่องกับไอพีได้เองในไฟล์ /etc/hosts
ตัวอย่าง

127.0.0.1 localhost 127.0.1.1 proxy 192.168.1.34 mrgill-laptop

เสร็จแล้วก็อย่าลืม restart squid3 กันด้วยนะครับ

Category : How to,Linux,Server

Tags: hostname, log, proxy

Random Posts

ภาพบรรยากาศการอบรม Linux Ubuntu ณ โรงพยาลบาลภักดีชุมพล จังหวัดชัยภูมิ Daily Tips : การเปลี่ยนชื่อไฟล์พร้อมกันที่ละหลายๆ ไฟล์

Leave a Comment

(required)

(required), (Hidden)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

TrackBack URL  |  RSS feed for comments on this post.


Chat

Recent Entries

Random Posts

Social Network

Tag Cloud

Calendar

March 2010
S M T W T F S
« Feb   Apr »
 123456
78910111213
14151617181920
21222324252627
28293031  

RSSTwitter: imrgill

RSS LinuxToday

RSS UbuntuClub

RSS Blognone

Tag

ภาษาไทย adobe amsn antivirus apt-get bash chat clip dns emesene entertainment Facebook firefox Forward mail free google graphic grave accent How to howto im install Internet karmic keyboard Linux monitoring msn operating system os Programming recovery Server shell script sms Social network Software themes troubleshooting twitter Ubuntu utility virtualization Windows wine

Categories

Archives

Blogroll

Meta

Get Adobe Flash playerPlugin by wpburn.com wordpress themes