การติดตั้ง radius server ด้วยโปรแกรม freeradius

เป็นคำแนะนำติดตั้งจัดการปรับแต่ง radius server
ต้นแบบทดสอบด้วย linux fedora core 3,2,1 ใช้งานภายในมหาวิทยาลัยสงขลานครินทร์

วิธีติดตั้ง radius server ด้วยโปรแกรม freeradius
*** แหล่งข้อมูลต้นฉบับ freeradius คือ http://www.freeradius.org/

  1. ติดตั้งโปรแกรม freeradius ด้วยคำสั่ง
    apt-get install freeradius
  2. แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
    chkconfig radiusd on
  3. สั่งให้ทำงานด้วยคำสั่งว่า
    /etc/init.d/radiusd start
    Starting RADIUS server: [ OK ]
  4. ตรวจสอบว่าโปรแกรมทำงานแล้วด้วยคำสั่ง
    /etc/init.d/radiusd status
    ได้ผลออกมาดังตัวอย่าง
    radiusd (pid 19180) is running…
  5. แฟ้มที่เกี่ยวข้อง
    • /var/log/radius/radius.log
    • /etc/raddb/radiusd.conf
    • /etc/raddb/clients.conf
  6. เมื่อให้ radiusd ทำงานแล้ว เริ่มขั้นตอนทดสอบระบบโดยป้อนตัวอย่างคำสั่งดังนี้radtest root password-root localhost 0 testing123
    *** จากตัวอย่าง password-root คือรหัสผ่านของ root
    ได้ผลข้อความตอบกลับดังตัวอย่าง
    Sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    Re-sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “{\277\033\t\217\224\n\021\036\271$\301\026\234\353\225”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Reject packet from host 127.0.0.1:1812, id=43, length=20

    แสดงว่าระบบใช้งานได้แล้ว ถึงแม้ว่าจะมีการแจ้งว่า Access-Reject
    เป็นสาเหตุเนื่องจากไม่มีสิทธิในการอ่านแฟ้ม /etc/shadow ของระบบ

  7. หากต้องการให้ใช้กับบัญชีผู้ใช้ระบบ UNIX
    ต้องตั้งค่าให้อ่านแฟ้ม /etc/shadow ได้
    โดยแก้ไขแฟ้ม /etc/raddb/radiusd.conf
    ทำการ comment ยกเลิกบรรทัดข้อความจากเดิม
    user = radiusd
    group = radiusd
    ให้เป็น
    #user = radiusd
    #group = radiusd
    เสร็จแล้วให้ restart ระบบ radiusd ใหม่ด้วยคำสั่ง /etc/init.d/radiusd restart
    ต่อไปลองป้อนตัวอย่างคำสั่งเดิมเพื่อทดสอบดังนี้
    radtest root password-root localhost 0 testing123
    คราวนี้จะได้ผลข้อความว่า
    Sending Access-Request of id 82 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=82, length=20
    โดยมีผลการแจ้งว่า Access-Accept ถูกต้องตามต้องการ
  8. หากต้องการให้ radius client เข้ามาติดต่อใช้งานระบบ radiusd นี้ได้
    ให้แก้ไขแฟ้ม /etc/raddb/clients.conf ให้มีค่าดังตัวอย่างนี้
    client 10.0.1.0/24 {
    secret = mytestkey
    shortname = private-network
    }
    ตัวอย่างคือให้ radius client ที่มีหมายเลข ip 10.0.1.x
    สามารถเข้ามาใช้ด้วย secret key ว่า mytestkey
    เมื่อแก้ไขเสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ลองทดสอบด้วยคำสั่งตัวอย่าง
    radtest root passwordroot 10.0.1.1 0 mytestkey
    *** ค่า passwordroot คือ รหัสผ่านของ root และ 10.0.1.1 คือหมายเลข ip ของ radius server
    ได้ผลแสดงข้อความดังตัวอย่าง
    Sending Access-Request of id 246 to 10.0.1.1:1812
    User-Name = “root”
    User-Password = “passwordroot”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 10.0.1.1:1812, id=246, length=20ถึงขั้นตอนนี้เป็นอันเปิดใช้ระบบ radiusd ได้แล้ว
  9. หากต้องการให้ใช้ได้ดับ LDAP ด้วยให้แก้ไขแฟ้ม /etc/raddb/radiusd.conf
    เพื่อให้รองรับและเชื่อมต่อกับ LDAP server ดังนี้ต้องแก้ไขส่วนของ modules โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    modules {

    ldap {
    **** ให้แก้ไขค่าของ server , basedn ดังตัวอย่าง
    server = “myldap.net”
    basedn = “dc=my, dc=net”
    **** ให้ comment บรรทัด access_attr เพื่อยกเลิกค่า เนื่องจากไม่ได้ใช้รูปแบบนี้
    # access_attr = “dialupAccess”

    *** ในส่วนของ modules แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authorize โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authorize {

    # Read the ‘users’ file
    files
    *** ให้แก้ไขโดยแทรกเพิ่มบรรทัดข้อความว่า ldap ก่อนบรรทัดคำว่า files
    เพื่อให้ระบบทำการลำดับ authorize ด้วยแบบ ldap ก่อน
    หากไม่พบก็จะต่อด้วยแบบ files (แฟ้ม /etc/shadow)
    ถ้ากลับลำดับการ authorize อาจพบปัญหาผิดพลาดได้
    ดังตัวอย่างหลังการแทรกเพิ่มข้อความ
    # Read the ‘users’ file
    ldap
    files
    *** ในส่วนของ authorize แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authenticate โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authenticate {

    # Auth-Type LDAP {
    # ldap
    # }
    *** ให้แก้ไขด้วยการ uncomment บรรทัดข้อความเพื่อให้ระบบกำหนดวิธี LDAP
    Auth-Type LDAP {
    ldap
    }
    *** ในส่วนของ authenticate แก้ไขเพียงแค่นี้

    เสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ทดสอบใช้งานได้เลย

  10. แนะนำให้ยกเลิกการกำหนดค่าการทำงานบางตัวที่ไม่ได้ใช้งาน
    โดยการ comment บรรทัดข้อความในแฟ้ม /etc/raddb/radiusd.confถ้าไม่ได้ใช้เป็น proxy radius ควรยกเลิก
    โดยเปลี่ยนจากเดิม proxy_requests = yes
    ให้เป็น proxy_requests = no

    ควรยกเลิกบาง authorize ที่ไม่ได้ใช้เช่น
    authorize {
    # preprocess
    # chap
    # mschap
    # suffix
    # ldap —> ระบบ ldap
    # files –> ระบบ UNIX หรือแฟ้ม /etc/shadow

  11. การแสดงผลรายงานจำเป็นต้องหาโปรแกรมมาต่างหาก
    ขอแนะนำตัวอย่างโปรแกรมแสดงผลรายงาน

    • ต้นแหล่งข้อมูลคือ http://www.tummy.com/radiusContext/
      สามารถได้ดาวน์โหลดโปรแกรมได้ที่
      ftp://ftp.psu.ac.th/pub/freeradius/radiusContext-1.93.tar.gz
    • ให้ดาวน์โหลดมาแล้วขยายแฟ้มเก็บไว้ที่ /root ด้วยตัวอย่างคำสั่ง
      tar -C /root -zxvf radiusContext-1.93.tar.gz
    • สร้าง directory สำหรับแสดงผลบนเวบ ดังตัวอย่างคือ
      mkdir /var/www/html/radiusreport
      จะแสดงผลบนโฮมพจ http://x.x.x.x/radius-report
    • ตัวอย่าง ขั้นตอนที่ใช้สำหรับประมวลผลรวมข้อมูลจาก
      /var/log/radius/radacct ไปเก็บไว้เพื่อแสดงผลที่ /var/www/html/radius-report
      *** ภายใน /var/log/radius/radacct จะแยกเก็บข้อมูลเป็น directory ของ
      แต่ละหมายเลข ip ทำให้อาจยุ่งยากต่อการรวบรวมข้อมูล/root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
      /root/radiusContext-1.93/stdreport -D /var/www/html/radius-report

      *** ต้องใช้คำสั่งเหล่านี้ทุกครั้งเพื่อปรับปรุงผลรายงาน

    • ทดสอบผลรายงานได้เลยที่ http://x.x.x.x/radius-report

ที่มา:  http://zeous21.exteen.com/20050919/radius-server-freeradius

การติดตั้ง chillispot, FreeRadius, syslog-ng บน ubuntu เพื่อทำตาม พรบ.ตอมพิวเตอร์

การติดตั้ง chillispot, FreeRadius, syslog-ng บน ubuntu เพื่อทำตาม พรบ.ตอมพิวเตอร์

ดัดแปลงโดย อดิศร  ขาวสังข์
ดัดแปลงจาก คู่มือประกอบการฝึกอบรมเชิงปฏิบัติการ “การติดตั้ง Authentication” ของ SiPA และ ATSI (http://61.7.253.244/syslog-ng/)
จัดทำเมื่อ 20/11/2008
ทดลองบน Ubuntu 8.04, Ubuntu 8.10
บทนำ
ท่านที่เคยไปพักตามโรงแรมหรือสถานที่ท่องเที่ยว/จุดพักเิดินทาง ฯลฯ คงเคยเห็นมีบริการ Wi-Fi และมีการขายบัตรอินเตอร์เ้น็ต หลาย ๆ ที่ดังกล่าว ได้นำเอาโปรแกรม chillispot และ FreeRaDius ไปประยุกต์ใช้งาน  นั่นคือเมื่อเราเชื่อมต่อ Wi-Fi ได้แล้ว พอเข้าเว็บไซต์ก็จะมีหน้าต่างให้เราป้อน username และ password ก่อนจึงจะใช้งานได้

ในสถานการณ์ปัจจุบัน  พรบ.คอมพิวเตอร์ 2550 ได้บังคับใช้งานแ้ล้ว  เราสามารถนำเอาโปรแกรม chillispot, FreeRadius, syslog-ng มาประยุกต์ใช้งานให้เข้ากับ พรบ.ได้ เพราะ พรบ.ได้ระบุว่า ผู้ให้บริการจะต้องสามารถระบุตัวตนของผู้ใช้งานได้ พร้ออมเก็บข้อมูลการจราจรคอมพิวเตอร์ไม่น้อยกว่า 90 วัน ซึ่ง chillispot + freeradius + syslog-ng สามารถที่จะช่วยได้  ไม่เว้นแ่ต่ plawan centralized log ก็ได้นำซอฟต์แวร์ชุดนี้มาใช้งานเช่นกัน

การติดตั้งในที่นี้เป็นการติดตั้งตามรูปคอนฟิกข้างล่าง  โดยติดตั้ง FreeRadius และ syslog-ng ไว้บน Server ที่วางอยู่ในตำแหน่ง DMZ และติดตั้ง Chillispot ให้ทำหน้าที่เป็น Authentication Gateway ไ้ว้ในตำแน่ง Internal  ซึ่งจะเห็นว่าถ้าเป็นเครือข่ายขนาดใหญ่ และมีหลาย Internal Network ก็สามารถใช้ FreeRadius และ syslog-ng ร่วมกันได้  โดยส่วนประกอบของ chillispot ก็ประกอบด้วย dhcp, firewall, และ nat อยู่ในตัว การทำงานของ chillispot จะต้องทำงานร่วมกับ FreeRadius ซึ่งวิธีการติดตั้ง FreeRadius ดูได้ ที่นี่ โดยในที่นี้ผู้เขียนติดตั้ง chillispot บน ubuntu 8.10 ส่วน FreeRadius ติดตั้งบน ubuntu 8.04 (ไม่ใช้ ubuntu 8.10 เพราะเจอปัญหาบางอย่างที่้ัยังแก้ไม่ได้)

หมายเหตุ FreeRadius, chillispot และ syslog-ng สามารถติดตั้งในเครื่องเดียวกันได้  ซึ่งจะเหมาะสมกับหน่วยงานขนาดเล็ก ด้วยการปรับค่าคอนฟิกบางส่วน
ขั้นตอนการติดตั้ง Freeradius
การติดตั้ง Freeradius สำหรับวิธีการของผู้เขียนดูวิธีได้ ที่นี่

โดยบนเครื่อง FreeRadius จะต้องมีการคอนฟิกอนุญาตให้เข้าไปใช้งาน FreeRadius ที่ไฟล์ /etc/freeradius/client.conf ดังนี้
client 172.24.51.16 {
secret = radiussecret
shortname = chilli
}

จากค่า client ข้างบนอาจจะมีการสงสัยกันว่าทำไม่อนุญาต IP 172.24.51.252 เข้าไปใช้งาน  คำตอบก็คือว่าที่ Firewall มีการทำ NAT ระหว่าง Internal กับ DMZ ดังนั้น IP ที่ส่งไปยัง FreeRadius จึงเป็น IP ของ Firewall ฝั่ง Internal คือ 172.24.51.16

ในการติดตั้งใช้งาน ที่ Firewall ต้องทำให้เครื่อง Authentication Gateway สามารถเชื่อมต่อไปยังเครื่องที่เป็น FreeRadius ได้  ไม่นั้นก็จะไม่สามารถติดตั้ง FreeRadius ได้
ขั้นตอนการติดตั้ง chillispot บนเครื่อง Authentication Gateway
เซ็ตค่า Network

  1. ทำการ Enable packet forwarding ด้วยการแก้ไขไฟล์ /etc/sysctl.conf ด้วยการเอาเครื่องหมาย # หน้าคำว่า net.ipv4.ip_forward=1 ออก เพื่อสั่งให้ packet forwarding ของ ipv4 ทำงาน
  2. ทำการรันคำสั่งต่อไปนี้  เพื่อให้มีผลทันที  ให้เครื่องสามารถ forward packet ทำตัวเป็นเราเตอร์ได้
    echo 1 | tee /proc/sys/net/ipv4/ip_forward
    ถ้าผลที่ได้เป็น 1 ถือว่าทำการ Enable packet forwarding สำเร็จ
  3. ทำการ Restart network ด้วยคำสั่งต่อไปนี้
    sysctl -p
    /etc/init.d/networking restart

Enable TUN/TAP device driver support

  1. ทำการ Enable TUN/TAP device drive support ด้วยการเพิ่มคำว่า tun ต่อท้ายไฟล์ /etc/modules
  2. จากนั้นทำการ Enable โดยไม่ต้อง reboot ด้วยการรันคำสั่งต่อไปนี้
    modprobe tun

Install Chillispot
โปรแกรม chillispot เป็น Opensource ที่ใช้ติดตั้งบน Gateway Server เพื่อทำหน้าที่ควบคุมการใช้งานของ user ที่วิ่งผ่านให้มีการป้อน username และ password ก่อนจึุงจะใช้งานได้ ซึ่งจะทำงานร่วมกับโปรแกรม Radius ซึ่งทำหน้าที่บริหารจัดการฐานข้อมูลของ user โดยโปรแกรม chillispot กับ FreeRadius อาจจะติดตั้งอยู่บนเครื่องเดียวกันหรือต่างเครื่องกันได้
การติดตั้ง chillispot จะต้องใช้การ์แลน 2 การ์ด ซึ่งมีขั้นตอนต่อไปนี้

  1. ทำการติดตั้ง chillispot โดยใ้้ช้คำสั่งต่อไปนี้
    apt-get install chillispot
    จากนั้นให้เติมรายละเอียดดังต่อไปนี้
    IP address of radius server 1:
    127.0.0.1(ของผู้เีขียนชี้ไปยัง Freeradius ซึ่งอยู่อีกเครื่องจึงกำหนดเป็น 192.168.9.12)
    Radius shared secret:
    radiussecret   (ค่านี้ต้องตรงกับ Radius Server)
    Ethernet interface for DHCP to listen:
    eth1
    URL of UAM server:
    https://192.168.182.1/cgi-bin/hotspotlogin.cgi  (เปลี่ยนเป็นค่าอื่นได้)
    URL of UAM homepage:
    https://192.168.182.1/welcome.html
    Shared password between chillispot and webserver:
    uamsecret
  2. ต่อไปทำการแก้ไขไฟล์ /etc/default/chillispot เพื่อ Enable captive portal ด้วยการกำหนดค่าให้
    ENABLED=1
  3. ทำการแก้ไขไฟล์คอนฟิกของ chillispot คือไฟล์ /etc/chilli.conf โดยค่าที่สำคัญมาจากขั้นตอนของการติดตั้งที่ได้ทำมาแล้ว  และให้แก้ไขค่าให้เหมาะสม ดังต่อไปนี้
    net 192.168.182.0/24
    dns1 61.19.253.134
    dns2 61.19.253.136
    radiusserver1 127.0.0.1 (ของผู้เีขียนเป็น 192.168.99.12)
    radiusserver2 127.0.0.1 (ของผู้เีขียนเป็น 192.168.99.12)
    radiussecert radiussecret
    dhcpif eth1
    uamserver https://192.168.182.1/cgi-bin/hotspotlogin.cgi
    uamhomepage https://192.168.182.1/welcome.html
    uamsecret uamsecret
    uamlisten 192.168.182.1
    uamallowed www.google.co.th,192.168.182.0/24โดยค่าของ dns ต้องสามารถใช้งานได้จริง เพราะเป็นค่าที่จะต้องจ่ายให้กับเครื่อง Client

ติดตั้ง Firewall สำหรับ Chillispot
chillispot จะต้องมีการติดตั้ง Firewall (iptables) เพื่อกำหนดให้แพ็กเกตของข้อมูลจากเครื่อง Client ที่วิ่งผ่าน  ต้องผ่าน Service ที่เป็น chillispot เพื่อให้ Client ทุกคนต้องมีการป้อน username และ password ก่อนถึงจะใช้งานได้  โดย Firewall ของ Chillspot จะมีมาให้แล้วกับการติดตั้ง ซึ่งมีขั้นตอนการนำมาใช้ดังต่อไปนี้

  1. ทำการกำหนด firewall โดยทำการสร้างไฟล์ chilli.iptables ด้วยการคัดลอกมาจากไฟล์ firewall.iptables ที่มากับ chillispot ไปไว้ในตำแหน่ง /etc/init.d ด้วยคำสั่งดังนี้
    cp /usr/share/doc/chillispot/firewall.iptables /etc/init.d/chilli.iptables
  2. กำหนดให้ไฟล์ chilli.iptables สามารถ execute ได้ด้วยคำสั่ง
    chmod a+x /etc/init.d/chilli.iptables
  3. กำหนดให้กฎ firewall มีการ start ทุกครั้งเมื่อมีการเิปิดเครื่องด้วยคำสั่ง
    ln -s /etc/init.d/chilli.iptables /etc/rcS.d/S41chilli.iptables
  4. โดยค่าดีฟอลต์ไฟร์วอลล์จะทำการกำหนดค่าให้ eth0=internet, eth1= LAN แต่ถ้าคุณต้องการเปลี่ยนค่าก็สามารถเปลี่ยนแปลงได้
  5. หากต้องการให้เครื่องลูกสามารถทดสอบการเชื่อมต่อโดยใ้ช้โปรโตคอล ICMP หรือ ping ได้ ให้เพิ่มกฎของ iptables ดังนี้
    #Allow ping to myserver
    SERVER_IP=”192.168.182.1″
    iptables -A INPUT -p icmp –icmp-type 8 -s 0/0 -d $SERVER_IP -m state –state NEW,ESTABLISHED,RELATED -j ACCEPT
    iptables -A OUTPUT -p icmp –icmp-type 0 -s $SERVER_IP -d 0/0 -m state –state ESTABLISHED,RELATED -j ACCEPT
  6. ทำการ Enable firewall script ด้วยคำสั่ง
    /etc/init.d/chilli.iptables

ติดตั้ง Apache และ PHP

  1. ติดตั้ง Apache Web Server ด้วยคำสั่ง
    apt-get install apache2
  2. start apache ด้วยคำสั่ง
    /etc/init.d/apache2 start
  3. ตรวจสอบว่า apache ทำงานหรือไม่ด้วยคำสั่ง
    netstat -lnt
    ถ้าทำแล้วจะต้องมีคำว่า
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
  4. ติดตั้ง PHP5 ด้วยคำสั่ง
    apt-get install php5
  5. restart apache ด้วยคำสั่ง
    /etc/init.d/apache2 restart

สร้างหน้าต่าง Login

  1. โดยปกติตำแหน่งที่เป็น ScriptAlias /cgi-bin/ ของ apache จะอยู่ที่ /usr/lib/cgi-bin/
  2. ให้ทำการเปลี่ยนไดเร็กทอรีเข้าไปยังตำแหน่งดังกล่าวแล้วใ้ช้ีคำสั่ง ls จะเห็นชื่อไฟล์ชื่อว่า hotspotlogin.cgi ซึ่งเป็นไฟล์ที่ถูกสร้างขึ้นในขั้นตอนการติดตั้ง chillispot
  3. ทำการแก้ไขไฟล์ดังกล่าวโดยให้เอาเครื่องหมาย # หน้าคำว่า $uamsecret และ $userpassword ออกและำกำหนดค่าเป็นดังนี้
    $uamsecret = “uamsecret”;
    $userpassword=1;
  4. เมื่อแก้ไขเสร็จแล้วทำการ restart chillispot ด้วยคำสั่ง
    /etc/init.d/chillispot start
  5. ทำการสร้างไฟล์ welcome.html ด้วยคำสั่ง
    vim /var/www/welcome.html
  6. ทำการเพิ่มข้อความต่อไปนี้ลงไปในไฟล์ welcome.html
    <html>
    <head><title> Welcome to Our Hotspot, Wireless Network </title></head>
    <body>
    <center>
    <H1><font color=”red”>TESTING ONLY</font></H1>
    <img src=”chillispot.png”>
    <H3><font color=”blue”>Welcome to Our Hotspot, Wireless Network.</font></H3>
    <p>You are connected to an authentication and restricted network access point.
    <H3><a href=”http://192.168.182.1:3990/prelogin”>Click here to login</a></H3>
    <p>
    <p>Enjoy.
    </center>
    </body>
    </html>
  7. ถ้าต้องการรูป chillispot.png ให้ทำการดาว์นโหลดโดยใช้คำสั่ง
    wget http://mamboeasy.psu.ac.th/~wiboon.w/images/stories/chillispot/chillispo…
    cp chillispot.png /var/www

เซ็ตอัพ SSL

  1. ติดตั้ง SSL โดยใช้คำสั่งต่อไปนี้
    apt-get install ssl-cert
  2. สร้างไดเร็กทอรี่ขึ้นมาเพื่อเก็บ Certificate ที่ถูกสร้างขึ้น โดยใช้คำสั่ง
    mkdir /etc/apache2/ssl
  3. ทำการสร้าง self-signed cerfiticate ด้วยคำสั่งดังต่อไปนี้
    make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
  4. แล้วจะถูกถามคำถามต่าง ๆ แต่ใน ubuntu 8.10 อาจจะถามแค่ hostname
    Country Name : ป้อน TH
    State or Province Name : ป้อนจังหวัด
    Locality Name : ป้อนชื่อที่เหมาะสม
    Organization : ป้อนชื่อองค์กร
    hostname   :  localhost (ควรจะใช้ hostname ที่เป็นจริง ของผู้เขียนแค่ทดลอง)
    Email : ป้อนอีเมล์
  5. ทำการ install module ssl ด้วยคำสั่ง
    a2enmod ssl
  6. ให้รันคำสั่งต่อไปนี้เพื่อ active new configuration
    /etc/init.d/apache2 restart
  7. สร้าง virtual host ชื่อ hotspot ขึ้นมาด้วยคำสั่งต่อไปนี้
    vim /etc/apache2/sites-available/hotspot
  8. เพิ่มข้อความต่อไปนี้ลงไปในไฟล์
    NameVirtualHost 192.168.182.1:443
    <VirtualHost 192.168.182.1:443>
    ServerAdmin adisorn.k@cattelecom.com
    DocumentRoot “/var/www”
    ServerName “192.168.182.1”
    <Directory “/var/www/”>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory “/usr/lib/cgi-bin/”>
    AllowOverride None
    Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    </Directory>
    ErrorLog /var/log/apache2/hotspot-error.log
    LogLevel warn
    CustomLog /var/log/apache2/hotspot-access.log combined
    ServerSignature On
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/apache.pem
    </VirtualHost>
  9. ทำการ Enable SSL VirtualHost ด้วยคำสั่งต่อไปนี้
    a2ensite hotspot
  10. ทำการ reload apache ด้วยคำสั่ง
    /etc/init.d/apache2 reload
  11. การ Listen port ของ https (SSL) โดย default จะเป็นพอร์ต 443 ให้ทำการแก้ไขค่าคอนฟิกที่เกี่ยวกับ port ของ SSL ที่ไฟล์ /etc/apache2/ports.conf ให้มีค่าเป็นดังนี้ 
  12. เปลี่ยนแปลงค่าให้มีการ Listen port ที่เป็น default http (80) ด้วยการแก้ไขไฟล์ /etc/apache2/site-available/default โดยให้มีโครงสร้างของ VirtualHost เป็นดังนี้
    NameVirtualHost *:80
    <VirtualHost *:80>


    </VirtualHost>
  13. ทำการกำหนดค่า ServerName ในไฟล์ /etc/apache2/apache2.conf ให้มีค่าดังนี้
    ServerName  192.168.182.1  (ของผู้เขียนไม่ได้กำหนดค่านี้ก็ทำงานได้)
  14. ทำการ restart apache ด้วยคำสั่ง
    /etc/init.d/apache restart
  15. เืมื่อเอาเครื่อง client มาเชื่อมใช้งานหลังเครื่อง Authentications Gateway ก็ได้จะรับ IP address ที่ Authentications Gateway จ่ายมาให้โดย ค่า Gateway IP ที่ได้ เป็นค่าที่ชี้ไปยัง Authentication Server ดังนั้นเมื่อเปิดใ้ช้งาน Browser ตัว Authentication Gateway จะบังคับให้มีการ Redirect ไปยัง https ดังรูป ให้คลิ๊กที่คำว่า Continue to this website (not recommended) 
  16. จากนั้นจะได้หน้าต่างแจ้งข้อมูลดังรูป ให้คลิ๊กที่ Link –> Click Here to login 
  17. จากนั้นจะได้หน้า่ต่างให้ป้อน username และ password ดังรูป 
  18. ถ้า Login ถูกต้องจะได้ผลดังรูป

กรณีที่ต้องการบังคับให้ผู้ใช้งานเว็บต้องใช้งานผ่าน Proxy ต้องทำดังขั้นตอนต่อไปนี้

  1. ติดตั้ง squid ด้วยคำสั่ง
    apt-get install squid
  2. แก้ไขไฟล์คอนฟิกของ squid คือไฟล์ /etc/squid/squid.conf ดังนี้
    1. เอาเครื่องหมาย # ไปไว้หน้าคำว่า http_port 3128 เพื่อกำหนดให้เป็นคอมเมนต์
    2. หาข้อความว่า # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS แล้วข้อความเพิ่มเติมอีก 3 บรรทัดต่อไปนี้
      acl chillispot src 192.168.182.0/255.255.255.0
      http_port 192.168.182.1:3128 transparent
      http_access allow chillispot
      คำอธิบาย
      # http_port 3128  เป็นการยกเลิกการทำงานของโปรแกรมแบบไม่ทำ transparent
      visible_hostname ต้องกำหนดชื่อเครื่องให้ระบบ หากไม่กำหนด  อาจมีปัญหาในการ start service
      acl chillispot src เป็นการกำหนดค่าเน็ตเวิร์กของเครือข่ายที่จะอนุญาตให้ใช้งานผ่านโปรแกรม Squid
      http_port x.x.x.x.3128 transparent เป็นการกำหนดให้พอร์ต 3128 เป็น transparent proxy
      http_access allow กำหนดค่า Access Control ให้เน็ตเวิร์ควง chillispot สามารถใช้งานผ่าน transparent proxy ได้
    3. หาคำว่า visible_hostname แล้วใส่ชื่อหลังคำดังกล่าวเช่น
      visible_hostname myproxy
  3. สั่งให้โปรแกรม squid ทำงานด้วยคำสั่ง
    /etc/init.d/squid start
  4. ทำการส่งต่อ packet ที่เข้ามาทางพอร์ต 80 ไปยัง squid พอร์ต 3128 ด้วย คำสั่ง iptables โดยเพิ่มในไฟล์ /etc/init.d/chilli.iptables ดังนี้
    iptables -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 80 -j REDIRECT –to-ports 3128
  5. ทำการอนุญาตให้ใช้งาน INPUT ที่เป็น syn flag ดังนี้
    iptables -A INPUT -i tun0 -p tcp -m tcp –dport 3128 –syn -j ACCEPT
  6. ต้องเิพิ่ม rule ต่อไปนี้เพื่อป้องกันการเ้้ข้าใช้งานระบบโดยการแอบตั้งค่า proxy เอง
    iptables -t nat -I PREROUTING -p tcp -m tcp –dport 3128 -j DROP

การจัดการเรื่อง Log
การจัดการเรื่อง Log ในที่นี้จะเลือกข้อมูลการจราจรที่สำคัญจากเครื่องที่เป็น Authentication Gateway และ Log ของ Server อื่น ๆ (ถ้ามี) ส่งไปยังเครื่อง Centralized Log Server เหตุผลที่เรามีการคัดเฉพาะส่วนที่ำจำเป็นก็คือ เพื่อไม่ให้ปริมาณทราฟฟิกของข้อมูลการจราจร ทำให้การใช้งานระบบเครือข่ายคอมพิวเตอร์ช้าลง หรือเปลืองแบนด์วิดธ์ของระบบ

สำหรับเซอร์วิสที่สำคัญที่จะ้ต้องส่งต่อข้อมูลการจราจรคอมพิวเตอร์ได้แก่ squid และ radius ขณะเดียวกันเราจะต้องใช้หลักการของ IPTABLES เพื่อทำการคัดเลือกข้อมูลเบื้องต้นสำหรับการใช้งานผ่านพอร์ตต่าง ๆ ที่เป็นเซอร์วิสพื้นฐานเพื่อจัดเก็บข้อมูลการจราจรคอมพิวเตอร์ เช่น http, https, ftp, smtp, imap, pop3, IM เป็นต้น

Install Time Server
ด้วย พรบ.ได้กำหนดว่าต้องตั้งนาฬิกาของอุปกรณ์บริการทุกชนิดให้ตรงกับเวลาอ้างอิงสากล (Stratum0) ซึ่งเราควรจะติดตั้ง NTP Server ไว้บน Server เครื่องใดเครืองหนึ่ง  ซึ่งในที่นี้เลือกเครื่องที่เป็น Log Server เพื่อกระจายสัญญาณนาฬิกาให้กับเครื่อง Server และเครื่อง Workstation อืน ๆ ทั้งหมดในระบบเป็นลำดับที่ 1 ส่วนลำดับที่ 2 และ 3 ให้อ้างอิงไปยังฐานฐานเวลาภายนอก โดยรูปแบบการอ้างอิงฐานเวลาเป็นดังรูปข้างล่าง

รูปแสดงการอ้างอิงฐานเวลา

ส่วนตารางข้างล่างเป็นการอิงเวลามาตรฐานของประเทศไทย

ตารางแสดงการอิงเวลามาตรฐานของประเทศไทย

ขั้นตอนการติดตั้ง NTP Server ที่เครื่อง Log Server เป็นดังนี้

  1. ติดตั้ง ntp ด้วยสั่ง
    apt-get instal ntp
  2. ทำการสำเนาไฟล์คอนฟิกของ ntp ไปไว้เป็นอีกชื่อดังนี้
    cp /etc/ntp.conf /etc/ntp.conf.bak
  3. แก้ไขไฟล์ /etc/ntp.conf ให้มีค่าเป็นดังนี้
    restrict default kod nomodify notrap noquery nopeer
    restrict 127.0.0.1
    # อนุญาตให้ Internal network เข้าใช้งาน
    restrict 172.24.51.0 mask 255.255.255.0 nomodify notrap
    server 203.185.69.60 dynamic
    server time.navy.mi.th dynamic
    server time.nist.gov dynamic
    server 127.127.1.0 # local clock
    fudge 127.127.1.0 stratum 10
    driftfile /var/lib/ntp/ntp.drift
    broadcastdelay 0.008
    keys /etc/ntp/keys
  4. ตรวจสอบ Remote Server ที่ต้องการใช้อ้างอิงฐานเวลา ใช้คำสั่งดังนี้
    apt-get install ntpdate
    ntpdate -b 203.185.69.60
    ntpdate -b time.navy.mi.th
    ntpdate -b time.nist.gov
  5. สั่ง restart service ด้วยคำสั่ง
    /etc/init.d/ntp restart
  6. หลังจากที่ Server ทำงานปกติไม่มีการแจ้ง error ใด ๆ สามารถตรวจสอบตารางการทำงานของ Server ด้วยคำสั่ง
    ntpq -pn
    ซึ่งจะได้ผลดังนี้remote                     refid       st    t    when   poll     reach   delay     offset     jitter
    ================================================================
    203.185.69.60         .INIT.    16    u     –            64       0      0.000    0.000    0.000
    118.175.67.83         .INIT.    16    u     –            64       0      0.000    0.000    0.000
    192.43.244.18         .INIT.    16    u     –            64       0      0.000    0.000    0.000
    127.127.1.0             .LOCL. 10     l    54           64      7       0.000    0.000    0.001
  7. สามารถใช้เครื่อง Linux เครื่องอื่นในระบบทดสอบการทำงานของ Server ได้ด้วยคำสั่ง
    ntpdate <ip address> ใส่ ip address ของเครื่อง NTP Server

ขั้นตอนการติดตั้ง NTP Server ที่เครื่อง Server เครื่องอื่น (NTP client) เป็นดังนี้

  1. ติดตั้ง ntp ด้วยสั่ง
    apt-get instal ntp
  2. ทำการสำเนาไฟล์คอนฟิกของ ntp ไปไว้เป็นอีกชื่อดังนี้
    cp /etc/ntp.conf /etc/ntp.conf.bak
  3. แก้ไขค่าคอนไฟล์ของเครื่อง Linux Server อื่น ๆ ที่ไฟล์ /etc/ntp.conf ดังนี้
    server 192.168.9.12  ## ip address ของ NTP Server
    restrict 127.0.0.1
    driftfile /var/lib/ntp/ntp.drift

หมายเหตุ : สำหรับการทำ NTP Server จะมีการใช้งานโปรโตคอล NTP ซึ่งทำงานที่ port 123 ดังนั้นต้องดูเรื่องของ Firewal ให้เปิด port ดังกล่าวด้วย
การติดตั้ง syslog-ng ที่ centralized log

  1. ติดตั้ง syslog-ng ด้วยคำสั่ง
    apt-get install syslog-ng
  2. สำเนาไฟล์คอนฟิกของ syslog-ng คือไฟล์ /etc/syslog-ng/syslog-ng.conf ด้วยคำสั่ง
    cp /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf.bak
  3. แ้ำก้ไขค่าคอนฟิกในไฟล์ /etc/syslog-ng/syslog-ng.conf ตามความเหมาะสม  ซึ่งในที่นี้ให้แก้ไขค่าในส่วนของ options ซึ่งมีโครงสร้างเป็นดังนี้
    options {
    – – – – –
    – – – – –
    – – – – –
    }
    โดยให้เพิ่มข้อความต่อไปนี้ลงไปในส่วนของ options เพื่อให้ syslog-ng ทำการเก็บชื่อ hostname ของเครื่องที่ส่ง log เข้ามา
    keep_hostname (yes);
  4. จากรูปเครือข่ายของผู้เขียนจะเห็นว่าโปรแกรม Freeraius ติดตั้งอยู่ีที่เดียวกับเครื่อง Centralized log ซึ่งปกติแล้ว detail file ซึ่งเป็นไฟล์ที่เก็บข้อมูลการ Login เข้าใช้งานโปรแกรม Freeradius จะอยู่ในตำแหน่ง /var/log/freeradius/radacct/ipaddress_of_client/detail-Ymd โดยค่า Ymd คือ Year month day ซึ่งชื่อไฟล์จะมีการแปรเปลี่ยนตามปีเดือนวัน ฉะนั้นถ้าต้องการให้สามารถส่ง detail file ดังกล่าวไปยัง syslog ได้  เราจะต้องทำการเปลี่ยนชื่อไฟล์ดังกล่าวให้มีชื่อที่คงที่คือไม่มีปีเดือนวัน  ด้วยการเปลี่ยนตัวแปร detailfile ในไฟล์ /etc/freeradius/radiusd.conf ดังนี้
    ให้เปลี่ยนค่า detailfile = ${radacctdir}/%{Client-IP-Address}/detail-%Y%m%d  เป็น
    detailfile = ${radacctdir}/%{Client-IP-Address}/details
    หมายเหตุ ถ้าไม่ต้องการส่ง freeradius detail file ไปยัง syslog ก็ไม่ต้องทำขั้นตอนนี้
  5. เพิ่ม log rotate ของ freeeradius ในส่วนของ detail file เื่ืพื่อแก้ปัญหาขนาดไฟล์ที่อาจจะใหญ่เกินไป ด้วยการเพิ่มข้อมูลต่อไปนี้ไปต่อท้ายของไฟล์ /etc/logrotate.d/freeradius/var/log/radius/radacct/172.24.51.16/details {
    rotate 13
    weekly
    missingok
    notifempty
    compress
    }
    หมายเหตุ ค่า 172.24.51.16 เป็น IP address ของเครื่อง client ที่เข้ามาใช้งาน freeradius server ซึ่งจากรูปคือเครื่อง 172.24.51.252 แต่มีการใช้งานผ่าน firewall ที่มีการทำ nat จึงต้องเปลี่ยนค่า IP เป็น 172.24.51.16
  6. สั่งให้มีการส่งขอมูลของ freeradius server ซึ่งในที่นี้คือ detail file ดังที่กล่าวมาไปยัง syslog-ng agent ด้วยการสร้างไฟล์ขึ้นมาหนึ่งไฟล์ในที่นี้คือ /etc/init.d/rc.capture และให้ป้อนข้อมูลต่อไปนี้เข้าไปในไฟล์
    #!/bin/bash
    tail -F /var/log/radius/radacct/127.0.0.1/details | logger -t freeradius -p local3.info&
  7. จากนั้นสั่งให้สามารถรันได้และสร้าง Link ให้ทำงานทุกครั้งหลังเิปิดเครื่องด้วยคำสั่ง
    chmod a+x /etc/init.d/rc.capture
    ln -s /etc/init.d/rc.capture /etc/rcS.d/S88rccapture
  8. ซึ่งเมื่อเราไปเปิด log file ของ syslog-ng (/var/log/syslog) ก็จะเห็นค่าของการ login เข้าใช้งาน freeradius เหมือนกับค่าในไฟล์ detail file ของ freeradius ดังรูป

การติดตั้ง syslog-ng ที่เครื่อง Authentication Gateway

  1. ติดตั้ง syslog-ng ด้วยคำสั่ง
    apt-get install syslog-ng
  2. กำหนดให้เครื่อง Authentication Gateway ส่ง log ไปยัง Centralized log ด้วยการเพิ่มเติมค่าคอนฟิกในไฟล์ /etc/syslog-ng/syslog-ng.conf ดังนี้
    destination remote {
    udp(“192.168.9.12” port(514));
    };
    log {source(s_all); filter(f_messages); destination(remote); };
    log {source(s_all); filter(f_kern); destination(remote); };สคริปต์ข้างบนเป็นการส่ง log ไปยังเครื่อง 192.168.9.12
  3. ทำการส่งค่า log ของ squid (/var/log/squid/access.log) ไปยัง syslog-ng agent ซึ่งก็คือส่งไปยัง syslog-ng agent ของเครื่องตัวเอง และหลังจากนั้น syslog-ng agent ในเครื่องตัวเองก็จะส่งต่อไปยัง remote syslog ต่อไป  โดยการส่งมี 2 วิธีคือ
    วิธีที่ 1 ส่ง log ของ squid ที่เก็บไว้ในไฟล์ /var/log/squid/access.log ในลักษณะที่สำเนาต่อไปยังยังเครื่อง centralized log ซึ่งทำได้ดังนี้

    1. ด้วยการสร้างไฟล์หนึ่งไฟล์ในที่นี้ชื่อว่า /etc/init.d/rc.capture และมีข้อความในไฟล์ดังนี้
      #!/bin/bash
      tail -F /var/log/squid/access.log | logger -t squid -p local3.info
    2. จากนั้นสั่งให้สามารถรันได้และสร้าง Link ให้ทำงานทุกครั้งหลังเิปิดเครื่องด้วยคำสั่ง
      chmod a+x /etc/init.d/rc.capture
      ln -s /etc/init.d/rc.capture /etc/rcS.d/S88rccapture
    3. เมื่อเราไปเิปิดดู log ที่ไฟล์ /var/log/syslog ของเครื่อง Centralized log จะได้ Log ของ squid ดังรูปรูปแสดง Log ของ squid บนเครื่อง Centralized Log

    วิธีที่ 2 ส่ง log ของ squid ไปยังเครื่อง Centralized log โดยไม่มีการเก็บ squid log (/var/log/squid/access.log) ไว้ในเครื่องของตัวเอง ทำดังนี้

    1. แก้ไขไฟล์ /etc/squid/squid.conf โดยแก้ไขค่าดังนี้
      ของเดิม
      access_log /var/log/squid/access.log squid
      แก้ไขเป็น
      access_log syslog:local7.info หรือ
      access_log syslog:local0.notice หรือ
      access_log syslog:local0.warning หรือแบบอื่น ขึ้นอยู่กับ facility และ priority
    2. สั่ง reconfigure squid ด้วยคำัสั่ง
      squid -k reconfigure
  4. ที่ผ่านมาจะเราสามารถเก็บ Log ของ Freeradius ซึ่งอยู่บนเครื่อง Centralized Log และเก็บ Log ของ Squid ที่อยู่ ณ เครื่อง Authentication Gateway ได้แล้ว ซึ่งเป็น Log หลัก ที่ควรจะเก็บเอาไว้ ต่อไปนี้ก็จะขึ้นอยู่กับนนโยบายของแต่ละหน่วยงานว่ามีการเปิดให้ใช้งานโปรโตคอลอื่น ๆ บน Authentication Gateway นอกเหนือจาก web หรือไม่ ซึ่งถ้าไม่เป็น การเก็บ Log แค่นี้ก็อาจจะเพียงพอแล้ว เพราะทุก application ที่ผู้ใช้ใช้งาน มีการใช้ผ่่าน squid อย่า่งเดียว  แต่ถ้ามีการใช้งานโปรโตคอลอื่น ๆ ด้วย ก็จะ้ต้องมีการเก็บ Log เพิ่มเติมต่อไป
  5. ในกรณีที่ต้องการเก็บ Log ของทราฟฟิกทั้งหมดที่เข้าทางขา eth1 (ซึ่ง chillispot จะสร้าง interface ที่เป็น tun0 ขึ้นมา) และออกทางขา eth0 ของ Authentication Gateway ให้เพิ่มคำสั่ง iptables ลงไปในไฟล์/etc/init.d/rc.capture โดยให้เพิ่มคำสั่งต่อไปนี้ลงไป
    iptables -A FORWARD -i tun0 -o eth0 -j LOG –log-level info –log-prefix “FORWARD “

การส่ง Log จาก Server อื่น ๆ ไปยัง Centralized Log

  1. ติดตั้ง NTP Server ที่เครื่อง Server เครื่องอื่น (NTP client) ตามวิธีการที่ได้กล่าวมาแล้วข้างบน
  2. ติดตั้ง syslog-ng ด้วยคำสั่ง
    apt-get install syslog-ng
  3. กำหนดให้เครื่อง Server อื่น ๆ ส่ง log ไปยัง Centralized log ด้วยการเพิ่มเติมค่าคอนฟิกในไฟล์ /etc/syslog-ng/syslog-ng.conf ดังนี้
    destination remote {
    udp(“202.129.16.26” port(514));
    };
    log {source(s_all); filter(f_messages); destination(remote); };
    log {source(s_all); filter(f_kern); destination(remote); };สคริปต์ข้างบนเป็นการส่ง log ไปยังเครื่อง 202.129.16.26
  4. แ้ก้ไขการกำหนดค่า log ของ Apache ที่ไฟล์คอนฟิกของ Apache (/etc/apache2/sites-available/default) เป็นดังนี้
    ของเดิม
    LogLevel warn
    แก้ไขเป็น
    LogLevel notice

กรณี Apache Web Server ให้ทำดังนี้
วิธีที่ 1 ทำการส่ง log ที่ถูกเก็บเอาไว้ในเครื่อง Web Server แล้ว (/var/log/apache2/access.log) และให้สำเนาส่งไปยัี่งครื่อง Centralized log ด้วย ทำดังนี้

  1. สร้างไฟล์ขึ้นมาหนึ่งไฟล์ในที่นี้ชื่อว่า /etc/init.d/rc.capture และมีข้อความในไฟล์ดังนี้
    #!/bin/bash
    tail -F /var/log/apache2/access.log | logger -t apache2_copy -p local3.info
  2. จากนั้นสั่งให้สามารถรันได้และสร้าง Link ให้ทำงานทุกครั้งหลังเิปิดเครื่องด้วยคำสั่ง
    chmod a+x /etc/init.d/rc.capture
    ln -s /etc/init.d/rc.capture /etc/rcS.d/S88rccapture
  3. เมื่อเราไปเิปิดดู log ที่ไฟล์ /var/log/syslog ของเครื่อง Centralized log จะได้ Log ของ apache ดังรูปจากรูปจะเห็นคำว่า ns2 ซึ่งเป็นชื่อ host ของ Web Server และคำว่า apache2_copy ซึ่งเป็นข้อความที่อยู่หลัง -t ของคำสั่งที่กล่าวมา  โดยเราสามารถที่จะเปลี่ยนแปลงค่าได้ตามความเหมาะสม  เพื่อให้บ่งบอกได้ว่าเป็น log ประเภทไหน

วิธีที่ 2 กำหนดให้ส่ง log จาก Apache Web Server (/var/log/apache2/access.log) ไปยัง Centralized Log โดยไม่มีการสำเนาเก็บไว้ที่ Apache Web Server ทำดังนี้

  1. แก้ไขคอนฟิกไฟล์ของ Apache (/etc/apache2/sites-available/default) ในส่วนของ Log ดังนี้
    ของเดิม
    CustomLog /var/log/apache2/access.log combined
    แก้ไขเป็น
    CustomLog “|/usr/bin/logger -t apache2 -p local1.info” combined
  2. สั่ง restart apache ด้วยคำสั่ง
    /etc/init.d/apache2 restart
  3. เมื่อเราไปเิปิดดู log ที่ไฟล์ /var/log/syslog ของเครื่อง Centralized log จะได้ Log ของ apache ดังรูป

การสั่งให้ Centralized log มีการเก็บ Log แบบกลั่นกรอง (Filter)
ที่ผ่านมาการเก็บ Log ของ Centralized Log Server มีการเก็บ log ไว้ที่ไฟล์ /var/log/syslog ทั้งหมด  ซึ่งจะยากต่อการมอนิเตอร์  วิธีการแก้ทำได้ด้วยการสั่งให้ syslog-ng มีการเก็บ log แบบกลั่นกรองคือกำหนดให้มีการเก็บ log ของแต่ละโปรแกรมหรือแต่ละบริการ แยกไฟล์ต่างหาก
ซึ่งสามารถทำได้ด้วยการแก้ไขไฟล์ /etc/syslog-ng/syslog-ng.conf แล้วเพิ่มค่าการ Filter ดังต่อไปนี้

  • สำหรับฟิลเตอร์โปรแกรม Freeraduisfilter f_radius { match(“radius”); };
    destination d_radius {
    file(“/var/log/$HOST/$YEAR/$MONTH/radius.$YEAR-$MONTH-$DAY”
    owner(root) group(adm) perm(665)
    create_dirs(yes) dir_perm(0775));
    };
    log { source(s_all); filter(f_radius); destination(d_radius); };
  • สำหรับฟิลเตอร์โปรแกรม squidfilter f_squid { match(“squid”); };
    destination d_squid {
    file(“/var/log/$HOST/$YEAR/$MONTH/squid.$YEAR-$MONTH-$DAY”
    owner(root) group(adm) perm(665)
    create_dirs(yes) dir_perm(0775));
    };
    log { source(s_all); filter(f_squid); destination(d_squid); };
  • สำหรับฟิลเตอร์โปรแกรม apachefilter f_apache { match(“apache”); };
    destination d_apache {
    file(“/var/log/$HOST/$YEAR/$MONTH/apache.$YEAR-$MONTH-$DAY”
    owner(root) group(adm) perm(665)
    create_dirs(yes) dir_perm(0775));
    };
    log { source(s_all); filter(f_apache); destination(d_apache); };

หมายเหตุ คำว่า match สำมารถใช้คำว่า program แทนได้
ซึ่งเมื่อเราทำการฟิลเตอร์แล้ว  เมื่อเข้าไปดูไฟล์ในไดเร็กทอรี่ที่กำหนด ก็จะได้ไฟล์เป็นดังรูป

รูปแสดง ไฟล์ที่เก็บ Log ซึ่งผ่านการ Filter แล้ว บน Centralized log ซึ่งเป็น Log ของ radius ที่ส่งมาจาก Server มีชื่อ Hostname เป็น qc

รูปแสดง ไฟล์ที่เก็บ Log ซึ่งผ่านการ Filter แล้ว บน Centralized log ซึ่งเป็น Log ของ squid ที่ส่งมาจาก Server มีชื่อ Hostname เป็น chilli

รูปแสดง ไฟล์ที่เก็บ Log ซึ่งผ่านการ Filter แล้ว บน Centralized log ซึ่งเป็น Log ของ apache ที่ส่งมาจาก Server มีชื่อ Hostname เป็น ns2
การเพิ่มชื่อผู้ใช้งานบน FreeRadius
เป็นการเพิ่มข้อมูลเข้าไปยังฐานข้อมูล MySQL ของ FreeRadius ซึ่งมีวิธีการเพิ่มที่สามารถทำได้ 3 วิธีคือ

  1. การเพิ่มผ่านโปรแกรม phpmyprepaid ซึ่งจะไ่ม่ขอกล่าวเพราะสามารถทำได้ง่ายผ่าน GUI
  2. การเพิ่มผ่านโปรแกรม phpmyadmin
    โดยตารางข้อมูลที่ใช้ี่สำหรับการเพิ่ม user ในเบื้องต้นมี 2 ตารางคือ ตาราง radcheck ซึ่งมีไว้เพื่อเก็บข้อมูลที่เป็น username และ password ของผู้ใช้งาน และตารางที่สองชื่อ radreply มีไว้สำหรับเก็บข้อมูลที่เกี่ยวกับคุณสมบัติการใช้งานของผู้ีใช้ เช่นเวลาในการใช้งานทั้งหมด (Session-Timeout) และเวลาที่เป็นที่เป็น Idle (Idle-Timeout) โดยข้อมูลตัวอย่างเป็นดังรูปตัวอย่างข้อมูลในตาราง radcheck

    ตัวอย่างข้อมูลในตาราง radreply

     

  3. การเพิ่มผู้ใช้งานด้วยการ import text file ผ่าน phpmyadmin โดยมีขั้นตอนดังนี้
    1. สร้าง text file เพื่อสร้างรายชื่อผู้ใช้งานในตาราง radcheck และตาราง radreply ให้มีนามสกุลเป็น *.sqlตัวอย่างการเพิ่มรายชื่อผู้ใช้งานในตาราง radcheck
      INSERT INTO radcheck VALUES (”, ‘somsak’, ‘User-Password’, ‘==’, ‘test123’),
      (”, ‘somchai’, ‘User-Password’, ‘==’, ‘test123’);

      ตัวอย่างการเพิ่มรายชื่อผู้ใช้งานในตาราง radreply
      INSERT INTO radreply VALUES (”, ‘somsak’, ‘Session-Timeout’, ‘:=’, 10800),
      (”, ‘somsak’, ‘Idle-Timeout’, ‘:=’, 1200);

    2. เปิด phpmyadmin แล้วเลือกเมนู import เพื่อทำการ import text file จากนั้นกดปุ่ม Browse เพื่อเลือก text file ที่ได้สร้างไว้ จากนั้นกดปุ่ม Go เพื่อทำการ import text file

ยังมีต่ออีกเร็ว ๆ นี้ครับ

ที่มา: http://www.itmanage.info/technology/linux/ubuntu/chillihospot/install_chillhotspot_ubutu_8_10.html

FreeRadius and Ldap on Ubuntu 10.04

LDAP and FreeRadius they both are know as beasts when it comes to setting them up and configuring them properly. But once you got them they are piece of cake going forward.

I am using both of them since Ubuntu 8.04, but in Ubuntu 10.04 thing has been changed in every aspects, newer versions, different configs etc are some of those changes.

But I got both of them with 10.04 very long time ago but my setup back then were with samba, but this time I have configured them without samba so it just LDAP and FreeRadius. I thought maybe my pain will be gain for someone

Enough talking, lets get to work.
I am assuming that you already have Ubuntu 10.04 [server/desktop] with ssh [not required tho] up and running
I am also assuming that you have setup the static IP for your machine, not required though but good idea
The domain name/tree name we will be using in this examples is

Quote:

dc=myldap,dc=ent

The basic group which will hold our user accounts is

Quote:

cn=Domain Users,ou=Groups,dc=myldap,dc=ent

The users will be in Users OU

Quote:

ou=Users,dc=myldap,dc=ent

Feel free to change any of the above according to you setup So lets start

Be root instead of typing password everytime you use sudo

Quote:

sudo bash

Check update and install if needed

Quote:

apt-get update && apt-get upgrade

Install slapd and its utils

Quote:

sudo apt-get install slapd ldap-utils -y

Add basic schemas in ldap database

Quote:

sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif

Setup core

Quote:

nano /tmp/mysetup.ldif

And paste the following in it, feel free to change the tree name

Quote:

# Load dynamic backend modules
dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
olcModulepath: /usr/lib/ldap
olcModuleload: back_hdb

# Database settings
dn: olcDatabase=hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {1}hdb
olcSuffix: dc=myldap,dc=ent
olcDbDirectory: /var/lib/ldap
olcRootDN: cn=admin,dc=myldap,dc=ent
olcRootPW: mypassword
olcDbConfig: set_cachesize 0 2097152 0
olcDbConfig: set_lk_max_objects 1500
olcDbConfig: set_lk_max_locks 1500
olcDbConfig: set_lk_max_lockers 1500
olcDbIndex: objectClass eq
olcLastMod: TRUE
olcDbCheckpoint: 512 30
olcAccess: to attrs=userPassword by dn=”cn=admin,dc=myldap,dc=ent” write by anonymous auth by self write by * none
olcAccess: to attrs=shadowLastChange by self write by * read
olcAccess: to dn.base=”” by * read
olcAccess: to * by dn=”cn=admin,dc=myldap,dc=ent” write by * read

Add the above ldif file

Quote:

sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /tmp/mysetup.ldif

Setup ldap for authentication

Quote:

sudo apt-get –yes install ldap-auth-client

You will be asked few question, answer them very carefully and after reading.
LDAP server in this case is local host so it would ldap://127.0.0.1/
DN would be dc=myldap,dc=ent
Accept Version 3 as default
Answer Yes to next question
Answer No to next question
Ldap root account would be cn=admin,dc=myldap,dc=ent
And ldap root[admin in this case] password would be mypassword

Check setup

Quote:

sudo auth-client-config -t nss -p lac_ldap

There should not be any error at this point, if there is then something is not right
Update pam for ldap authentication

Quote:

sudo pam-auth-update ldap

Make sure ldap is selected at least
Edit ldap.conf to adjust authentication option

Quote:

nano /etc/ldap.conf

Uncomment line 24
Uncomment line 72 and replace hard with soft
Save the file and exit out of it
Copy this file to /etc/ldap/ directory

Quote:

cp /etc/ldap/ldap.conf /etc/ldap/ldap.old
cp /etc/ldap.conf /etc/ldap/

Make home directory where user profiles will be places

Quote:

mkdir /ldaphome
chmod 777 /ldaphome

Setup basic groups and users

Quote:

nano /tmp/myldap.ldif

And paste the following in it

Quote:

# Create top-level object in domain
dn: dc=myldap,dc=ent
objectClass: top
objectClass: dcObject
objectclass: organization
o: Ldap Enterprise
dc: MYLDAP
description: LDAP Enterprise

# Admin user.
dn: cn=admin,dc=myldap,dc=ent
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
description: LDAP administrator
userPassword: mypassword

dn: ou=Groups,dc=myldap,dc=ent
objectClass: organizationalUnit
ou: Groups

dn: cn=Domain Users,ou=Groups,dc=myldap,dc=ent
objectClass: posixGroup
objectClass: top
cn: Domain Users
gidNumber: 513
description: Domain Users

dn: ou=Users,dc=myldap,dc=ent
objectClass: organizationalUnit
ou: Users

dn: uid=rkhan,ou=Users,dc=myldap,dc=ent
objectClass: organizationalPerson
objectClass: person
objectClass: top
objectClass: posixAccount
objectClass: shadowAccount
uid: rkhan
sn: Khan
cn: Ryaz Khan
uidNumber: 30000
gidNumber: 513
userPassword: test
gecos: Ryaz Khan
loginShell: /bin/bash
homeDirectory: /ldaphome/rkhan
shadowExpire: -1
shadowFlag: 0
shadowWarning: 7
shadowMin: 8
shadowMax: 999999
shadowLastChange: 10877
title: System Administrator

Now add the above ldif file/basic structure to ldap database

Quote:

sudo ldapadd -x -D cn=admin,dc=myldap,dc=ent -w mypassword -f /tmp/myldap.ldif

This should run without any error, if there is/are, something is not right
At this point you should be able to login to your system with user rkhan
You might get error about the home directory does not exists while doing ssh, you can create it manually or if you are using desktop, login with rkhan and it will create the directory. But this is not a show stopper any shape or form
Now lets move to our next setup [freeradius], lets install and setup this monster

Quote:

apt-get install freeradius freeradius-ldap -y

Copy the openldap schema needed for freeradius to work to ldap schema directory

Quote:

cp /usr/share/doc/freeradius/examples/openldap.schema /etc/ldap/schema/

Convert the above schema you just copied to ldif file so it can be added to ldap database

Quote:

nano /tmp/schema_convert.ldif

And paste the following, delete any existing entries from the file, if there is any

Quote:

include /etc/ldap/schema/core.schema
include /etc/ldap/schema/corba.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/dyngroup.schema
include /etc/ldap/schema/inetorgperson.schema
include /etc/ldap/schema/misc.schema
include /etc/ldap/schema/nis.schema
include /etc/ldap/schema/openldap.schema

Create ldif file for openldap schema

Quote:

slapcat -f /tmp/schema_convert.ldif -F ~ -n0 -s “cn={7}openldap,cn=schema,cn=config” > /tmp/cn=openldap.ldif

Clean the above ldif file a bit

Quote:

nano /tmp/cn\=openldap.ldif

Remove number and {} from first lines to make it like the following

Quote:

dn: cn=openldap,cn=schema,cn=config

cn: openldap

And get rid of following lines, there is no use of these but they will/can cause trouble, they are located at the end of openldap.ldif

Quote:

structuralObjectClass: olcSchemaConfig
entryUUID: c69d2a24-1274-1030-8c56-69db9ca637cf
creatorsName: cn=config
createTimestamp: 20110514125231Z
entryCSN: 20110514125231.473294Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20110514125231Z

Now just add the above cleaned ldif file to ldap database

Quote:

sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /tmp/cn\=openldap.ldif

Again there should not be any error
To make sure the schemas we have added so far are in place, issue the following

Quote:

sudo ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b cn=config dn

You will get list of all schemas
Now ldap server is ready with frad schema, its time to configure it
I would simply restart both monster [ldap and freeradius] just to be safe, not required though

Quote:

service slapd restart
service freeradius restart

Back to configuration

Quote:

nano /etc/freeradius/modules/ldap

You want to make sure that at least followings are in place, rest of the file is good by default for out setup

Quote:

server = “localhost”
identity = “cn=admin,dc=myldap,dc=ent”
password = mypassword
basedn = “ou=Users,dc=myldap,dc=ent”
filter = “(uid=%{%{Stripped-User-Name}:-%{User-Name}})”
base_filter = “(objectclass=radiusprofile)”
access_attr = “dialupAccess”
password_attribute = userPassword

Tell freeradius to use ldap for authentication by edit the following file

Quote:

nano /etc/freeradius/sites-enabled/default

Uncomment ldap, located on line 170, 181, and 182
Also tell freeradius to use ldap within tunnel as well, otherwise it simply would not work and you will damage your head by hitting it against the wall

Quote:

nano /etc/freeradius/sites-enabled/inner-tunnel

Uncomment line 129 (ldap)
We are pretty much done, so restart both monster [ldap and freeradius]

Quote:

service slapd restart
service freeradius restart

Issue the following command to see that ldap mapping is working correctely

Quote:

freeradius -XXX

If something like following is in place, we are good here, everything is working the way it designed

Quote:

Sat May 14 09:12:39 2011 : Debug: rlm_ldap: Registering ldap_groupcmp for Ldap-Group
Debug: rlm_ldap: Registering ldap_xlat with xlat_name ldap
Debug: rlm_ldap: LDAP radiusCheckItem mapped to RADIUS $GENERIC$
Debug: rlm_ldap: LDAP radiusReplyItem mapped to RADIUS $GENERIC$
Debug: rlm_ldap: LDAP radiusAuthType mapped to RADIUS Auth-Type
Debug: rlm_ldap: LDAP lmPassword mapped to RADIUS LM-Password
Debug: rlm_ldap: LDAP ntPassword mapped to RADIUS NT-Password
Debug: rlm_ldap: LDAP sambaLmPassword mapped to RADIUS LM-Password
Debug: rlm_ldap: LDAP sambaNtPassword mapped to RADIUS NT-Password
Debug: rlm_ldap: LDAP dBCSPwd mapped to RADIUS LM-Password
Debug: rlm_ldap: LDAP acctFlags mapped to RADIUS SMB-Account-CTRL-TEXT
Debug: rlm_ldap: LDAP radiusExpiration mapped to RADIUS Expiration
Debug: rlm_ldap: LDAP radiusNASIpAddress mapped to RADIUS NAS-IP-Address
Debug: rlm_ldap: LDAP radiusServiceType mapped to RADIUS Service-Type
Debug: rlm_ldap: LDAP radiusFramedProtocol mapped to RADIUS Framed-Protocol
Debug: rlm_ldap: LDAP radiusFramedRoute mapped to RADIUS Framed-Route
Debug: rlm_ldap: LDAP radiusFramedRouting mapped to RADIUS Framed-Routing
Debug: rlm_ldap: LDAP radiusFilterId mapped to RADIUS Filter-Id
Debug: rlm_ldap: LDAP radiusFramedMTU mapped to RADIUS Framed-MTU
Debug: rlm_ldap: LDAP radiusLoginIPHost mapped to RADIUS Login-IP-Host
Debug: rlm_ldap: LDAP radiusLoginService mapped to RADIUS Login-Service
Debug: rlm_ldap: LDAP radiusLoginTCPPort mapped to RADIUS Login-TCP-Port
Debug: rlm_ldap: LDAP radiusCallbackNumber mapped to RADIUS Callback-Number
Debug: rlm_ldap: LDAP radiusCallbackId mapped to RADIUS Callback-Id
Debug: rlm_ldap: LDAP radiusClass mapped to RADIUS Class
Debug: rlm_ldap: LDAP radiusSessionTimeout mapped to RADIUS Session-Timeout
Debug: rlm_ldap: LDAP radiusIdleTimeout mapped to RADIUS Idle-Timeout
Debug: rlm_ldap: LDAP radiusLoginLATNode mapped to RADIUS Login-LAT-Node
Debug: rlm_ldap: LDAP radiusLoginLATGroup mapped to RADIUS Login-LAT-Group
Debug: rlm_ldap: LDAP radiusPortLimit mapped to RADIUS Port-Limit
Debug: rlm_ldap: LDAP radiusLoginLATPort mapped to RADIUS Login-LAT-Port
Debug: rlm_ldap: LDAP radiusReplyMessage mapped to RADIUS Reply-Message
Debug: rlm_ldap: LDAP radiusTunnelType mapped to RADIUS Tunnel-Type

One last thing, we have to add radiusprofile objectClass and dialupAceess attribute to user rkhan
You can do it right on console, but I would use ldif file

Quote:

nano /tmp/modify.ldif

And paste the following in it

Quote:

dn: uid=rkhan,ou=Users,dc=myldap,dc=ent
changetype: modify
add: objectClass
objectClass: radiusprofile

dn: uid=rkhan,ou=Users,dc=myldap,dc=ent
changetype: modify
add: dialupAccess
dialupAccess: access_attr

Issue the following command to add above entries in user rkhan records

Quote:

sudo ldapmodify -h localhost -p 389 -D “cn=admin,dc=myldap,dc=ent” -w mypassword -f /tmp/modify.ldif

At this point freeradius is all setup with ldap authentication and only rkhan can use freeradius to authenticate against open-ldap.
Setup/allow client, localhost is allowed by default

Quote:

nano /etc/freeradius/clients.conf

Look through the file and make changes where needed
Configure wireless or wired clients and have fun !
I have tested it with my wireless [eap/peap authentication method] setup and it work like a charm everytime
Enjoy!

You can also access this articles at
my website

I already have wrote php script to add user via a web page, it will take care of all 1zz and 2zz in background.
User/administrator just have to fill the form and hit submit and yea ! our new user is ready to use freeradius and can authenticate against our freshly configured ldap server

Let me know if you are interested in that script

Note:- I have tested this setup using plain text password in ldap database

Feel free to email me if you have any question(s)
__________________
Ryaz Khan
cns.selfip.net
ที่มา: http://ubuntuforums.org/showthread.php?t=1760830

FreeRadius and Ldap on Ubuntu 10.04

LDAP and FreeRadius they both are know as beasts when it comes to setting them up and configuring them properly. But once you got them they are piece of cake going forward.

I am using both of them since Ubuntu 8.04, but in Ubuntu 10.04 thing has been changed in every aspects, newer versions, different configs etc are some of those changes.

But I got both of them with 10.04 very long time ago but my setup back then were with samba, but this time I have configured them without samba so it just LDAP and FreeRadius. I thought maybe my pain will be gain for someone

Enough talking, lets get to work.
I am assuming that you already have Ubuntu 10.04 [server/desktop] with ssh [not required tho] up and running
I am also assuming that you have setup the static IP for your machine, not required though but good idea
The domain name/tree name we will be using in this examples is

Quote:

dc=myldap,dc=ent

The basic group which will hold our user accounts is

Quote:

cn=Domain Users,ou=Groups,dc=myldap,dc=ent

The users will be in Users OU

Quote:

ou=Users,dc=myldap,dc=ent

Feel free to change any of the above according to you setup So lets start

Be root instead of typing password everytime you use sudo

Quote:

sudo bash

Check update and install if needed

Quote:

apt-get update && apt-get upgrade

Install slapd and its utils

Quote:

sudo apt-get install slapd ldap-utils -y

Add basic schemas in ldap database

Quote:

sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif

Setup core

Quote:

nano /tmp/mysetup.ldif

And paste the following in it, feel free to change the tree name

Quote:

# Load dynamic backend modules
dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
olcModulepath: /usr/lib/ldap
olcModuleload: back_hdb

# Database settings
dn: olcDatabase=hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {1}hdb
olcSuffix: dc=myldap,dc=ent
olcDbDirectory: /var/lib/ldap
olcRootDN: cn=admin,dc=myldap,dc=ent
olcRootPW: mypassword
olcDbConfig: set_cachesize 0 2097152 0
olcDbConfig: set_lk_max_objects 1500
olcDbConfig: set_lk_max_locks 1500
olcDbConfig: set_lk_max_lockers 1500
olcDbIndex: objectClass eq
olcLastMod: TRUE
olcDbCheckpoint: 512 30
olcAccess: to attrs=userPassword by dn=”cn=admin,dc=myldap,dc=ent” write by anonymous auth by self write by * none
olcAccess: to attrs=shadowLastChange by self write by * read
olcAccess: to dn.base=”” by * read
olcAccess: to * by dn=”cn=admin,dc=myldap,dc=ent” write by * read

Add the above ldif file

Quote:

sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /tmp/mysetup.ldif

Setup ldap for authentication

Quote:

sudo apt-get –yes install ldap-auth-client

You will be asked few question, answer them very carefully and after reading.
LDAP server in this case is local host so it would ldap://127.0.0.1/
DN would be dc=myldap,dc=ent
Accept Version 3 as default
Answer Yes to next question
Answer No to next question
Ldap root account would be cn=admin,dc=myldap,dc=ent
And ldap root[admin in this case] password would be mypassword

Check setup

Quote:

sudo auth-client-config -t nss -p lac_ldap

There should not be any error at this point, if there is then something is not right
Update pam for ldap authentication

Quote:

sudo pam-auth-update ldap

Make sure ldap is selected at least
Edit ldap.conf to adjust authentication option

Quote:

nano /etc/ldap.conf

Uncomment line 24
Uncomment line 72 and replace hard with soft
Save the file and exit out of it
Copy this file to /etc/ldap/ directory

Quote:

cp /etc/ldap/ldap.conf /etc/ldap/ldap.old
cp /etc/ldap.conf /etc/ldap/

Make home directory where user profiles will be places

Quote:

mkdir /ldaphome
chmod 777 /ldaphome

Setup basic groups and users

Quote:

nano /tmp/myldap.ldif

And paste the following in it

Quote:

# Create top-level object in domain
dn: dc=myldap,dc=ent
objectClass: top
objectClass: dcObject
objectclass: organization
o: Ldap Enterprise
dc: MYLDAP
description: LDAP Enterprise

# Admin user.
dn: cn=admin,dc=myldap,dc=ent
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
description: LDAP administrator
userPassword: mypassword

dn: ou=Groups,dc=myldap,dc=ent
objectClass: organizationalUnit
ou: Groups

dn: cn=Domain Users,ou=Groups,dc=myldap,dc=ent
objectClass: posixGroup
objectClass: top
cn: Domain Users
gidNumber: 513
description: Domain Users

dn: ou=Users,dc=myldap,dc=ent
objectClass: organizationalUnit
ou: Users

dn: uid=rkhan,ou=Users,dc=myldap,dc=ent
objectClass: organizationalPerson
objectClass: person
objectClass: top
objectClass: posixAccount
objectClass: shadowAccount
uid: rkhan
sn: Khan
cn: Ryaz Khan
uidNumber: 30000
gidNumber: 513
userPassword: test
gecos: Ryaz Khan
loginShell: /bin/bash
homeDirectory: /ldaphome/rkhan
shadowExpire: -1
shadowFlag: 0
shadowWarning: 7
shadowMin: 8
shadowMax: 999999
shadowLastChange: 10877
title: System Administrator

Now add the above ldif file/basic structure to ldap database

Quote:

sudo ldapadd -x -D cn=admin,dc=myldap,dc=ent -w mypassword -f /tmp/myldap.ldif

This should run without any error, if there is/are, something is not right
At this point you should be able to login to your system with user rkhan
You might get error about the home directory does not exists while doing ssh, you can create it manually or if you are using desktop, login with rkhan and it will create the directory. But this is not a show stopper any shape or form
Now lets move to our next setup [freeradius], lets install and setup this monster

Quote:

apt-get install freeradius freeradius-ldap -y

Copy the openldap schema needed for freeradius to work to ldap schema directory

Quote:

cp /usr/share/doc/freeradius/examples/openldap.schema /etc/ldap/schema/

Convert the above schema you just copied to ldif file so it can be added to ldap database

Quote:

nano /tmp/schema_convert.ldif

And paste the following, delete any existing entries from the file, if there is any

Quote:

include /etc/ldap/schema/core.schema
include /etc/ldap/schema/corba.schema
include /etc/ldap/schema/cosine.schema
include /etc/ldap/schema/dyngroup.schema
include /etc/ldap/schema/inetorgperson.schema
include /etc/ldap/schema/misc.schema
include /etc/ldap/schema/nis.schema
include /etc/ldap/schema/openldap.schema

Create ldif file for openldap schema

Quote:

slapcat -f /tmp/schema_convert.ldif -F ~ -n0 -s “cn={7}openldap,cn=schema,cn=config” > /tmp/cn=openldap.ldif

Clean the above ldif file a bit

Quote:

nano /tmp/cn\=openldap.ldif

Remove number and {} from first lines to make it like the following

Quote:

dn: cn=openldap,cn=schema,cn=config

cn: openldap

And get rid of following lines, there is no use of these but they will/can cause trouble, they are located at the end of openldap.ldif

Quote:

structuralObjectClass: olcSchemaConfig
entryUUID: c69d2a24-1274-1030-8c56-69db9ca637cf
creatorsName: cn=config
createTimestamp: 20110514125231Z
entryCSN: 20110514125231.473294Z#000000#000#000000
modifiersName: cn=config
modifyTimestamp: 20110514125231Z

Now just add the above cleaned ldif file to ldap database

Quote:

sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /tmp/cn\=openldap.ldif

Again there should not be any error
To make sure the schemas we have added so far are in place, issue the following

Quote:

sudo ldapsearch -LLL -Y EXTERNAL -H ldapi:/// -b cn=config dn

You will get list of all schemas
Now ldap server is ready with frad schema, its time to configure it
I would simply restart both monster [ldap and freeradius] just to be safe, not required though

Quote:

service slapd restart
service freeradius restart

Back to configuration

Quote:

nano /etc/freeradius/modules/ldap

You want to make sure that at least followings are in place, rest of the file is good by default for out setup

Quote:

server = “localhost”
identity = “cn=admin,dc=myldap,dc=ent”
password = mypassword
basedn = “ou=Users,dc=myldap,dc=ent”
filter = “(uid=%{%{Stripped-User-Name}:-%{User-Name}})”
base_filter = “(objectclass=radiusprofile)”
access_attr = “dialupAccess”
password_attribute = userPassword

Tell freeradius to use ldap for authentication by edit the following file

Quote:

nano /etc/freeradius/sites-enabled/default

Uncomment ldap, located on line 170, 181, and 182
Also tell freeradius to use ldap within tunnel as well, otherwise it simply would not work and you will damage your head by hitting it against the wall

Quote:

nano /etc/freeradius/sites-enabled/inner-tunnel

Uncomment line 129 (ldap)
We are pretty much done, so restart both monster [ldap and freeradius]

Quote:

service slapd restart
service freeradius restart

Issue the following command to see that ldap mapping is working correctely

Quote:

freeradius -XXX

If something like following is in place, we are good here, everything is working the way it designed

Quote:

Sat May 14 09:12:39 2011 : Debug: rlm_ldap: Registering ldap_groupcmp for Ldap-Group
Debug: rlm_ldap: Registering ldap_xlat with xlat_name ldap
Debug: rlm_ldap: LDAP radiusCheckItem mapped to RADIUS $GENERIC$
Debug: rlm_ldap: LDAP radiusReplyItem mapped to RADIUS $GENERIC$
Debug: rlm_ldap: LDAP radiusAuthType mapped to RADIUS Auth-Type
Debug: rlm_ldap: LDAP lmPassword mapped to RADIUS LM-Password
Debug: rlm_ldap: LDAP ntPassword mapped to RADIUS NT-Password
Debug: rlm_ldap: LDAP sambaLmPassword mapped to RADIUS LM-Password
Debug: rlm_ldap: LDAP sambaNtPassword mapped to RADIUS NT-Password
Debug: rlm_ldap: LDAP dBCSPwd mapped to RADIUS LM-Password
Debug: rlm_ldap: LDAP acctFlags mapped to RADIUS SMB-Account-CTRL-TEXT
Debug: rlm_ldap: LDAP radiusExpiration mapped to RADIUS Expiration
Debug: rlm_ldap: LDAP radiusNASIpAddress mapped to RADIUS NAS-IP-Address
Debug: rlm_ldap: LDAP radiusServiceType mapped to RADIUS Service-Type
Debug: rlm_ldap: LDAP radiusFramedProtocol mapped to RADIUS Framed-Protocol
Debug: rlm_ldap: LDAP radiusFramedRoute mapped to RADIUS Framed-Route
Debug: rlm_ldap: LDAP radiusFramedRouting mapped to RADIUS Framed-Routing
Debug: rlm_ldap: LDAP radiusFilterId mapped to RADIUS Filter-Id
Debug: rlm_ldap: LDAP radiusFramedMTU mapped to RADIUS Framed-MTU
Debug: rlm_ldap: LDAP radiusLoginIPHost mapped to RADIUS Login-IP-Host
Debug: rlm_ldap: LDAP radiusLoginService mapped to RADIUS Login-Service
Debug: rlm_ldap: LDAP radiusLoginTCPPort mapped to RADIUS Login-TCP-Port
Debug: rlm_ldap: LDAP radiusCallbackNumber mapped to RADIUS Callback-Number
Debug: rlm_ldap: LDAP radiusCallbackId mapped to RADIUS Callback-Id
Debug: rlm_ldap: LDAP radiusClass mapped to RADIUS Class
Debug: rlm_ldap: LDAP radiusSessionTimeout mapped to RADIUS Session-Timeout
Debug: rlm_ldap: LDAP radiusIdleTimeout mapped to RADIUS Idle-Timeout
Debug: rlm_ldap: LDAP radiusLoginLATNode mapped to RADIUS Login-LAT-Node
Debug: rlm_ldap: LDAP radiusLoginLATGroup mapped to RADIUS Login-LAT-Group
Debug: rlm_ldap: LDAP radiusPortLimit mapped to RADIUS Port-Limit
Debug: rlm_ldap: LDAP radiusLoginLATPort mapped to RADIUS Login-LAT-Port
Debug: rlm_ldap: LDAP radiusReplyMessage mapped to RADIUS Reply-Message
Debug: rlm_ldap: LDAP radiusTunnelType mapped to RADIUS Tunnel-Type

One last thing, we have to add radiusprofile objectClass and dialupAceess attribute to user rkhan
You can do it right on console, but I would use ldif file

Quote:

nano /tmp/modify.ldif

And paste the following in it

Quote:

dn: uid=rkhan,ou=Users,dc=myldap,dc=ent
changetype: modify
add: objectClass
objectClass: radiusprofile

dn: uid=rkhan,ou=Users,dc=myldap,dc=ent
changetype: modify
add: dialupAccess
dialupAccess: access_attr

Issue the following command to add above entries in user rkhan records

Quote:

sudo ldapmodify -h localhost -p 389 -D “cn=admin,dc=myldap,dc=ent” -w mypassword -f /tmp/modify.ldif

At this point freeradius is all setup with ldap authentication and only rkhan can use freeradius to authenticate against open-ldap.
Setup/allow client, localhost is allowed by default

Quote:

nano /etc/freeradius/clients.conf

Look through the file and make changes where needed
Configure wireless or wired clients and have fun !
I have tested it with my wireless [eap/peap authentication method] setup and it work like a charm everytime
Enjoy!

You can also access this articles at
my website

I already have wrote php script to add user via a web page, it will take care of all 1zz and 2zz in background.
User/administrator just have to fill the form and hit submit and yea ! our new user is ready to use freeradius and can authenticate against our freshly configured ldap server

Let me know if you are interested in that script

Note:- I have tested this setup using plain text password in ldap database

Feel free to email me if you have any question(s)
__________________
Ryaz Khan
cns.selfip.net
ที่มา: http://ubuntuforums.org/showthread.php?t=1760830

การติดตั้ง chillispot, FreeRadius, syslog-ng บน ubuntu เพื่อทำตาม พรบ.ตอมพิวเตอร์

การติดตั้ง chillispot, FreeRadius, syslog-ng บน ubuntu เพื่อทำตาม พรบ.ตอมพิวเตอร์

ดัดแปลงโดย อดิศร  ขาวสังข์
ดัดแปลงจาก คู่มือประกอบการฝึกอบรมเชิงปฏิบัติการ “การติดตั้ง Authentication” ของ SiPA และ ATSI (http://61.7.253.244/syslog-ng/)
จัดทำเมื่อ 20/11/2008
ทดลองบน Ubuntu 8.04, Ubuntu 8.10
บทนำ
ท่านที่เคยไปพักตามโรงแรมหรือสถานที่ท่องเที่ยว/จุดพักเิดินทาง ฯลฯ คงเคยเห็นมีบริการ Wi-Fi และมีการขายบัตรอินเตอร์เ้น็ต หลาย ๆ ที่ดังกล่าว ได้นำเอาโปรแกรม chillispot และ FreeRaDius ไปประยุกต์ใช้งาน  นั่นคือเมื่อเราเชื่อมต่อ Wi-Fi ได้แล้ว พอเข้าเว็บไซต์ก็จะมีหน้าต่างให้เราป้อน username และ password ก่อนจึงจะใช้งานได้

ในสถานการณ์ปัจจุบัน  พรบ.คอมพิวเตอร์ 2550 ได้บังคับใช้งานแ้ล้ว  เราสามารถนำเอาโปรแกรม chillispot, FreeRadius, syslog-ng มาประยุกต์ใช้งานให้เข้ากับ พรบ.ได้ เพราะ พรบ.ได้ระบุว่า ผู้ให้บริการจะต้องสามารถระบุตัวตนของผู้ใช้งานได้ พร้ออมเก็บข้อมูลการจราจรคอมพิวเตอร์ไม่น้อยกว่า 90 วัน ซึ่ง chillispot + freeradius + syslog-ng สามารถที่จะช่วยได้  ไม่เว้นแ่ต่ plawan centralized log ก็ได้นำซอฟต์แวร์ชุดนี้มาใช้งานเช่นกัน

การติดตั้งในที่นี้เป็นการติดตั้งตามรูปคอนฟิกข้างล่าง  โดยติดตั้ง FreeRadius และ syslog-ng ไว้บน Server ที่วางอยู่ในตำแหน่ง DMZ และติดตั้ง Chillispot ให้ทำหน้าที่เป็น Authentication Gateway ไ้ว้ในตำแน่ง Internal  ซึ่งจะเห็นว่าถ้าเป็นเครือข่ายขนาดใหญ่ และมีหลาย Internal Network ก็สามารถใช้ FreeRadius และ syslog-ng ร่วมกันได้  โดยส่วนประกอบของ chillispot ก็ประกอบด้วย dhcp, firewall, และ nat อยู่ในตัว การทำงานของ chillispot จะต้องทำงานร่วมกับ FreeRadius ซึ่งวิธีการติดตั้ง FreeRadius ดูได้ ที่นี่ โดยในที่นี้ผู้เขียนติดตั้ง chillispot บน ubuntu 8.10 ส่วน FreeRadius ติดตั้งบน ubuntu 8.04 (ไม่ใช้ ubuntu 8.10 เพราะเจอปัญหาบางอย่างที่้ัยังแก้ไม่ได้)

หมายเหตุ FreeRadius, chillispot และ syslog-ng สามารถติดตั้งในเครื่องเดียวกันได้  ซึ่งจะเหมาะสมกับหน่วยงานขนาดเล็ก ด้วยการปรับค่าคอนฟิกบางส่วน
ขั้นตอนการติดตั้ง Freeradius
การติดตั้ง Freeradius สำหรับวิธีการของผู้เขียนดูวิธีได้ ที่นี่

โดยบนเครื่อง FreeRadius จะต้องมีการคอนฟิกอนุญาตให้เข้าไปใช้งาน FreeRadius ที่ไฟล์ /etc/freeradius/client.conf ดังนี้
client 172.24.51.16 {
secret = radiussecret
shortname = chilli
}

จากค่า client ข้างบนอาจจะมีการสงสัยกันว่าทำไม่อนุญาต IP 172.24.51.252 เข้าไปใช้งาน  คำตอบก็คือว่าที่ Firewall มีการทำ NAT ระหว่าง Internal กับ DMZ ดังนั้น IP ที่ส่งไปยัง FreeRadius จึงเป็น IP ของ Firewall ฝั่ง Internal คือ 172.24.51.16

ในการติดตั้งใช้งาน ที่ Firewall ต้องทำให้เครื่อง Authentication Gateway สามารถเชื่อมต่อไปยังเครื่องที่เป็น FreeRadius ได้  ไม่นั้นก็จะไม่สามารถติดตั้ง FreeRadius ได้
ขั้นตอนการติดตั้ง chillispot บนเครื่อง Authentication Gateway
เซ็ตค่า Network

  1. ทำการ Enable packet forwarding ด้วยการแก้ไขไฟล์ /etc/sysctl.conf ด้วยการเอาเครื่องหมาย # หน้าคำว่า net.ipv4.ip_forward=1 ออก เพื่อสั่งให้ packet forwarding ของ ipv4 ทำงาน
  2. ทำการรันคำสั่งต่อไปนี้  เพื่อให้มีผลทันที  ให้เครื่องสามารถ forward packet ทำตัวเป็นเราเตอร์ได้
    echo 1 | tee /proc/sys/net/ipv4/ip_forward
    ถ้าผลที่ได้เป็น 1 ถือว่าทำการ Enable packet forwarding สำเร็จ
  3. ทำการ Restart network ด้วยคำสั่งต่อไปนี้
    sysctl -p
    /etc/init.d/networking restart

Enable TUN/TAP device driver support

  1. ทำการ Enable TUN/TAP device drive support ด้วยการเพิ่มคำว่า tun ต่อท้ายไฟล์ /etc/modules
  2. จากนั้นทำการ Enable โดยไม่ต้อง reboot ด้วยการรันคำสั่งต่อไปนี้
    modprobe tun

Install Chillispot
โปรแกรม chillispot เป็น Opensource ที่ใช้ติดตั้งบน Gateway Server เพื่อทำหน้าที่ควบคุมการใช้งานของ user ที่วิ่งผ่านให้มีการป้อน username และ password ก่อนจึุงจะใช้งานได้ ซึ่งจะทำงานร่วมกับโปรแกรม Radius ซึ่งทำหน้าที่บริหารจัดการฐานข้อมูลของ user โดยโปรแกรม chillispot กับ FreeRadius อาจจะติดตั้งอยู่บนเครื่องเดียวกันหรือต่างเครื่องกันได้
การติดตั้ง chillispot จะต้องใช้การ์แลน 2 การ์ด ซึ่งมีขั้นตอนต่อไปนี้

  1. ทำการติดตั้ง chillispot โดยใ้้ช้คำสั่งต่อไปนี้
    apt-get install chillispot
    จากนั้นให้เติมรายละเอียดดังต่อไปนี้
    IP address of radius server 1:
    127.0.0.1(ของผู้เีขียนชี้ไปยัง Freeradius ซึ่งอยู่อีกเครื่องจึงกำหนดเป็น 192.168.9.12)
    Radius shared secret:
    radiussecret   (ค่านี้ต้องตรงกับ Radius Server)
    Ethernet interface for DHCP to listen:
    eth1
    URL of UAM server:
    https://192.168.182.1/cgi-bin/hotspotlogin.cgi  (เปลี่ยนเป็นค่าอื่นได้)
    URL of UAM homepage:
    https://192.168.182.1/welcome.html
    Shared password between chillispot and webserver:
    uamsecret
  2. ต่อไปทำการแก้ไขไฟล์ /etc/default/chillispot เพื่อ Enable captive portal ด้วยการกำหนดค่าให้
    ENABLED=1
  3. ทำการแก้ไขไฟล์คอนฟิกของ chillispot คือไฟล์ /etc/chilli.conf โดยค่าที่สำคัญมาจากขั้นตอนของการติดตั้งที่ได้ทำมาแล้ว  และให้แก้ไขค่าให้เหมาะสม ดังต่อไปนี้
    net 192.168.182.0/24
    dns1 61.19.253.134
    dns2 61.19.253.136
    radiusserver1 127.0.0.1 (ของผู้เีขียนเป็น 192.168.99.12)
    radiusserver2 127.0.0.1 (ของผู้เีขียนเป็น 192.168.99.12)
    radiussecert radiussecret
    dhcpif eth1
    uamserver https://192.168.182.1/cgi-bin/hotspotlogin.cgi
    uamhomepage https://192.168.182.1/welcome.html
    uamsecret uamsecret
    uamlisten 192.168.182.1
    uamallowed www.google.co.th,192.168.182.0/24โดยค่าของ dns ต้องสามารถใช้งานได้จริง เพราะเป็นค่าที่จะต้องจ่ายให้กับเครื่อง Client

ติดตั้ง Firewall สำหรับ Chillispot
chillispot จะต้องมีการติดตั้ง Firewall (iptables) เพื่อกำหนดให้แพ็กเกตของข้อมูลจากเครื่อง Client ที่วิ่งผ่าน  ต้องผ่าน Service ที่เป็น chillispot เพื่อให้ Client ทุกคนต้องมีการป้อน username และ password ก่อนถึงจะใช้งานได้  โดย Firewall ของ Chillspot จะมีมาให้แล้วกับการติดตั้ง ซึ่งมีขั้นตอนการนำมาใช้ดังต่อไปนี้

  1. ทำการกำหนด firewall โดยทำการสร้างไฟล์ chilli.iptables ด้วยการคัดลอกมาจากไฟล์ firewall.iptables ที่มากับ chillispot ไปไว้ในตำแหน่ง /etc/init.d ด้วยคำสั่งดังนี้
    cp /usr/share/doc/chillispot/firewall.iptables /etc/init.d/chilli.iptables
  2. กำหนดให้ไฟล์ chilli.iptables สามารถ execute ได้ด้วยคำสั่ง
    chmod a+x /etc/init.d/chilli.iptables
  3. กำหนดให้กฎ firewall มีการ start ทุกครั้งเมื่อมีการเิปิดเครื่องด้วยคำสั่ง
    ln -s /etc/init.d/chilli.iptables /etc/rcS.d/S41chilli.iptables
  4. โดยค่าดีฟอลต์ไฟร์วอลล์จะทำการกำหนดค่าให้ eth0=internet, eth1= LAN แต่ถ้าคุณต้องการเปลี่ยนค่าก็สามารถเปลี่ยนแปลงได้
  5. หากต้องการให้เครื่องลูกสามารถทดสอบการเชื่อมต่อโดยใ้ช้โปรโตคอล ICMP หรือ ping ได้ ให้เพิ่มกฎของ iptables ดังนี้
    #Allow ping to myserver
    SERVER_IP=”192.168.182.1″
    iptables -A INPUT -p icmp –icmp-type 8 -s 0/0 -d $SERVER_IP -m state –state NEW,ESTABLISHED,RELATED -j ACCEPT
    iptables -A OUTPUT -p icmp –icmp-type 0 -s $SERVER_IP -d 0/0 -m state –state ESTABLISHED,RELATED -j ACCEPT
  6. ทำการ Enable firewall script ด้วยคำสั่ง
    /etc/init.d/chilli.iptables

ติดตั้ง Apache และ PHP

  1. ติดตั้ง Apache Web Server ด้วยคำสั่ง
    apt-get install apache2
  2. start apache ด้วยคำสั่ง
    /etc/init.d/apache2 start
  3. ตรวจสอบว่า apache ทำงานหรือไม่ด้วยคำสั่ง
    netstat -lnt
    ถ้าทำแล้วจะต้องมีคำว่า
    tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN
  4. ติดตั้ง PHP5 ด้วยคำสั่ง
    apt-get install php5
  5. restart apache ด้วยคำสั่ง
    /etc/init.d/apache2 restart

สร้างหน้าต่าง Login

  1. โดยปกติตำแหน่งที่เป็น ScriptAlias /cgi-bin/ ของ apache จะอยู่ที่ /usr/lib/cgi-bin/
  2. ให้ทำการเปลี่ยนไดเร็กทอรีเข้าไปยังตำแหน่งดังกล่าวแล้วใ้ช้ีคำสั่ง ls จะเห็นชื่อไฟล์ชื่อว่า hotspotlogin.cgi ซึ่งเป็นไฟล์ที่ถูกสร้างขึ้นในขั้นตอนการติดตั้ง chillispot
  3. ทำการแก้ไขไฟล์ดังกล่าวโดยให้เอาเครื่องหมาย # หน้าคำว่า $uamsecret และ $userpassword ออกและำกำหนดค่าเป็นดังนี้
    $uamsecret = “uamsecret”;
    $userpassword=1;
  4. เมื่อแก้ไขเสร็จแล้วทำการ restart chillispot ด้วยคำสั่ง
    /etc/init.d/chillispot start
  5. ทำการสร้างไฟล์ welcome.html ด้วยคำสั่ง
    vim /var/www/welcome.html
  6. ทำการเพิ่มข้อความต่อไปนี้ลงไปในไฟล์ welcome.html
    <html>
    <head><title> Welcome to Our Hotspot, Wireless Network </title></head>
    <body>
    <center>
    <H1><font color=”red”>TESTING ONLY</font></H1>
    <img src=”chillispot.png”>
    <H3><font color=”blue”>Welcome to Our Hotspot, Wireless Network.</font></H3>
    <p>You are connected to an authentication and restricted network access point.
    <H3><a href=”http://192.168.182.1:3990/prelogin”>Click here to login</a></H3>
    <p>
    <p>Enjoy.
    </center>
    </body>
    </html>
  7. ถ้าต้องการรูป chillispot.png ให้ทำการดาว์นโหลดโดยใช้คำสั่ง
    wget http://mamboeasy.psu.ac.th/~wiboon.w/images/stories/chillispot/chillispo…
    cp chillispot.png /var/www

เซ็ตอัพ SSL

  1. ติดตั้ง SSL โดยใช้คำสั่งต่อไปนี้
    apt-get install ssl-cert
  2. สร้างไดเร็กทอรี่ขึ้นมาเพื่อเก็บ Certificate ที่ถูกสร้างขึ้น โดยใช้คำสั่ง
    mkdir /etc/apache2/ssl
  3. ทำการสร้าง self-signed cerfiticate ด้วยคำสั่งดังต่อไปนี้
    make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
  4. แล้วจะถูกถามคำถามต่าง ๆ แต่ใน ubuntu 8.10 อาจจะถามแค่ hostname
    Country Name : ป้อน TH
    State or Province Name : ป้อนจังหวัด
    Locality Name : ป้อนชื่อที่เหมาะสม
    Organization : ป้อนชื่อองค์กร
    hostname   :  localhost (ควรจะใช้ hostname ที่เป็นจริง ของผู้เขียนแค่ทดลอง)
    Email : ป้อนอีเมล์
  5. ทำการ install module ssl ด้วยคำสั่ง
    a2enmod ssl
  6. ให้รันคำสั่งต่อไปนี้เพื่อ active new configuration
    /etc/init.d/apache2 restart
  7. สร้าง virtual host ชื่อ hotspot ขึ้นมาด้วยคำสั่งต่อไปนี้
    vim /etc/apache2/sites-available/hotspot
  8. เพิ่มข้อความต่อไปนี้ลงไปในไฟล์
    NameVirtualHost 192.168.182.1:443
    <VirtualHost 192.168.182.1:443>
    ServerAdmin adisorn.k@cattelecom.com
    DocumentRoot “/var/www”
    ServerName “192.168.182.1”
    <Directory “/var/www/”>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
    </Directory>
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory “/usr/lib/cgi-bin/”>
    AllowOverride None
    Options ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    </Directory>
    ErrorLog /var/log/apache2/hotspot-error.log
    LogLevel warn
    CustomLog /var/log/apache2/hotspot-access.log combined
    ServerSignature On
    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/apache.pem
    </VirtualHost>
  9. ทำการ Enable SSL VirtualHost ด้วยคำสั่งต่อไปนี้
    a2ensite hotspot
  10. ทำการ reload apache ด้วยคำสั่ง
    /etc/init.d/apache2 reload
  11. การ Listen port ของ https (SSL) โดย default จะเป็นพอร์ต 443 ให้ทำการแก้ไขค่าคอนฟิกที่เกี่ยวกับ port ของ SSL ที่ไฟล์ /etc/apache2/ports.conf ให้มีค่าเป็นดังนี้ 
  12. เปลี่ยนแปลงค่าให้มีการ Listen port ที่เป็น default http (80) ด้วยการแก้ไขไฟล์ /etc/apache2/site-available/default โดยให้มีโครงสร้างของ VirtualHost เป็นดังนี้
    NameVirtualHost *:80
    <VirtualHost *:80>


    </VirtualHost>
  13. ทำการกำหนดค่า ServerName ในไฟล์ /etc/apache2/apache2.conf ให้มีค่าดังนี้
    ServerName  192.168.182.1  (ของผู้เขียนไม่ได้กำหนดค่านี้ก็ทำงานได้)
  14. ทำการ restart apache ด้วยคำสั่ง
    /etc/init.d/apache restart
  15. เืมื่อเอาเครื่อง client มาเชื่อมใช้งานหลังเครื่อง Authentications Gateway ก็ได้จะรับ IP address ที่ Authentications Gateway จ่ายมาให้โดย ค่า Gateway IP ที่ได้ เป็นค่าที่ชี้ไปยัง Authentication Server ดังนั้นเมื่อเปิดใ้ช้งาน Browser ตัว Authentication Gateway จะบังคับให้มีการ Redirect ไปยัง https ดังรูป ให้คลิ๊กที่คำว่า Continue to this website (not recommended) 
  16. จากนั้นจะได้หน้าต่างแจ้งข้อมูลดังรูป ให้คลิ๊กที่ Link –> Click Here to login 
  17. จากนั้นจะได้หน้า่ต่างให้ป้อน username และ password ดังรูป 
  18. ถ้า Login ถูกต้องจะได้ผลดังรูป

กรณีที่ต้องการบังคับให้ผู้ใช้งานเว็บต้องใช้งานผ่าน Proxy ต้องทำดังขั้นตอนต่อไปนี้

  1. ติดตั้ง squid ด้วยคำสั่ง
    apt-get install squid
  2. แก้ไขไฟล์คอนฟิกของ squid คือไฟล์ /etc/squid/squid.conf ดังนี้
    1. เอาเครื่องหมาย # ไปไว้หน้าคำว่า http_port 3128 เพื่อกำหนดให้เป็นคอมเมนต์
    2. หาข้อความว่า # INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS แล้วข้อความเพิ่มเติมอีก 3 บรรทัดต่อไปนี้
      acl chillispot src 192.168.182.0/255.255.255.0
      http_port 192.168.182.1:3128 transparent
      http_access allow chillispot
      คำอธิบาย
      # http_port 3128  เป็นการยกเลิกการทำงานของโปรแกรมแบบไม่ทำ transparent
      visible_hostname ต้องกำหนดชื่อเครื่องให้ระบบ หากไม่กำหนด  อาจมีปัญหาในการ start service
      acl chillispot src เป็นการกำหนดค่าเน็ตเวิร์กของเครือข่ายที่จะอนุญาตให้ใช้งานผ่านโปรแกรม Squid
      http_port x.x.x.x.3128 transparent เป็นการกำหนดให้พอร์ต 3128 เป็น transparent proxy
      http_access allow กำหนดค่า Access Control ให้เน็ตเวิร์ควง chillispot สามารถใช้งานผ่าน transparent proxy ได้
    3. หาคำว่า visible_hostname แล้วใส่ชื่อหลังคำดังกล่าวเช่น
      visible_hostname myproxy
  3. สั่งให้โปรแกรม squid ทำงานด้วยคำสั่ง
    /etc/init.d/squid start
  4. ทำการส่งต่อ packet ที่เข้ามาทางพอร์ต 80 ไปยัง squid พอร์ต 3128 ด้วย คำสั่ง iptables โดยเพิ่มในไฟล์ /etc/init.d/chilli.iptables ดังนี้
    iptables -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 80 -j REDIRECT –to-ports 3128
  5. ทำการอนุญาตให้ใช้งาน INPUT ที่เป็น syn flag ดังนี้
    iptables -A INPUT -i tun0 -p tcp -m tcp –dport 3128 –syn -j ACCEPT
  6. ต้องเิพิ่ม rule ต่อไปนี้เพื่อป้องกันการเ้้ข้าใช้งานระบบโดยการแอบตั้งค่า proxy เอง
    iptables -t nat -I PREROUTING -p tcp -m tcp –dport 3128 -j DROP

การจัดการเรื่อง Log
การจัดการเรื่อง Log ในที่นี้จะเลือกข้อมูลการจราจรที่สำคัญจากเครื่องที่เป็น Authentication Gateway และ Log ของ Server อื่น ๆ (ถ้ามี) ส่งไปยังเครื่อง Centralized Log Server เหตุผลที่เรามีการคัดเฉพาะส่วนที่ำจำเป็นก็คือ เพื่อไม่ให้ปริมาณทราฟฟิกของข้อมูลการจราจร ทำให้การใช้งานระบบเครือข่ายคอมพิวเตอร์ช้าลง หรือเปลืองแบนด์วิดธ์ของระบบ

สำหรับเซอร์วิสที่สำคัญที่จะ้ต้องส่งต่อข้อมูลการจราจรคอมพิวเตอร์ได้แก่ squid และ radius ขณะเดียวกันเราจะต้องใช้หลักการของ IPTABLES เพื่อทำการคัดเลือกข้อมูลเบื้องต้นสำหรับการใช้งานผ่านพอร์ตต่าง ๆ ที่เป็นเซอร์วิสพื้นฐานเพื่อจัดเก็บข้อมูลการจราจรคอมพิวเตอร์ เช่น http, https, ftp, smtp, imap, pop3, IM เป็นต้น

Install Time Server
ด้วย พรบ.ได้กำหนดว่าต้องตั้งนาฬิกาของอุปกรณ์บริการทุกชนิดให้ตรงกับเวลาอ้างอิงสากล (Stratum0) ซึ่งเราควรจะติดตั้ง NTP Server ไว้บน Server เครื่องใดเครืองหนึ่ง  ซึ่งในที่นี้เลือกเครื่องที่เป็น Log Server เพื่อกระจายสัญญาณนาฬิกาให้กับเครื่อง Server และเครื่อง Workstation อืน ๆ ทั้งหมดในระบบเป็นลำดับที่ 1 ส่วนลำดับที่ 2 และ 3 ให้อ้างอิงไปยังฐานฐานเวลาภายนอก โดยรูปแบบการอ้างอิงฐานเวลาเป็นดังรูปข้างล่าง

รูปแสดงการอ้างอิงฐานเวลา

ส่วนตารางข้างล่างเป็นการอิงเวลามาตรฐานของประเทศไทย

ตารางแสดงการอิงเวลามาตรฐานของประเทศไทย

ขั้นตอนการติดตั้ง NTP Server ที่เครื่อง Log Server เป็นดังนี้

  1. ติดตั้ง ntp ด้วยสั่ง
    apt-get instal ntp
  2. ทำการสำเนาไฟล์คอนฟิกของ ntp ไปไว้เป็นอีกชื่อดังนี้
    cp /etc/ntp.conf /etc/ntp.conf.bak
  3. แก้ไขไฟล์ /etc/ntp.conf ให้มีค่าเป็นดังนี้
    restrict default kod nomodify notrap noquery nopeer
    restrict 127.0.0.1
    # อนุญาตให้ Internal network เข้าใช้งาน
    restrict 172.24.51.0 mask 255.255.255.0 nomodify notrap
    server 203.185.69.60 dynamic
    server time.navy.mi.th dynamic
    server time.nist.gov dynamic
    server 127.127.1.0 # local clock
    fudge 127.127.1.0 stratum 10
    driftfile /var/lib/ntp/ntp.drift
    broadcastdelay 0.008
    keys /etc/ntp/keys
  4. ตรวจสอบ Remote Server ที่ต้องการใช้อ้างอิงฐานเวลา ใช้คำสั่งดังนี้
    apt-get install ntpdate
    ntpdate -b 203.185.69.60
    ntpdate -b time.navy.mi.th
    ntpdate -b time.nist.gov
  5. สั่ง restart service ด้วยคำสั่ง
    /etc/init.d/ntp restart
  6. หลังจากที่ Server ทำงานปกติไม่มีการแจ้ง error ใด ๆ สามารถตรวจสอบตารางการทำงานของ Server ด้วยคำสั่ง
    ntpq -pn
    ซึ่งจะได้ผลดังนี้remote                     refid       st    t    when   poll     reach   delay     offset     jitter
    ================================================================
    203.185.69.60         .INIT.    16    u     –            64       0      0.000    0.000    0.000
    118.175.67.83         .INIT.    16    u     –            64       0      0.000    0.000    0.000
    192.43.244.18         .INIT.    16    u     –            64       0      0.000    0.000    0.000
    127.127.1.0             .LOCL. 10     l    54           64      7       0.000    0.000    0.001
  7. สามารถใช้เครื่อง Linux เครื่องอื่นในระบบทดสอบการทำงานของ Server ได้ด้วยคำสั่ง
    ntpdate <ip address> ใส่ ip address ของเครื่อง NTP Server

ขั้นตอนการติดตั้ง NTP Server ที่เครื่อง Server เครื่องอื่น (NTP client) เป็นดังนี้

  1. ติดตั้ง ntp ด้วยสั่ง
    apt-get instal ntp
  2. ทำการสำเนาไฟล์คอนฟิกของ ntp ไปไว้เป็นอีกชื่อดังนี้
    cp /etc/ntp.conf /etc/ntp.conf.bak
  3. แก้ไขค่าคอนไฟล์ของเครื่อง Linux Server อื่น ๆ ที่ไฟล์ /etc/ntp.conf ดังนี้
    server 192.168.9.12  ## ip address ของ NTP Server
    restrict 127.0.0.1
    driftfile /var/lib/ntp/ntp.drift

หมายเหตุ : สำหรับการทำ NTP Server จะมีการใช้งานโปรโตคอล NTP ซึ่งทำงานที่ port 123 ดังนั้นต้องดูเรื่องของ Firewal ให้เปิด port ดังกล่าวด้วย
การติดตั้ง syslog-ng ที่ centralized log

  1. ติดตั้ง syslog-ng ด้วยคำสั่ง
    apt-get install syslog-ng
  2. สำเนาไฟล์คอนฟิกของ syslog-ng คือไฟล์ /etc/syslog-ng/syslog-ng.conf ด้วยคำสั่ง
    cp /etc/syslog-ng/syslog-ng.conf /etc/syslog-ng/syslog-ng.conf.bak
  3. แ้ำก้ไขค่าคอนฟิกในไฟล์ /etc/syslog-ng/syslog-ng.conf ตามความเหมาะสม  ซึ่งในที่นี้ให้แก้ไขค่าในส่วนของ options ซึ่งมีโครงสร้างเป็นดังนี้
    options {
    – – – – –
    – – – – –
    – – – – –
    }
    โดยให้เพิ่มข้อความต่อไปนี้ลงไปในส่วนของ options เพื่อให้ syslog-ng ทำการเก็บชื่อ hostname ของเครื่องที่ส่ง log เข้ามา
    keep_hostname (yes);
  4. จากรูปเครือข่ายของผู้เขียนจะเห็นว่าโปรแกรม Freeraius ติดตั้งอยู่ีที่เดียวกับเครื่อง Centralized log ซึ่งปกติแล้ว detail file ซึ่งเป็นไฟล์ที่เก็บข้อมูลการ Login เข้าใช้งานโปรแกรม Freeradius จะอยู่ในตำแหน่ง /var/log/freeradius/radacct/ipaddress_of_client/detail-Ymd โดยค่า Ymd คือ Year month day ซึ่งชื่อไฟล์จะมีการแปรเปลี่ยนตามปีเดือนวัน ฉะนั้นถ้าต้องการให้สามารถส่ง detail file ดังกล่าวไปยัง syslog ได้  เราจะต้องทำการเปลี่ยนชื่อไฟล์ดังกล่าวให้มีชื่อที่คงที่คือไม่มีปีเดือนวัน  ด้วยการเปลี่ยนตัวแปร detailfile ในไฟล์ /etc/freeradius/radiusd.conf ดังนี้
    ให้เปลี่ยนค่า detailfile = ${radacctdir}/%{Client-IP-Address}/detail-%Y%m%d  เป็น
    detailfile = ${radacctdir}/%{Client-IP-Address}/details
    หมายเหตุ ถ้าไม่ต้องการส่ง freeradius detail file ไปยัง syslog ก็ไม่ต้องทำขั้นตอนนี้
  5. เพิ่ม log rotate ของ freeeradius ในส่วนของ detail file เื่ืพื่อแก้ปัญหาขนาดไฟล์ที่อาจจะใหญ่เกินไป ด้วยการเพิ่มข้อมูลต่อไปนี้ไปต่อท้ายของไฟล์ /etc/logrotate.d/freeradius/var/log/radius/radacct/172.24.51.16/details {
    rotate 13
    weekly
    missingok
    notifempty
    compress
    }
    หมายเหตุ ค่า 172.24.51.16 เป็น IP address ของเครื่อง client ที่เข้ามาใช้งาน freeradius server ซึ่งจากรูปคือเครื่อง 172.24.51.252 แต่มีการใช้งานผ่าน firewall ที่มีการทำ nat จึงต้องเปลี่ยนค่า IP เป็น 172.24.51.16
  6. สั่งให้มีการส่งขอมูลของ freeradius server ซึ่งในที่นี้คือ detail file ดังที่กล่าวมาไปยัง syslog-ng agent ด้วยการสร้างไฟล์ขึ้นมาหนึ่งไฟล์ในที่นี้คือ /etc/init.d/rc.capture และให้ป้อนข้อมูลต่อไปนี้เข้าไปในไฟล์
    #!/bin/bash
    tail -F /var/log/radius/radacct/127.0.0.1/details | logger -t freeradius -p local3.info&
  7. จากนั้นสั่งให้สามารถรันได้และสร้าง Link ให้ทำงานทุกครั้งหลังเิปิดเครื่องด้วยคำสั่ง
    chmod a+x /etc/init.d/rc.capture
    ln -s /etc/init.d/rc.capture /etc/rcS.d/S88rccapture
  8. ซึ่งเมื่อเราไปเปิด log file ของ syslog-ng (/var/log/syslog) ก็จะเห็นค่าของการ login เข้าใช้งาน freeradius เหมือนกับค่าในไฟล์ detail file ของ freeradius ดังรูป

การติดตั้ง syslog-ng ที่เครื่อง Authentication Gateway

  1. ติดตั้ง syslog-ng ด้วยคำสั่ง
    apt-get install syslog-ng
  2. กำหนดให้เครื่อง Authentication Gateway ส่ง log ไปยัง Centralized log ด้วยการเพิ่มเติมค่าคอนฟิกในไฟล์ /etc/syslog-ng/syslog-ng.conf ดังนี้
    destination remote {
    udp(“192.168.9.12” port(514));
    };
    log {source(s_all); filter(f_messages); destination(remote); };
    log {source(s_all); filter(f_kern); destination(remote); };สคริปต์ข้างบนเป็นการส่ง log ไปยังเครื่อง 192.168.9.12
  3. ทำการส่งค่า log ของ squid (/var/log/squid/access.log) ไปยัง syslog-ng agent ซึ่งก็คือส่งไปยัง syslog-ng agent ของเครื่องตัวเอง และหลังจากนั้น syslog-ng agent ในเครื่องตัวเองก็จะส่งต่อไปยัง remote syslog ต่อไป  โดยการส่งมี 2 วิธีคือ
    วิธีที่ 1 ส่ง log ของ squid ที่เก็บไว้ในไฟล์ /var/log/squid/access.log ในลักษณะที่สำเนาต่อไปยังยังเครื่อง centralized log ซึ่งทำได้ดังนี้

    1. ด้วยการสร้างไฟล์หนึ่งไฟล์ในที่นี้ชื่อว่า /etc/init.d/rc.capture และมีข้อความในไฟล์ดังนี้
      #!/bin/bash
      tail -F /var/log/squid/access.log | logger -t squid -p local3.info
    2. จากนั้นสั่งให้สามารถรันได้และสร้าง Link ให้ทำงานทุกครั้งหลังเิปิดเครื่องด้วยคำสั่ง
      chmod a+x /etc/init.d/rc.capture
      ln -s /etc/init.d/rc.capture /etc/rcS.d/S88rccapture
    3. เมื่อเราไปเิปิดดู log ที่ไฟล์ /var/log/syslog ของเครื่อง Centralized log จะได้ Log ของ squid ดังรูปรูปแสดง Log ของ squid บนเครื่อง Centralized Log

    วิธีที่ 2 ส่ง log ของ squid ไปยังเครื่อง Centralized log โดยไม่มีการเก็บ squid log (/var/log/squid/access.log) ไว้ในเครื่องของตัวเอง ทำดังนี้

    1. แก้ไขไฟล์ /etc/squid/squid.conf โดยแก้ไขค่าดังนี้
      ของเดิม
      access_log /var/log/squid/access.log squid
      แก้ไขเป็น
      access_log syslog:local7.info หรือ
      access_log syslog:local0.notice หรือ
      access_log syslog:local0.warning หรือแบบอื่น ขึ้นอยู่กับ facility และ priority
    2. สั่ง reconfigure squid ด้วยคำัสั่ง
      squid -k reconfigure
  4. ที่ผ่านมาจะเราสามารถเก็บ Log ของ Freeradius ซึ่งอยู่บนเครื่อง Centralized Log และเก็บ Log ของ Squid ที่อยู่ ณ เครื่อง Authentication Gateway ได้แล้ว ซึ่งเป็น Log หลัก ที่ควรจะเก็บเอาไว้ ต่อไปนี้ก็จะขึ้นอยู่กับนนโยบายของแต่ละหน่วยงานว่ามีการเปิดให้ใช้งานโปรโตคอลอื่น ๆ บน Authentication Gateway นอกเหนือจาก web หรือไม่ ซึ่งถ้าไม่เป็น การเก็บ Log แค่นี้ก็อาจจะเพียงพอแล้ว เพราะทุก application ที่ผู้ใช้ใช้งาน มีการใช้ผ่่าน squid อย่า่งเดียว  แต่ถ้ามีการใช้งานโปรโตคอลอื่น ๆ ด้วย ก็จะ้ต้องมีการเก็บ Log เพิ่มเติมต่อไป
  5. ในกรณีที่ต้องการเก็บ Log ของทราฟฟิกทั้งหมดที่เข้าทางขา eth1 (ซึ่ง chillispot จะสร้าง interface ที่เป็น tun0 ขึ้นมา) และออกทางขา eth0 ของ Authentication Gateway ให้เพิ่มคำสั่ง iptables ลงไปในไฟล์/etc/init.d/rc.capture โดยให้เพิ่มคำสั่งต่อไปนี้ลงไป
    iptables -A FORWARD -i tun0 -o eth0 -j LOG –log-level info –log-prefix “FORWARD “

การส่ง Log จาก Server อื่น ๆ ไปยัง Centralized Log

  1. ติดตั้ง NTP Server ที่เครื่อง Server เครื่องอื่น (NTP client) ตามวิธีการที่ได้กล่าวมาแล้วข้างบน
  2. ติดตั้ง syslog-ng ด้วยคำสั่ง
    apt-get install syslog-ng
  3. กำหนดให้เครื่อง Server อื่น ๆ ส่ง log ไปยัง Centralized log ด้วยการเพิ่มเติมค่าคอนฟิกในไฟล์ /etc/syslog-ng/syslog-ng.conf ดังนี้
    destination remote {
    udp(“202.129.16.26” port(514));
    };
    log {source(s_all); filter(f_messages); destination(remote); };
    log {source(s_all); filter(f_kern); destination(remote); };สคริปต์ข้างบนเป็นการส่ง log ไปยังเครื่อง 202.129.16.26
  4. แ้ก้ไขการกำหนดค่า log ของ Apache ที่ไฟล์คอนฟิกของ Apache (/etc/apache2/sites-available/default) เป็นดังนี้
    ของเดิม
    LogLevel warn
    แก้ไขเป็น
    LogLevel notice

กรณี Apache Web Server ให้ทำดังนี้
วิธีที่ 1 ทำการส่ง log ที่ถูกเก็บเอาไว้ในเครื่อง Web Server แล้ว (/var/log/apache2/access.log) และให้สำเนาส่งไปยัี่งครื่อง Centralized log ด้วย ทำดังนี้

  1. สร้างไฟล์ขึ้นมาหนึ่งไฟล์ในที่นี้ชื่อว่า /etc/init.d/rc.capture และมีข้อความในไฟล์ดังนี้
    #!/bin/bash
    tail -F /var/log/apache2/access.log | logger -t apache2_copy -p local3.info
  2. จากนั้นสั่งให้สามารถรันได้และสร้าง Link ให้ทำงานทุกครั้งหลังเิปิดเครื่องด้วยคำสั่ง
    chmod a+x /etc/init.d/rc.capture
    ln -s /etc/init.d/rc.capture /etc/rcS.d/S88rccapture
  3. เมื่อเราไปเิปิดดู log ที่ไฟล์ /var/log/syslog ของเครื่อง Centralized log จะได้ Log ของ apache ดังรูปจากรูปจะเห็นคำว่า ns2 ซึ่งเป็นชื่อ host ของ Web Server และคำว่า apache2_copy ซึ่งเป็นข้อความที่อยู่หลัง -t ของคำสั่งที่กล่าวมา  โดยเราสามารถที่จะเปลี่ยนแปลงค่าได้ตามความเหมาะสม  เพื่อให้บ่งบอกได้ว่าเป็น log ประเภทไหน

วิธีที่ 2 กำหนดให้ส่ง log จาก Apache Web Server (/var/log/apache2/access.log) ไปยัง Centralized Log โดยไม่มีการสำเนาเก็บไว้ที่ Apache Web Server ทำดังนี้

  1. แก้ไขคอนฟิกไฟล์ของ Apache (/etc/apache2/sites-available/default) ในส่วนของ Log ดังนี้
    ของเดิม
    CustomLog /var/log/apache2/access.log combined
    แก้ไขเป็น
    CustomLog “|/usr/bin/logger -t apache2 -p local1.info” combined
  2. สั่ง restart apache ด้วยคำสั่ง
    /etc/init.d/apache2 restart
  3. เมื่อเราไปเิปิดดู log ที่ไฟล์ /var/log/syslog ของเครื่อง Centralized log จะได้ Log ของ apache ดังรูป

การสั่งให้ Centralized log มีการเก็บ Log แบบกลั่นกรอง (Filter)
ที่ผ่านมาการเก็บ Log ของ Centralized Log Server มีการเก็บ log ไว้ที่ไฟล์ /var/log/syslog ทั้งหมด  ซึ่งจะยากต่อการมอนิเตอร์  วิธีการแก้ทำได้ด้วยการสั่งให้ syslog-ng มีการเก็บ log แบบกลั่นกรองคือกำหนดให้มีการเก็บ log ของแต่ละโปรแกรมหรือแต่ละบริการ แยกไฟล์ต่างหาก
ซึ่งสามารถทำได้ด้วยการแก้ไขไฟล์ /etc/syslog-ng/syslog-ng.conf แล้วเพิ่มค่าการ Filter ดังต่อไปนี้

  • สำหรับฟิลเตอร์โปรแกรม Freeraduisfilter f_radius { match(“radius”); };
    destination d_radius {
    file(“/var/log/$HOST/$YEAR/$MONTH/radius.$YEAR-$MONTH-$DAY”
    owner(root) group(adm) perm(665)
    create_dirs(yes) dir_perm(0775));
    };
    log { source(s_all); filter(f_radius); destination(d_radius); };
  • สำหรับฟิลเตอร์โปรแกรม squidfilter f_squid { match(“squid”); };
    destination d_squid {
    file(“/var/log/$HOST/$YEAR/$MONTH/squid.$YEAR-$MONTH-$DAY”
    owner(root) group(adm) perm(665)
    create_dirs(yes) dir_perm(0775));
    };
    log { source(s_all); filter(f_squid); destination(d_squid); };
  • สำหรับฟิลเตอร์โปรแกรม apachefilter f_apache { match(“apache”); };
    destination d_apache {
    file(“/var/log/$HOST/$YEAR/$MONTH/apache.$YEAR-$MONTH-$DAY”
    owner(root) group(adm) perm(665)
    create_dirs(yes) dir_perm(0775));
    };
    log { source(s_all); filter(f_apache); destination(d_apache); };

หมายเหตุ คำว่า match สำมารถใช้คำว่า program แทนได้
ซึ่งเมื่อเราทำการฟิลเตอร์แล้ว  เมื่อเข้าไปดูไฟล์ในไดเร็กทอรี่ที่กำหนด ก็จะได้ไฟล์เป็นดังรูป

รูปแสดง ไฟล์ที่เก็บ Log ซึ่งผ่านการ Filter แล้ว บน Centralized log ซึ่งเป็น Log ของ radius ที่ส่งมาจาก Server มีชื่อ Hostname เป็น qc

รูปแสดง ไฟล์ที่เก็บ Log ซึ่งผ่านการ Filter แล้ว บน Centralized log ซึ่งเป็น Log ของ squid ที่ส่งมาจาก Server มีชื่อ Hostname เป็น chilli

รูปแสดง ไฟล์ที่เก็บ Log ซึ่งผ่านการ Filter แล้ว บน Centralized log ซึ่งเป็น Log ของ apache ที่ส่งมาจาก Server มีชื่อ Hostname เป็น ns2
การเพิ่มชื่อผู้ใช้งานบน FreeRadius
เป็นการเพิ่มข้อมูลเข้าไปยังฐานข้อมูล MySQL ของ FreeRadius ซึ่งมีวิธีการเพิ่มที่สามารถทำได้ 3 วิธีคือ

  1. การเพิ่มผ่านโปรแกรม phpmyprepaid ซึ่งจะไ่ม่ขอกล่าวเพราะสามารถทำได้ง่ายผ่าน GUI
  2. การเพิ่มผ่านโปรแกรม phpmyadmin
    โดยตารางข้อมูลที่ใช้ี่สำหรับการเพิ่ม user ในเบื้องต้นมี 2 ตารางคือ ตาราง radcheck ซึ่งมีไว้เพื่อเก็บข้อมูลที่เป็น username และ password ของผู้ใช้งาน และตารางที่สองชื่อ radreply มีไว้สำหรับเก็บข้อมูลที่เกี่ยวกับคุณสมบัติการใช้งานของผู้ีใช้ เช่นเวลาในการใช้งานทั้งหมด (Session-Timeout) และเวลาที่เป็นที่เป็น Idle (Idle-Timeout) โดยข้อมูลตัวอย่างเป็นดังรูปตัวอย่างข้อมูลในตาราง radcheck

    ตัวอย่างข้อมูลในตาราง radreply

     

  3. การเพิ่มผู้ใช้งานด้วยการ import text file ผ่าน phpmyadmin โดยมีขั้นตอนดังนี้
    1. สร้าง text file เพื่อสร้างรายชื่อผู้ใช้งานในตาราง radcheck และตาราง radreply ให้มีนามสกุลเป็น *.sqlตัวอย่างการเพิ่มรายชื่อผู้ใช้งานในตาราง radcheck
      INSERT INTO radcheck VALUES (”, ‘somsak’, ‘User-Password’, ‘==’, ‘test123’),
      (”, ‘somchai’, ‘User-Password’, ‘==’, ‘test123’);

      ตัวอย่างการเพิ่มรายชื่อผู้ใช้งานในตาราง radreply
      INSERT INTO radreply VALUES (”, ‘somsak’, ‘Session-Timeout’, ‘:=’, 10800),
      (”, ‘somsak’, ‘Idle-Timeout’, ‘:=’, 1200);

    2. เปิด phpmyadmin แล้วเลือกเมนู import เพื่อทำการ import text file จากนั้นกดปุ่ม Browse เพื่อเลือก text file ที่ได้สร้างไว้ จากนั้นกดปุ่ม Go เพื่อทำการ import text file

ยังมีต่ออีกเร็ว ๆ นี้ครับ

ที่มา: http://www.itmanage.info/technology/linux/ubuntu/chillihospot/install_chillhotspot_ubutu_8_10.html

การติดตั้ง FreeRadius และ phpmyprepaid บน ubuntu 8.04

การติดตั้ง FreeRadius และ phpmyprepaid บน ubuntu 8.04

โดย อดิศร ขาวสังข์
จัดทำเมื่อ 15/11/2008
ติดตั้งบน Ubuntu 8.04
ขั้นตอน

  1. หากยังไม่ติดตั้ง apache และ php ให้ติดตั้งด้วยคำสั่ง
    apt-get install apache2 php5 php5-mysql
  2. สั่งให้ apache ทำงานด้วยคำสั่ง
    /etc/init.d/apache2 restart
  3. หากยังไม่ติดตั้ง mysql ให้ติดตั้งด้วยคำสั่ง
    apt-get install mysql-server
  4. หากยังไม่ติดตั้ง FreeRadius ให้ติดตั้งด้วยคำสั่ง
    apt-get install freeradius freeradius-mysql
  5. สั่งให้ FreeRadius ทำงานด้วยคำสั่ง
    /etc/init.d/freeradius start
  6. เข้าสู่โปรแกรม mysql ด้วย username คือ root และ password ที่ได้กำหนดไว้ด้วยคำสั่ง
    mysql –u root –p
    แล้วป้อนรหัสผ่านของ root
  7. ทำการสร้าง Database ชื่อ phpmyprepaid เพื่อใช้ในการเก็บบัญชีผู้ใช้งาน (สามารถจะใช้ชื่อฐานข้อมูลอื่นก็ได้) ด้วยคำสั่งดังนี้
    CREATE DATABASE phpmyprepaid;
  8. กำหนดสิทธิให้กับบัญชีผู้ใช้งานบน mysql ที่ชื่อว่า phpmyprepaid พร้อม password คือ radpass (user และ password สามารถเปลี่ยนแปลงได้ตามความเหมาะสม) ด้วยคำสั่ง
    GRANT ALL PRIVILEGES ON phpmyprepaid.* to ‘phpmyprepaid’@’localhost’ IDENTIFIED BY ‘radpass’;
    FLUSH PRIVILEGES;
  9. ออกจาก mysql ด้วยคำสั่ง quit
  10. แก้ไขไฟล์ /etc/freeradius/sql.conf เพื่อให้เรียกใช้ฐานข้อมูล phpmyprepaid ด้วยสิทธิผู้ใช้เป็น phpmyprepaid ซึ่งมี password เป็น radpass  ดังนี้
    # Connection info:
    server = “localhost”
    login = “phpmyprepaid”
    password = “radpass”
    # Database table configuration for everything except Oracle
    radius_db = “phpmyprepaid”
  11. ทำการกำหนด password ให้กับเครื่อง Client ที่จะเข้าใช้งาน FreeRadius ที่ไฟล์ /etc/freeradius/cliens.conf โดยกำหนดให้ client 127.0.0.1 มีค่า secret = radiussecret
    client localhost {
    secret = radiussecret
    {
    ในกรณีที่อนุญาตให้เครื่อง client อื่นเข้ามาใ้้ช้งาน FreeRadius เช่น client ที่มี IP เป็น 172.24.51.16 ก็ให้กำหนดค่าเพิ่มเติมดังนี้
    client 172.24.51.16 {
    secret = radiussecret
    shortname = chilli
    }
  12. ในกรณีที่จะอนุญาตให้เครื่อง Client อื่น ๆ (ที่ไม่ใช่เครื่องตัวเอง หรือ Localhost) เข้ามาใช้งาน FreeRadius ได้นั้นจะต้องทำการเพิ่มข้อมูลในไฟล์ /etc/freeradius/naslist ซึ่งในที่นี้คือเพิ่มบรรทัดสุดท้ายดังต่อไปนี้เข้าไป# NAS Name                  Short Name                 Type
    #—————-                   ———-                         —-
    #portmaster1.isp.com      pm1.NY                    livingston
    #portmaster2.isp.com      pm1.LA                     livingston
    localhost                          local                          portslave
    chilli                                  chilli                          other
  13. แก้ไขไฟล์ /etc/freeradius/sql.conf กำหนดให้ค่า readclients = yes เพื่อที่จะทำให้ radius client อ่านค่าจาก database
  14. แก้ไขไฟล์ /etc/freeradius/radiusd.conf ดังนี้
    • ในส่วนของ  accounting {……} ให้เอาเครื่องหมาย  # หน้าคำว่า sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ username , password ในการทำ accounting
    • ในส่วน session {……} ให้เอาเครื่องหมาย # หน้าคำว่า sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ username, password ในการทำ session
    • ในส่วนของ authorize {……} ให้เอาเครื่องหมาย # ไว้หน้าคำว่า file  และเอาเครื่องหมาย # ออกจากคำว่า sql
  15. ทำการ restart FreeRadius ด้วยคำสั่ง
    /etc/init.d/freeradius restart
  16. ตอนนี้ ทั้ง freeradius และ mysql พร้อม database phpmyprepaid ว่าง ๆ พร้อมแล้ว
    ต่อไปจะทำการติดตั้งโปรแกรม phpmyprepaid แล้วรันโปรแกรมผ่านเว็บบราวเซอร์
    จากนั้นจะเซ็ตค่าต่าง ๆ บนหน้าเว็บ ทำให้ได้ table ต่าง ๆ ที่จำเป็นใช้งานเกิดขึ้น
  17. ย้ายเข้าไปในไดเรกทอรี /var/www/ ด้วยคำสั่ง
    cd /var/www
  18. ดาวน์โหลดโปรแกรม phpmyprepaid เวอร์ชั่น 0.4 RC2 ด้วยคำสั่ง wget ดังนี้
    wget http://downloads.sourceforge.net/phpmyprepaid/phpmyprepaid04RC2.tgz
  19. คลายแฟ้มออกมาจะได้ไดเรกทอรี phpmyprepaid
    tar zxvf phpmyprepaid04RC2.tgz
  20. ติดตั้งโปรแกรม  rrdtool ด้วยคำสั่ง
    apt-get install rrdtool
  21. เปิด browser และเรียกไปที่ http://host/phpmyprepaid/www   แล้วระบบจะเปิดไฟล์ setup.php ดังรูป 
  22. ขั้นที่ 2 เป็นเรื่องของ License ให้คลิ๊กช่อง I Accept แล้วคลิ๊กปุ่ม Next 
  23. ขั้นตอนที่ 3 ถ้าเจอปัญหาดังรูปให้ใช้คำสั่ง
    chmod 777 /var/www/phpmyprepaid/www
    แล้วจะได้ผลลัพท์ดังรูป

     

  24. ขั้นตอนที่ 4 จะเป็นดังรูป ให้ป้อนค่าให้ถูกต้องโดยเฉพาะค่า Phpmyprepaid path อาจจะต้องเปลี่ยนให้ตรงความเป็นจริง 
  25. ขั้นตอนเป็นการคอนฟิก Radius ก็ให้ป้อนข้อมูลให้ตรงตามรูป 
  26. ขั้นที่ 6 เป็นการจัดการเรื่อง User Interface ก็ให้ป้อนข้อมูลตามต้องการ แต่อย่าลืม user และ password ที่ได้กำหนดไว้ด้วย 
  27. ขั้นตอนที่ 7 เป็นการคอนฟิกฐานข้อมูล ให้ป้อนข้อมูลตรงกับที่ได้กำหนดไว้ดังรูป 
  28. เมื่อป้อนข้อมูลในขั้นตอนที่ 7 ถูกต้อง ก็จะได้ผลลัพท์ดังขั้นตอนที่ 8 
  29. ขั้นตอนที่ 9 เป็นการป้อนข้อมูล Location ดังรูป 
  30. ขั้นตอนที่ 11 เป็นการคอนฟิกข้อมูลทั่วไป ดังรูป 
  31. ขั้นตอนที่ 11 เป็นขั้นตอนสุดท้าย ให้อ่านข้อความด้วยนะครับเพราะมีคำแนะนำบางอย่างที่ต้องทำตามด้วย 
  32. จากนั้นเมื่อเราเรียกใช้งาน http://host/phpmyprepaid/www/ ก็จะได้หน้าตาดังรูป 
  33. เมื่อ Login เข้าสู่ระบบได้แล้ว จะได้ผลลัพท์ดังรูป 
  34. รูปข้างล่างเป็นตัวอย่างการเพิ่ม Account ที่สามารถกำหนดความเร็วในการ upload และ download ได้ 
  35. ทดสอบการทำงานของ FreeRadius ด้วยคำสั่ง radtest
    radtest  username  password  localhost 0 mysecret
    ถ้าเซ็ตอัพถูกต้องและป้อนค่าถูกต้องจะได้ผลลัพธ์ว่า Access-Accept ดังรูป

จบครับ
ที่มา: http://www.itmanage.info/technology/linux/ubuntu/freeradius_phpmyprepaid/install_freeradius_phpmyprepaid_ubutu_8_04.html

การติดตั้ง FreeRadius และ phpmyprepaid บน ubuntu 8.04

การติดตั้ง FreeRadius และ phpmyprepaid บน ubuntu 8.04

โดย อดิศร ขาวสังข์
จัดทำเมื่อ 15/11/2008
ติดตั้งบน Ubuntu 8.04
ขั้นตอน

  1. หากยังไม่ติดตั้ง apache และ php ให้ติดตั้งด้วยคำสั่ง
    apt-get install apache2 php5 php5-mysql
  2. สั่งให้ apache ทำงานด้วยคำสั่ง
    /etc/init.d/apache2 restart
  3. หากยังไม่ติดตั้ง mysql ให้ติดตั้งด้วยคำสั่ง
    apt-get install mysql-server
  4. หากยังไม่ติดตั้ง FreeRadius ให้ติดตั้งด้วยคำสั่ง
    apt-get install freeradius freeradius-mysql
  5. สั่งให้ FreeRadius ทำงานด้วยคำสั่ง
    /etc/init.d/freeradius start
  6. เข้าสู่โปรแกรม mysql ด้วย username คือ root และ password ที่ได้กำหนดไว้ด้วยคำสั่ง
    mysql –u root –p
    แล้วป้อนรหัสผ่านของ root
  7. ทำการสร้าง Database ชื่อ phpmyprepaid เพื่อใช้ในการเก็บบัญชีผู้ใช้งาน (สามารถจะใช้ชื่อฐานข้อมูลอื่นก็ได้) ด้วยคำสั่งดังนี้
    CREATE DATABASE phpmyprepaid;
  8. กำหนดสิทธิให้กับบัญชีผู้ใช้งานบน mysql ที่ชื่อว่า phpmyprepaid พร้อม password คือ radpass (user และ password สามารถเปลี่ยนแปลงได้ตามความเหมาะสม) ด้วยคำสั่ง
    GRANT ALL PRIVILEGES ON phpmyprepaid.* to ‘phpmyprepaid’@’localhost’ IDENTIFIED BY ‘radpass’;
    FLUSH PRIVILEGES;
  9. ออกจาก mysql ด้วยคำสั่ง quit
  10. แก้ไขไฟล์ /etc/freeradius/sql.conf เพื่อให้เรียกใช้ฐานข้อมูล phpmyprepaid ด้วยสิทธิผู้ใช้เป็น phpmyprepaid ซึ่งมี password เป็น radpass  ดังนี้
    # Connection info:
    server = “localhost”
    login = “phpmyprepaid”
    password = “radpass”
    # Database table configuration for everything except Oracle
    radius_db = “phpmyprepaid”
  11. ทำการกำหนด password ให้กับเครื่อง Client ที่จะเข้าใช้งาน FreeRadius ที่ไฟล์ /etc/freeradius/cliens.conf โดยกำหนดให้ client 127.0.0.1 มีค่า secret = radiussecret
    client localhost {
    secret = radiussecret
    {
    ในกรณีที่อนุญาตให้เครื่อง client อื่นเข้ามาใ้้ช้งาน FreeRadius เช่น client ที่มี IP เป็น 172.24.51.16 ก็ให้กำหนดค่าเพิ่มเติมดังนี้
    client 172.24.51.16 {
    secret = radiussecret
    shortname = chilli
    }
  12. ในกรณีที่จะอนุญาตให้เครื่อง Client อื่น ๆ (ที่ไม่ใช่เครื่องตัวเอง หรือ Localhost) เข้ามาใช้งาน FreeRadius ได้นั้นจะต้องทำการเพิ่มข้อมูลในไฟล์ /etc/freeradius/naslist ซึ่งในที่นี้คือเพิ่มบรรทัดสุดท้ายดังต่อไปนี้เข้าไป# NAS Name                  Short Name                 Type
    #—————-                   ———-                         —-
    #portmaster1.isp.com      pm1.NY                    livingston
    #portmaster2.isp.com      pm1.LA                     livingston
    localhost                          local                          portslave
    chilli                                  chilli                          other
  13. แก้ไขไฟล์ /etc/freeradius/sql.conf กำหนดให้ค่า readclients = yes เพื่อที่จะทำให้ radius client อ่านค่าจาก database
  14. แก้ไขไฟล์ /etc/freeradius/radiusd.conf ดังนี้
    • ในส่วนของ  accounting {……} ให้เอาเครื่องหมาย  # หน้าคำว่า sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ username , password ในการทำ accounting
    • ในส่วน session {……} ให้เอาเครื่องหมาย # หน้าคำว่า sql ออก เพื่อเรียกใช้ข้อมูลจาก database ในการตรวจสอบ username, password ในการทำ session
    • ในส่วนของ authorize {……} ให้เอาเครื่องหมาย # ไว้หน้าคำว่า file  และเอาเครื่องหมาย # ออกจากคำว่า sql
  15. ทำการ restart FreeRadius ด้วยคำสั่ง
    /etc/init.d/freeradius restart
  16. ตอนนี้ ทั้ง freeradius และ mysql พร้อม database phpmyprepaid ว่าง ๆ พร้อมแล้ว
    ต่อไปจะทำการติดตั้งโปรแกรม phpmyprepaid แล้วรันโปรแกรมผ่านเว็บบราวเซอร์
    จากนั้นจะเซ็ตค่าต่าง ๆ บนหน้าเว็บ ทำให้ได้ table ต่าง ๆ ที่จำเป็นใช้งานเกิดขึ้น
  17. ย้ายเข้าไปในไดเรกทอรี /var/www/ ด้วยคำสั่ง
    cd /var/www
  18. ดาวน์โหลดโปรแกรม phpmyprepaid เวอร์ชั่น 0.4 RC2 ด้วยคำสั่ง wget ดังนี้
    wget http://downloads.sourceforge.net/phpmyprepaid/phpmyprepaid04RC2.tgz
  19. คลายแฟ้มออกมาจะได้ไดเรกทอรี phpmyprepaid
    tar zxvf phpmyprepaid04RC2.tgz
  20. ติดตั้งโปรแกรม  rrdtool ด้วยคำสั่ง
    apt-get install rrdtool
  21. เปิด browser และเรียกไปที่ http://host/phpmyprepaid/www   แล้วระบบจะเปิดไฟล์ setup.php ดังรูป 
  22. ขั้นที่ 2 เป็นเรื่องของ License ให้คลิ๊กช่อง I Accept แล้วคลิ๊กปุ่ม Next 
  23. ขั้นตอนที่ 3 ถ้าเจอปัญหาดังรูปให้ใช้คำสั่ง
    chmod 777 /var/www/phpmyprepaid/www
    แล้วจะได้ผลลัพท์ดังรูป

     

  24. ขั้นตอนที่ 4 จะเป็นดังรูป ให้ป้อนค่าให้ถูกต้องโดยเฉพาะค่า Phpmyprepaid path อาจจะต้องเปลี่ยนให้ตรงความเป็นจริง 
  25. ขั้นตอนเป็นการคอนฟิก Radius ก็ให้ป้อนข้อมูลให้ตรงตามรูป 
  26. ขั้นที่ 6 เป็นการจัดการเรื่อง User Interface ก็ให้ป้อนข้อมูลตามต้องการ แต่อย่าลืม user และ password ที่ได้กำหนดไว้ด้วย 
  27. ขั้นตอนที่ 7 เป็นการคอนฟิกฐานข้อมูล ให้ป้อนข้อมูลตรงกับที่ได้กำหนดไว้ดังรูป 
  28. เมื่อป้อนข้อมูลในขั้นตอนที่ 7 ถูกต้อง ก็จะได้ผลลัพท์ดังขั้นตอนที่ 8 
  29. ขั้นตอนที่ 9 เป็นการป้อนข้อมูล Location ดังรูป 
  30. ขั้นตอนที่ 11 เป็นการคอนฟิกข้อมูลทั่วไป ดังรูป 
  31. ขั้นตอนที่ 11 เป็นขั้นตอนสุดท้าย ให้อ่านข้อความด้วยนะครับเพราะมีคำแนะนำบางอย่างที่ต้องทำตามด้วย 
  32. จากนั้นเมื่อเราเรียกใช้งาน http://host/phpmyprepaid/www/ ก็จะได้หน้าตาดังรูป 
  33. เมื่อ Login เข้าสู่ระบบได้แล้ว จะได้ผลลัพท์ดังรูป 
  34. รูปข้างล่างเป็นตัวอย่างการเพิ่ม Account ที่สามารถกำหนดความเร็วในการ upload และ download ได้ 
  35. ทดสอบการทำงานของ FreeRadius ด้วยคำสั่ง radtest
    radtest  username  password  localhost 0 mysecret
    ถ้าเซ็ตอัพถูกต้องและป้อนค่าถูกต้องจะได้ผลลัพธ์ว่า Access-Accept ดังรูป

จบครับ
ที่มา: http://www.itmanage.info/technology/linux/ubuntu/freeradius_phpmyprepaid/install_freeradius_phpmyprepaid_ubutu_8_04.html

การติดตั้ง radius server ด้วยโปรแกรม freeradius

เป็นคำแนะนำติดตั้งจัดการปรับแต่ง radius server
ต้นแบบทดสอบด้วย linux fedora core 3,2,1 ใช้งานภายในมหาวิทยาลัยสงขลานครินทร์

วิธีติดตั้ง radius server ด้วยโปรแกรม freeradius
*** แหล่งข้อมูลต้นฉบับ freeradius คือ http://www.freeradius.org/

  1. ติดตั้งโปรแกรม freeradius ด้วยคำสั่ง
    apt-get install freeradius
  2. แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
    chkconfig radiusd on
  3. สั่งให้ทำงานด้วยคำสั่งว่า
    /etc/init.d/radiusd start
    Starting RADIUS server: [ OK ]
  4. ตรวจสอบว่าโปรแกรมทำงานแล้วด้วยคำสั่ง
    /etc/init.d/radiusd status
    ได้ผลออกมาดังตัวอย่าง
    radiusd (pid 19180) is running…
  5. แฟ้มที่เกี่ยวข้อง
    • /var/log/radius/radius.log
    • /etc/raddb/radiusd.conf
    • /etc/raddb/clients.conf
  6. เมื่อให้ radiusd ทำงานแล้ว เริ่มขั้นตอนทดสอบระบบโดยป้อนตัวอย่างคำสั่งดังนี้radtest root password-root localhost 0 testing123
    *** จากตัวอย่าง password-root คือรหัสผ่านของ root
    ได้ผลข้อความตอบกลับดังตัวอย่าง
    Sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    Re-sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “{\277\033\t\217\224\n\021\036\271$\301\026\234\353\225”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Reject packet from host 127.0.0.1:1812, id=43, length=20

    แสดงว่าระบบใช้งานได้แล้ว ถึงแม้ว่าจะมีการแจ้งว่า Access-Reject
    เป็นสาเหตุเนื่องจากไม่มีสิทธิในการอ่านแฟ้ม /etc/shadow ของระบบ

  7. หากต้องการให้ใช้กับบัญชีผู้ใช้ระบบ UNIX
    ต้องตั้งค่าให้อ่านแฟ้ม /etc/shadow ได้
    โดยแก้ไขแฟ้ม /etc/raddb/radiusd.conf
    ทำการ comment ยกเลิกบรรทัดข้อความจากเดิม
    user = radiusd
    group = radiusd
    ให้เป็น
    #user = radiusd
    #group = radiusd
    เสร็จแล้วให้ restart ระบบ radiusd ใหม่ด้วยคำสั่ง /etc/init.d/radiusd restart
    ต่อไปลองป้อนตัวอย่างคำสั่งเดิมเพื่อทดสอบดังนี้
    radtest root password-root localhost 0 testing123
    คราวนี้จะได้ผลข้อความว่า
    Sending Access-Request of id 82 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=82, length=20
    โดยมีผลการแจ้งว่า Access-Accept ถูกต้องตามต้องการ
  8. หากต้องการให้ radius client เข้ามาติดต่อใช้งานระบบ radiusd นี้ได้
    ให้แก้ไขแฟ้ม /etc/raddb/clients.conf ให้มีค่าดังตัวอย่างนี้
    client 10.0.1.0/24 {
    secret = mytestkey
    shortname = private-network
    }
    ตัวอย่างคือให้ radius client ที่มีหมายเลข ip 10.0.1.x
    สามารถเข้ามาใช้ด้วย secret key ว่า mytestkey
    เมื่อแก้ไขเสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ลองทดสอบด้วยคำสั่งตัวอย่าง
    radtest root passwordroot 10.0.1.1 0 mytestkey
    *** ค่า passwordroot คือ รหัสผ่านของ root และ 10.0.1.1 คือหมายเลข ip ของ radius server
    ได้ผลแสดงข้อความดังตัวอย่าง
    Sending Access-Request of id 246 to 10.0.1.1:1812
    User-Name = “root”
    User-Password = “passwordroot”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 10.0.1.1:1812, id=246, length=20ถึงขั้นตอนนี้เป็นอันเปิดใช้ระบบ radiusd ได้แล้ว
  9. หากต้องการให้ใช้ได้ดับ LDAP ด้วยให้แก้ไขแฟ้ม /etc/raddb/radiusd.conf
    เพื่อให้รองรับและเชื่อมต่อกับ LDAP server ดังนี้ต้องแก้ไขส่วนของ modules โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    modules {

    ldap {
    **** ให้แก้ไขค่าของ server , basedn ดังตัวอย่าง
    server = “myldap.net”
    basedn = “dc=my, dc=net”
    **** ให้ comment บรรทัด access_attr เพื่อยกเลิกค่า เนื่องจากไม่ได้ใช้รูปแบบนี้
    # access_attr = “dialupAccess”

    *** ในส่วนของ modules แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authorize โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authorize {

    # Read the ‘users’ file
    files
    *** ให้แก้ไขโดยแทรกเพิ่มบรรทัดข้อความว่า ldap ก่อนบรรทัดคำว่า files
    เพื่อให้ระบบทำการลำดับ authorize ด้วยแบบ ldap ก่อน
    หากไม่พบก็จะต่อด้วยแบบ files (แฟ้ม /etc/shadow)
    ถ้ากลับลำดับการ authorize อาจพบปัญหาผิดพลาดได้
    ดังตัวอย่างหลังการแทรกเพิ่มข้อความ
    # Read the ‘users’ file
    ldap
    files
    *** ในส่วนของ authorize แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authenticate โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authenticate {

    # Auth-Type LDAP {
    # ldap
    # }
    *** ให้แก้ไขด้วยการ uncomment บรรทัดข้อความเพื่อให้ระบบกำหนดวิธี LDAP
    Auth-Type LDAP {
    ldap
    }
    *** ในส่วนของ authenticate แก้ไขเพียงแค่นี้

    เสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ทดสอบใช้งานได้เลย

  10. แนะนำให้ยกเลิกการกำหนดค่าการทำงานบางตัวที่ไม่ได้ใช้งาน
    โดยการ comment บรรทัดข้อความในแฟ้ม /etc/raddb/radiusd.confถ้าไม่ได้ใช้เป็น proxy radius ควรยกเลิก
    โดยเปลี่ยนจากเดิม proxy_requests = yes
    ให้เป็น proxy_requests = no

    ควรยกเลิกบาง authorize ที่ไม่ได้ใช้เช่น
    authorize {
    # preprocess
    # chap
    # mschap
    # suffix
    # ldap —> ระบบ ldap
    # files –> ระบบ UNIX หรือแฟ้ม /etc/shadow

  11. การแสดงผลรายงานจำเป็นต้องหาโปรแกรมมาต่างหาก
    ขอแนะนำตัวอย่างโปรแกรมแสดงผลรายงาน

    • ต้นแหล่งข้อมูลคือ http://www.tummy.com/radiusContext/
      สามารถได้ดาวน์โหลดโปรแกรมได้ที่
      ftp://ftp.psu.ac.th/pub/freeradius/radiusContext-1.93.tar.gz
    • ให้ดาวน์โหลดมาแล้วขยายแฟ้มเก็บไว้ที่ /root ด้วยตัวอย่างคำสั่ง
      tar -C /root -zxvf radiusContext-1.93.tar.gz
    • สร้าง directory สำหรับแสดงผลบนเวบ ดังตัวอย่างคือ
      mkdir /var/www/html/radiusreport
      จะแสดงผลบนโฮมพจ http://x.x.x.x/radius-report
    • ตัวอย่าง ขั้นตอนที่ใช้สำหรับประมวลผลรวมข้อมูลจาก
      /var/log/radius/radacct ไปเก็บไว้เพื่อแสดงผลที่ /var/www/html/radius-report
      *** ภายใน /var/log/radius/radacct จะแยกเก็บข้อมูลเป็น directory ของ
      แต่ละหมายเลข ip ทำให้อาจยุ่งยากต่อการรวบรวมข้อมูล/root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
      /root/radiusContext-1.93/stdreport -D /var/www/html/radius-report

      *** ต้องใช้คำสั่งเหล่านี้ทุกครั้งเพื่อปรับปรุงผลรายงาน

    • ทดสอบผลรายงานได้เลยที่ http://x.x.x.x/radius-report

ที่มา: http://zeous21.exteen.com/20050919/radius-server-freeradius

การติดตั้ง radius server ด้วยโปรแกรม freeradius

เป็นคำแนะนำติดตั้งจัดการปรับแต่ง radius server
ต้นแบบทดสอบด้วย linux fedora core 3,2,1 ใช้งานภายในมหาวิทยาลัยสงขลานครินทร์

วิธีติดตั้ง radius server ด้วยโปรแกรม freeradius
*** แหล่งข้อมูลต้นฉบับ freeradius คือ http://www.freeradius.org/

  1. ติดตั้งโปรแกรม freeradius ด้วยคำสั่ง
    apt-get install freeradius
  2. แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
    chkconfig radiusd on
  3. สั่งให้ทำงานด้วยคำสั่งว่า
    /etc/init.d/radiusd start
    Starting RADIUS server: [ OK ]
  4. ตรวจสอบว่าโปรแกรมทำงานแล้วด้วยคำสั่ง
    /etc/init.d/radiusd status
    ได้ผลออกมาดังตัวอย่าง
    radiusd (pid 19180) is running…
  5. แฟ้มที่เกี่ยวข้อง
    • /var/log/radius/radius.log
    • /etc/raddb/radiusd.conf
    • /etc/raddb/clients.conf
  6. เมื่อให้ radiusd ทำงานแล้ว เริ่มขั้นตอนทดสอบระบบโดยป้อนตัวอย่างคำสั่งดังนี้radtest root password-root localhost 0 testing123
    *** จากตัวอย่าง password-root คือรหัสผ่านของ root
    ได้ผลข้อความตอบกลับดังตัวอย่าง
    Sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    Re-sending Access-Request of id 43 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “{\277\033\t\217\224\n\021\036\271$\301\026\234\353\225”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Reject packet from host 127.0.0.1:1812, id=43, length=20

    แสดงว่าระบบใช้งานได้แล้ว ถึงแม้ว่าจะมีการแจ้งว่า Access-Reject
    เป็นสาเหตุเนื่องจากไม่มีสิทธิในการอ่านแฟ้ม /etc/shadow ของระบบ

  7. หากต้องการให้ใช้กับบัญชีผู้ใช้ระบบ UNIX
    ต้องตั้งค่าให้อ่านแฟ้ม /etc/shadow ได้
    โดยแก้ไขแฟ้ม /etc/raddb/radiusd.conf
    ทำการ comment ยกเลิกบรรทัดข้อความจากเดิม
    user = radiusd
    group = radiusd
    ให้เป็น
    #user = radiusd
    #group = radiusd
    เสร็จแล้วให้ restart ระบบ radiusd ใหม่ด้วยคำสั่ง /etc/init.d/radiusd restart
    ต่อไปลองป้อนตัวอย่างคำสั่งเดิมเพื่อทดสอบดังนี้
    radtest root password-root localhost 0 testing123
    คราวนี้จะได้ผลข้อความว่า
    Sending Access-Request of id 82 to 127.0.0.1:1812
    User-Name = “root”
    User-Password = “password-root”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=82, length=20
    โดยมีผลการแจ้งว่า Access-Accept ถูกต้องตามต้องการ
  8. หากต้องการให้ radius client เข้ามาติดต่อใช้งานระบบ radiusd นี้ได้
    ให้แก้ไขแฟ้ม /etc/raddb/clients.conf ให้มีค่าดังตัวอย่างนี้
    client 10.0.1.0/24 {
    secret = mytestkey
    shortname = private-network
    }
    ตัวอย่างคือให้ radius client ที่มีหมายเลข ip 10.0.1.x
    สามารถเข้ามาใช้ด้วย secret key ว่า mytestkey
    เมื่อแก้ไขเสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ลองทดสอบด้วยคำสั่งตัวอย่าง
    radtest root passwordroot 10.0.1.1 0 mytestkey
    *** ค่า passwordroot คือ รหัสผ่านของ root และ 10.0.1.1 คือหมายเลข ip ของ radius server
    ได้ผลแสดงข้อความดังตัวอย่าง
    Sending Access-Request of id 246 to 10.0.1.1:1812
    User-Name = “root”
    User-Password = “passwordroot”
    NAS-IP-Address = 10.0.1.2
    NAS-Port = 0
    rad_recv: Access-Accept packet from host 10.0.1.1:1812, id=246, length=20ถึงขั้นตอนนี้เป็นอันเปิดใช้ระบบ radiusd ได้แล้ว
  9. หากต้องการให้ใช้ได้ดับ LDAP ด้วยให้แก้ไขแฟ้ม /etc/raddb/radiusd.conf
    เพื่อให้รองรับและเชื่อมต่อกับ LDAP server ดังนี้ต้องแก้ไขส่วนของ modules โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    modules {

    ldap {
    **** ให้แก้ไขค่าของ server , basedn ดังตัวอย่าง
    server = “myldap.net”
    basedn = “dc=my, dc=net”
    **** ให้ comment บรรทัด access_attr เพื่อยกเลิกค่า เนื่องจากไม่ได้ใช้รูปแบบนี้
    # access_attr = “dialupAccess”

    *** ในส่วนของ modules แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authorize โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authorize {

    # Read the ‘users’ file
    files
    *** ให้แก้ไขโดยแทรกเพิ่มบรรทัดข้อความว่า ldap ก่อนบรรทัดคำว่า files
    เพื่อให้ระบบทำการลำดับ authorize ด้วยแบบ ldap ก่อน
    หากไม่พบก็จะต่อด้วยแบบ files (แฟ้ม /etc/shadow)
    ถ้ากลับลำดับการ authorize อาจพบปัญหาผิดพลาดได้
    ดังตัวอย่างหลังการแทรกเพิ่มข้อความ
    # Read the ‘users’ file
    ldap
    files
    *** ในส่วนของ authorize แก้ไขเพียงแค่นี้
    ต่อไปแก้ไขส่วนของ authenticate โดยค้นเข้าไปที่บริเวณพื้นที่ขึ้นต้นด้วยข้อความว่า
    authenticate {

    # Auth-Type LDAP {
    # ldap
    # }
    *** ให้แก้ไขด้วยการ uncomment บรรทัดข้อความเพื่อให้ระบบกำหนดวิธี LDAP
    Auth-Type LDAP {
    ldap
    }
    *** ในส่วนของ authenticate แก้ไขเพียงแค่นี้

    เสร็จแล้วให้ reload ใหม่ด้วยคำสั่ง /etc/init.d/radiusd reload
    ทดสอบใช้งานได้เลย

  10. แนะนำให้ยกเลิกการกำหนดค่าการทำงานบางตัวที่ไม่ได้ใช้งาน
    โดยการ comment บรรทัดข้อความในแฟ้ม /etc/raddb/radiusd.confถ้าไม่ได้ใช้เป็น proxy radius ควรยกเลิก
    โดยเปลี่ยนจากเดิม proxy_requests = yes
    ให้เป็น proxy_requests = no

    ควรยกเลิกบาง authorize ที่ไม่ได้ใช้เช่น
    authorize {
    # preprocess
    # chap
    # mschap
    # suffix
    # ldap —> ระบบ ldap
    # files –> ระบบ UNIX หรือแฟ้ม /etc/shadow

  11. การแสดงผลรายงานจำเป็นต้องหาโปรแกรมมาต่างหาก
    ขอแนะนำตัวอย่างโปรแกรมแสดงผลรายงาน

    • ต้นแหล่งข้อมูลคือ http://www.tummy.com/radiusContext/
      สามารถได้ดาวน์โหลดโปรแกรมได้ที่
      ftp://ftp.psu.ac.th/pub/freeradius/radiusContext-1.93.tar.gz
    • ให้ดาวน์โหลดมาแล้วขยายแฟ้มเก็บไว้ที่ /root ด้วยตัวอย่างคำสั่ง
      tar -C /root -zxvf radiusContext-1.93.tar.gz
    • สร้าง directory สำหรับแสดงผลบนเวบ ดังตัวอย่างคือ
      mkdir /var/www/html/radiusreport
      จะแสดงผลบนโฮมพจ http://x.x.x.x/radius-report
    • ตัวอย่าง ขั้นตอนที่ใช้สำหรับประมวลผลรวมข้อมูลจาก
      /var/log/radius/radacct ไปเก็บไว้เพื่อแสดงผลที่ /var/www/html/radius-report
      *** ภายใน /var/log/radius/radacct จะแยกเก็บข้อมูลเป็น directory ของ
      แต่ละหมายเลข ip ทำให้อาจยุ่งยากต่อการรวบรวมข้อมูล/root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
      /root/radiusContext-1.93/stdreport -D /var/www/html/radius-report

      *** ต้องใช้คำสั่งเหล่านี้ทุกครั้งเพื่อปรับปรุงผลรายงาน

    • ทดสอบผลรายงานได้เลยที่ http://x.x.x.x/radius-report

ที่มา: http://zeous21.exteen.com/20050919/radius-server-freeradius