การทำ Wireless LAN Controller ด้วย Chillispot แบบ web login + freeradius + mysql + transparent proxy

ก่อนอื่นให้เครดิตผู้เขียนนิดนึงครับ
คุณวิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ มหาวิทยาลัยสงขลานครินทร์ ( wiboon.w (at) psu.ac.th )
ต้นฉบับ http://mamboeasy.psu.ac.th/~wiboon.w/content/view/58/40/
เอกสารอ้างอิง
แหล่งข้อมูลต้นฉบับ chillispot คือ http://www.chillispot.info
ขอขอบคุณ คุณวิภัทร ศรุติพรหม ให้ความรู้ linux server ที่เวบไซต์ http://www.opensource.psu.ac.th เมนู ทำง่าย-ใช้เป็น
ขอขอบคุณ คุณ au ร.ร.จุฬาภรณราชวิทยาลัย ปทุมธานี ให้ตัวอย่าง radius attribute

เอกสารนี้ใช้เพื่อ
เป็นคำแนะนำในการติดตั้งและปรับแต่ง Linux server ให้เป็น Wireless LAN Access Point Controller ด้วยโปรแกรม chillispot
เลือกวิธีการ authentication แบบ web login โดยตรวจสอบ username ที่ freeradius ที่ใช้ mysql เป็น database
รวมทั้งติดตั้ง proxy server ด้วยโปรแกรม squid แบบ transparent proxy เพื่อให้เครื่องไคลเอนต์ (โน้ตบุ๊ค) ที่ไม่เซ็ตค่าพร็อกซี่ก็สามารถใช้งานอินเทอร์เน็ตได้ทันทีภายหลังจากที่ ตรวจสอบ username ผ่านแล้ว
เอกสารนี้แบ่งออกเป็น 3 ตอน
ตอนที่ 1

  • การติดตั้ง Linux server
  • การติดตั้งโปรแกรม Apache web server
  • การติดตั้งโปรแกรม Freeradius
  • ทดสอบ authentication โดยใช้ username/password ของ Unix
  • การติดตั้งโปรแกรม Chillispot แบบ Web login

ตอนที่ 2

  • การติดตั้งโปรแกรม Mysql
  • ตัวอย่าง radius attribute
    • Max-All-Session
    • Max-Daily-Session
    • Max-Monthly-Session
    • Session-Timeout
    • WISPr-Bandwidth-Max-Down
    • WISPr-Bandwidth-Max-Up
    • Simultaneous-Use
  • ทดสอบ authentication โดยใช้ username/password ของ Mysql
  • การติดตั้งโปรแกรม radiusContext เพื่อทำรายงานการใช้งาน Freeradius

ตอนที่ 3

  • การติดตั้งโปรแกรม squid
  • การทำ Transparent proxy ด้วย iptables
  • การตั้งเวลาเก็บ access.log ทุกคืน

ตอนที่ 4

  • รออาสาสมัครที่สามารถใช้ php + mysql เขียนโปรแกรมจัดการบัญชีผู้ใช้ chillispot ด้วย php + mysql

รูปภาพการติดตั้ง

ข้อมูลเครือข่าย

  • eth0 คือ แลนการ์ดใบที่ 1 ต่อกับอินเทอร์เน็ต ได้รับแจก ip จาก dhcp server ในอินเทอร์เน็ต
  • eth1 คือ แลนการ์ดใบที่ 2 ต่อกับแอคเซสพอยต์ ได้รับแจก ip จาก chillispot server
  • แอคเซสพอยต์ได้รับแจก ip จาก chillispot server
  • ไคลเอนต์ที่มาต่อกับแอคเซสพอยต์ได้รับแจก ip จาก chillispot server ส่งต่อโดยแอคเซสพอยต์
  • chillispot server 1 เครื่อง ติดตั้งโปรแกรมดังนี้
    • Linux fedora core 6
    • freeradius 1.1.* (rpm) (ทดสอบแล้ว 1.1.3 – 1.1.7)
    • apache 2.2.* (rpm) (ทดสอบแล้ว 2.2.3 – 2.2.6)
    • chillispot 1.1.0 (rpm)

[Day 1]
ตอนที่ 1
1.1 การติดตั้ง Linux server
คำแนะนำการติดตั้ง

  • ในขั้นตอนที่ติดตั้งจากแผ่นซีดี ให้เลือก Package selection เป็น Software Development
  • ในขั้นตอนที่ติดตั้งจากแผ่นซีดีครบแล้ว เมื่อรีบูตกลับมาให้ปิด SeLinux โดยเปลี่ยนจาก enforcing เป็น disabled

คำแนะนำการใช้งาน

  • การคอนฟิกระบบจะง่ายขึ้น ให้ใช้วิธีการ copy และ paste คำสั่งหรือข้อความจากเอกสารที่กำลังอ่านอยู่นี้
    หากภายหลังการติดตั้งได้รับหน้าจอเป็น text mode ให้เปลี่ยนเป็นกราฟฟิคโหมด ด้วยคำสั่ง startx
  • เปิดวินโดวชื่อ terminal เพื่อใช้ในการปรับแต่งและรันคำสั่ง ดังนี้ คลิก Application, Accessories, Terminal
  • โปรแกรม editor ที่ใช้ในการแก้ไขค่าคือ gedit เป็น full screen editor ใช้เมาส์คลิกวางตำแหน่ง cursor ได้
    จบด้วยคลิกปุ่ม Save และคลิก X เพื่อปิดโปรแกรม

1.1.1 การปรับแต่งระบบลินุกซ์
(ดัดแปลงจาก การปรับแต่งระบบลินุกซ์หลังการติดตั้ง (28-9-2550) วิภัทร ศรุติพรหม http://rd.cc.psu.ac.th/content/view/14/46/ )
1. ตรวจสอบการ์ดแลนพร้อมใช้งานด้วยคำสั่ง
ifconfig -a
ผลลัพธ์

[root@dhcp160 ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:60:97:A5:38:6F
inet addr:192.168.2.220 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: 2001:3c8:9009:300:260:97ff:fea5:386f/64 Scope:Global
inet6 addr: fe80::260:97ff:fea5:386f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:126 errors:0 dropped:0 overruns:0 frame:0
TX packets:46 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9430 (9.2 KiB) TX bytes:8450 (8.2 KiB)
Interrupt:9 Base address:0x2080

eth1 Link encap:Ethernet HWaddr 00:01:03:18:BA:59
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:431699 errors:0 dropped:0 overruns:520 frame:0
TX packets:858 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:32878596 (31.3 MiB) TX bytes:88551 (86.4 KiB)
Interrupt:5

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:34660 errors:0 dropped:0 overruns:0 frame:0
TX packets:34660 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:9917351 (9.4 MiB) TX bytes:9917351 (9.4 MiB)

2. หากต้องการเปลี่ยนรหัสผ่านของ root ทำด้วยคำสั่ง
passwd
ผลลัพธ์

[root@dhcp160 ~]# passwd
Changing password for user root.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

3. ยกเลิกการตั้งค่า update อัตโนมัติ ด้วยคำสั่งดังนี้คือ
service yum-updatesd stop
chkconfig yum-updatesd off
ผลลัพธ์

[root@dhcp160 ~]# service yum-updatesd stop
Stopping yum-updatesd: [ OK ]
[root@dhcp160 ~]# chkconfig yum-updatesd off [root@dhcp160 ~]#

4. ตั้งเวลาให้ตรงกับสากลด้วยคำสั่ง /usr/sbin/ntpdate -u <ชื่อเซิร์ฟเวอร์>
โดยที่
pool.ntp.org เป็น ntp server ที่เป็นสากลโดยตร
ใช้คำสั่ง
/usr/sbin/ntpdate -u pool.ntp.org
ผลลัพธ์

[root@dhcp160 ~]# /usr/sbin/ntpdate -u pool.ntp.org
27 Nov 17:20:45 ntpdate[22639]: step time server 61.19.242.42 offset -130.874347 sec

ต้องการให้ทุกครั้งที่บูทเครื่องมีการตั้งเวลาใหม่ ให้แก้ไขแฟ้ม /etc/rc.local ใช้คำสั่ง
gedit /etc/rc.local
เพิ่มบรรทัดข้อความว่า
/usr/sbin/ntpdate -u pool.ntp.org
บันทึกและปิดหน้าต่าง gedit
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don’t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/sbin/ntpdate -u pool.ntp.org

ตั้งเวลาให้ตรงกับสากลทุกวัน ให้สร้างแฟ้มข้อมูลชื่อ /etc/cron.daily/ntp.cron ใช้คำสั่ง
gedit /etc/cron.daily/ntp.cron
มีข้อมูลดังนี้
#!/bin/sh
/usr/sbin/ntpdate -u pool.ntp.org
และเปลี่ยนโหมดของแฟ้มเป็น execute ด้วยคำสั่ง
chmod +x /etc/cron.daily/ntp.cron
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/cron.daily/ntp.cron

#!/bin/sh /usr/sbin/ntpdate -u pool.ntp.org

[root@dhcp160 ~]# chmod +x /etc/cron.daily/ntp.cron [root@dhcp160 ~]#

5. เกี่ยวกับ SeLinux อาจทำให้การใช้งานบางอย่างยากขึ้น ให้เปลี่ยนจาก enforcing เป็น disabled โดยแก้ไขแฟ้ม /etc/selinux/config ใช้คำสั่ง
gedit /etc/selinux/config
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing – SELinux security policy is enforced. (default)
# permissive – SELinux prints warnings instead of enforcing.
# disabled – SELinux is fully disabled.
SELINUX=disabled # SELINUXTYPE= type of policy in use. Possible values are:
# targeted – Only targeted network daemons are protected.
# strict – Full SELinux protection.
SELINUXTYPE=targeted

1.1.2 การ update packages linux fedora core 6 ให้ทันสมัย
สั่งปรับปรุงรายชื่อ package ให้ทันสมัยตามแหล่งข้อมูลต้นทาง
yum check-update
สั่งปรับปรุง/ติดตั้ง package ให้ทันสมัย
yum update
ผลลัพธ์

[root@dhcp160 ~]# yum check-update
Loading “installonlyn” plugin
Setting up repositories
extras 100% |=========================| 1.1 kB 00:00
updates 100% |=========================| 1.2 kB 00:00
base 100% |=========================| 951 B 00:00
Reading repository metadata in from local files
primary.xml.gz 100% |=========================| 1.7 MB 00:00

[root@dhcp160 ~]# yum update
Loading “installonlyn” plugin
Setting up Update Process
Setting up repositories
Reading repository metadata in from local files

Transaction Summary
=============================================================================
Install 11 Package(s)
Update 329 Package(s)
Remove 0 Package(s)

Total download size: 524 M
Is this ok [y/N]:y
… more lines…
[root@dhcp160 ~]#

1.2 การติดตั้งโปรแกรม Apache web server
ชื่อแฟ้มที่เกี่ยวข้องเมื่อติดตั้งเสร็จแล้ว
/var/log/httpd/access.log
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/
1. ติดตั้งโปรแกรม httpd พร้อมคู่มือ ด้วยคำสั่ง
yum install httpd
yum install httpd-manual
yum install mod_ssl
ผลลัพธ์

[root@dhcp160 ~]# yum install httpd
=============================================================================
Package Arch Version Repository Size
=============================================================================
Updating:
httpd i386 2.2.6-1.fc6 updates 1.0 M

Transaction Summary
=============================================================================

Complete!
[root@dhcp160 ~]# yum install httpd-manual
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
httpd-manual i386 2.2.6-1.fc6 updates 812 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp160 ~]# yum install mod_ssl
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mod_ssl i386 1:2.2.6-1.fc6 updates 84 k
Installing for dependencies:
distcache i386 1.4.5-14.1 base 120 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp160 ~]#

2. แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
chkconfig httpd on
ผลลัพธ์

[root@dhcp160 ~]# chkconfig httpd on
[root@dhcp160 ~]#

3. สั่งให้ทำงานด้วยคำสั่งว่า
service httpd start
ผลลัพธ์

[root@dhcp160 ~]# service httpd start
Starting httpd: [ OK ]
[root@dhcp160 ~]#

1.3 การติดตั้งโปรแกรม Freeradius
ชื่อแฟ้มที่เกี่ยวข้องเมื่อติดตั้งเสร็จแล้ว
/var/log/radius/radius.log
/etc/raddb/radiusd.conf
/etc/raddb/clients.conf
1. ติดตั้งโปรแกรม freeradius ด้วยคำสั่ง
yum install freeradius
แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
chkconfig radiusd on
สั่งให้ทำงานด้วยคำสั่งว่า
service radiusd start
ผลล้ัพธ์

[root@dhcp160 ~]# yum install freeradius
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
freeradius i386 1.1.7-3.1.fc6 updates 1.2 M
Installing for dependencies:
lm_sensors i386 2.10.1-1.fc6 updates 506 k
net-snmp i386 1:5.3.1-15.fc6 updates 695 k
net-snmp-utils i386 1:5.3.1-15.fc6 updates 179 k
perl-DBI i386 1.52-1.fc6 base 605 k

Transaction Summary
=============================================================================
Install 5 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 3.1 M
Is this ok [y/N]: y
Downloading Packages:

Complete!
[root@dhcp160 ~]# chkconfig radiusd on
[root@dhcp160 ~]# service radiusd start
radiusd is stopped
Starting RADIUS server: [ OK ]
[root@dhcp160 ~]#

1.4 ทดสอบ authentication โดยใช้ username/password ของ Unix
1. (หากยังไม่มี) ให้เตรียม username ที่จะใช้ทดสอบชื่อ chilli มีรหัสผ่านเป็น abcd1234 ด้วยคำสั่งดังนี้
adduser chilli
passwd chilli
ผลลัพธ์

[root@dhcp160 ~]# adduser chilli
[root@dhcp160 ~]# passwd chilli
Changing password for user chilli.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully. [root@dhcp160 ~]#

2. เมื่อให้ radiusd ทำงานแล้ว เริ่มขั้นตอนทดสอบระบบโดยป้อนตัวอย่างคำสั่งดังนี้
radtest chilli abcd1234 localhost 0 testing123
จะมีการแจ้งว่า Access-Reject
เป็นสาเหตุเนื่องจากไม่มีสิทธิในการอ่านแฟ้ม /etc/shadow ของระบบ
ผลลัพธ์

[root@dhcp160 ~]# radtest chilli abcd1234 localhost 0 testing123
Sending Access-Request of id 232 to 127.0.0.1 port 1812
User-Name = “chilli”
User-Password = “abcd1234”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
Re-sending Access-Request of id 232 to 127.0.0.1 port 1812
User-Name = “chilli”
User-Password = “abcd1234”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Reject packet from host 127.0.0.1:1812, id=232, length=20 [root@dhcp160 ~]#

หมายเหตุ คำว่า localhost คือ ชื่อโดเมนของไอพีแอดเดรส 127.0.0.1 ก็คือ ตัวเครื่องเซิร์ฟเวอร์เอง
ซึ่งต้องมีระบุไว้ในแฟ้ม /etc/hosts ใช้คำสั่งดูข้อมูลข้างในแฟ้มดังนี้
cat /etc/hosts

[root@dhcp160 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost [root@dhcp160 ~]#

3. แก้ไขให้อ่านแฟ้ม /etc/shadow ได้ โดยแก้ไขแฟ้ม /etc/raddb/radiusd.conf
3.1 ให้ทำการสำรองแฟ้มต้นฉบับเก็บไว้ก่อน ด้วยคำสั่ง
cp /etc/raddb/radiusd.conf /etc/raddb/radiusd.conf.save
ผลลัพธ์

[root@dhcp160 ~]# cp /etc/raddb/radiusd.conf /etc/raddb/radiusd.conf.save [root@dhcp160 ~]#

3.2 แก้ไขแฟ้ม /etc/raddb/radiusd.conf เพื่อทำการ comment ยกเลิกบรรทัดข้อความจากเดิม
user = radiusd
group = radiusd
ให้เป็น
#user = radiusd
#group = radiusd
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/raddb/radiusd.conf

Line 114
#user = radiusd #group = radiusd

3.3 เสร็จแล้วให้ restart ระบบ radiusd ใหม่ด้วยคำสั่ง
service radiusd restart
ผลลัพธ์

[root@dhcp160 ~]# service radiusd restart
radiusd (pid 23004) is running…
radiusd (pid 23004) is running…
Stopping RADIUS server: [ OK ]
radiusd is stopped
Starting RADIUS server: [ OK ] [root@dhcp160 ~]#

3.4 ต่อไปลองป้อนตัวอย่างคำสั่งเดิมเพื่อทดสอบดังนี้
radtest chilli abcd1234 localhost 0 testing123
จะมีการแจ้งว่า Access-Accept ถูกต้องตามต้องการ
ผลลัพธ์

[root@dhcp160 ~]# radtest chilli abcd1234 localhost 0 testing123
Sending Access-Request of id 39 to 127.0.0.1 port 1812
User-Name = “chilli”
User-Password = “abcd1234”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=39, length=20
[root@dhcp160 ~]#

3.5 ในการนำไปใช้งานจริง ขอให้แก้ไข secret ใหม่ ตัวอย่างเช่น ตั้งใหม่เป็น mytestkey
ให้แก้ไขแฟ้ม /etc/raddb/clients.conf ของโปรแกรม freeradius ให้มีค่าดังตัวอย่างนี้
client 127.0.0.1 {

บรรทัดที่ 35 เดิม secret = testing123
แก้ไขเป็น secret = mytestkey

}
เสร็จแล้วให้ restart ระบบ radiusd ใหม่ด้วยคำสั่ง
service radiusd restart
ทดสอบ radius อีกครั้งด้วย secret อันใหม่ ดังนี้
radtest chilli abcd1234 localhost 0 mytestkey
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/raddb/clients.conf

Line 35
secret = mytestkey

[root@dhcp160 ~]# service radiusd restart radiusd (pid 23068) is running…
radiusd (pid 23068) is running…
Stopping RADIUS server: [ OK ]
radiusd is stopped
Starting RADIUS server: [ OK ]

[root@dhcp160 ~]# radtest chilli abcd1234 localhost 0 mytestkey
Sending Access-Request of id 166 to 127.0.0.1 port 1812
User-Name = “chilli”
User-Password = “abcd1234”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=166, length=20
[root@dhcp160 ~]#

1.5 การติดตั้งโปรแกรม Chillispot แบบ Web login
ชื่อแฟ้มที่เกี่ยวข้องเมื่อติดตั้งเสร็จแล้ว
/etc/chilli.conf
/var/www/cgi-bin/hotspotlogin.cgi
/var/www/html/welcome.html
/etc/firewall.iptables
————————————-
โปรดตรวจสอบ
เนื่องจาก chillispot จะเป็น dhcp server เอง
กรณีที่นำเครื่องเดิมมาติดตั้ง chillispot เพิ่ม จะต้องเช็คว่าในเครื่องไม่มี dhcp server รันอยู่ ถ้ามีอยู่ก็หยุดดังนี้
service dhcpd stop
chkconfig dhcpd off
————————————-
1. เราต้องทำให้เครื่องนี้ทำหน้าที่เป็นเราเตอร์เพื่อ forward packet ทุกครั้งที่รีบูตเครื่อง
ให้แก้ไขแฟ้ม /etc/sysctl.conf ให้มีค่าดังตัวอย่างนี้
บรรทัดที่ 7 เดิม net.ipv4.ip_forward = 0
แก้ไขเป็น net.ipv4.ip_forward = 1
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/sysctl.conf

# Controls IP packet forwarding
net.ipv4.ip_forward = 1

2. เพื่อให้มีผลทันทีในขณะนี้ ให้เครื่อง forward packet
รันคำสั่ง echo “1″ > /proc/sys/net/ipv4/ip_forward

ผลลัพธ์

[root@dhcp160 ~]# echo “1” > /proc/sys/net/ipv4/ip_forward
[root@dhcp160 ~]#

3. เพื่อให้การ์ดแลน eth1 ไม่รับ dhcp ตอนรีบูตเครื่อง
ให้แก้ไขแฟ้ม /etc/sysconfig/network-scripts/ifcfg-eth1 ให้มีค่าดังตัวอย่างนี้
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/sysconfig/network-scripts/ifcfg-eth1

# 3Com Corporation 3c905C-TX/TX-M [Tornado]
DEVICE=eth1 BOOTPROTO=none HWADDR=00:01:03:18:BA:59 ONBOOT=yes

4. ดาวน์โหลดโปรแกรม chillispot จากเครื่องเอฟทีพีของม.อ. ด้วยคำสั่ง wget ดังนี้
wget ftp://ftp.psu.ac.th/pub/chillispot/chillispot-1.1.0.i386.rpm
ผลลัพธ์

[root@dhcp160 ~]# wget ftp://ftp.psu.ac.th/pub/chillispot/chillispot-1.1.0.i386.rpm
–20:25:02– ftp://ftp.psu.ac.th/pub/chillispot/chillispot-1.1.0.i386.rpm
=> chillispot-1.1.0.i386.rpm'
Resolving ftp.psu.ac.th... 192.168.100.101
Connecting to ftp.psu.ac.th|192.168.100.101|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD /pub/chillispot ... done.
==> SIZE chillispot-1.1.0.i386.rpm ... 88761
==> PASV ... done. ==> RETR chillispot-1.1.0.i386.rpm ... done.
Length: 88761 (87K)

100%[=======================================>] 88,761 --.-K/s in 0.04s

20:25:03 (2.00 MB/s) - chillispot-1.1.0.i386.rpm’ saved [88761]
[root@dhcp160 ~]#

หรือดาวน์โหลดจากเว็บต้นฉบับที่ http://www.chillispot.info/download.html

http://www.chillispot.info/download.html
Suitable for Redhat 9, Fedora (FC1, FC2 and FC3 and FC4).

http://www.chillispot.info/download/chillispot-1.1.0.i386.rpm

Or other linux distro.

http://www.chillispot.info/download/chillispot-1.1.0.tar.gz

5. แล้วติดตั้ง package rpm ด้วยคำสั่งดังนี้
rpm -Uvh chillispot-1.1.0.i386.rpm
ผลลัพธ์

[root@dhcp160 ~]# rpm -Uvh chillispot-1.1.0.i386.rpm
Preparing… ########################################### [100%]
1:chillispot ########################################### [100%] [root@dhcp160 ~]#

6. แก้ไขแฟ้ม /etc/chilli.conf ให้มีค่าดังตัวอย่างนี้
[หัวข้อ TUN parameters]
บรรทัดที่ 38 เดิม net 192.168.182.0/24
แก้ไขเป็น net 10.0.1.0/24
[หัวข้อ Radius parameters]
บรรทัดที่ 113 เดิม radiusserver1 rad01.chillispot.org
แก้ไขเป็น radiusserver1 127.0.0.1
บรรทัดที่ 120 เดิม radiusserver2 rad02.chillispot.org
แก้ไขเป็น radiusserver2 127.0.0.1
บรรทัดที่ 139 เดิม #radiussecret testing123
แก้ไขเป็น radiussecret mytestkey
(ตรงกับ radius secret ในแฟ้ม /etc/raddb/clients.conf ของ freeradius)
[หัวข้อ Universal access method (UAM) parameters]
บรรทัดที่ 237 เดิม #uamserver https://radius.chillispot.org/hotspotlogin
แก้ไขเป็น uamserver https://10.0.1.1/cgi-bin/hotspotlogin.cgi
บรรทัดที่ 244 เดิม #uamhomepage http://192.168.182.1/welcome.html
แก้ไขเป็น uamhomepage http://10.0.1.1/welcome.html
บรรทัดที่ 248 เดิม #uamsecret ht2eb8ej6s4et3rg1ulp
แก้ไขโดยให้เอาเครื่องหมาย# ออก เป็น uamsecret ht2eb8ej6s4et3rg1ulp
(หรือแก้ไขเป็นรหัสใหม่ แต่ต้องเหมือนกับในแฟ้ม hotspotlogin.cgi ในข้อถัดไป)
บรรทัดที่ 253 เดิม #uamlisten 192.168.182.1
แก้ไขเป็น uamlisten 10.0.1.1
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/chilli.conf

Line 38
net 10.0.1.0/24 radiusserver1 127.0.0.1 radiusserver2 127.0.0.1 radiussecret mytestkey uamserver https://10.0.1.1/cgi-bin/hotspotlogin.cgi uamhomepagehttp://10.0.1.1/welcome.html uamsecret ht2eb8ej6s4et3rg1ulp uamlisten 10.0.1.1

7. ให้คัดลอกแฟ้ม firewall.iptables ด้วยคำสั่ง
cp /usr/share/doc/chillispot-1.1.0/firewall.iptables /etc
ให้คัดลอกแฟ้ม hotspotlogin.cgi ด้วยคำสั่ง
cp /usr/share/doc/chillispot-1.1.0/hotspotlogin.cgi /var/www/cgi-bin/
ผลลัพธ์

[root@dhcp160 ~]# cp /usr/share/doc/chillispot-1.1.0/firewall.iptables /etc
[root@dhcp160 ~]# cp /usr/share/doc/chillispot-1.1.0/hotspotlogin.cgi /var/www/cgi-bin/ [root@dhcp160 ~]#

8. แก้ไขแฟ้ม /var/www/cgi-bin/hotspotlogin.cgi ให้มีค่าดังตัวอย่างนี้
บรรทัดที่ 27 เดิม #$uamsecret = “ht2eb8ej6s4et3rg1ulp”;
แก้ไขโดยให้เอาเครื่องหมาย# ออก เป็น $uamsecret = “ht2eb8ej6s4et3rg1ulp”;
บรรทัดที่ 31 เดิม #$userpassword=1;
แก้ไขโดยให้เอาเครื่องหมาย# ออก เป็น $userpassword=1;
ผลลัพธ์

[root@dhcp160 ~]# gedit /var/www/cgi-bin/hotspotlogin.cgi

Line 27
$uamsecret = “ht2eb8ej6s4et3rg1ulp”;

# Uncomment the following line if you want to use ordinary user-password
# for radius authentication. Must be used together with $uamsecret.
$userpassword=1;

9. สร้างแฟ้ม /var/www/html/welcome.html ให้มีค่าดังตัวอย่างนี้

ผลลัพธ์

[root@dhcp160 ~]# gedit /var/www/html/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” mce_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://10.0.1.1:3990/prelogin” mce_href=”http://10.0.1.1:3990/prelogin”>Click here to login</a></H3>
<p>
<p>Enjoy.
</center>
</body>
</html>

10. ถ้าต้องการรูป chillispot.png ให้ดาวน์โหลดได้ที่นี่
wget http://mamboeasy.psu.ac.th/~wiboon.w/images/stories/chillispot/chillispo…
แล้วคัดลอกแฟ้มนี้ไปไว้ใน /var/www/html ด้วยคำสั่งดังนี้
cp chillispot.png /var/www/html
ผลลัพธ์

[root@dhcp160 ~]# wget http://mamboeasy.psu.ac.th/~wiboon.w/images/stories/ chillispot/chillispot.png
[root@dhcp160 ~]# cp chillispot.png /var/www/html [root@dhcp160 ~]#

11. ก่อนที่จะสตาร์ท chillispot ให้ไปทำการคอนฟิกแอคเซสพอยน์/ไวร์เลสเราเตอร์ ให้พร้อมใช้งาน โดยทำตามเอกสารของแต่ละรุ่น
ความต้องการคือ ให้ทำ factory defaults แล้วกำหนดให้มันจะต้องรับ dhcp ip จาก chillispot และตัวมันเองจะต้องไม่ทำหน้าที่แจก ip
รวมทั้งควรแก้ไข ESSID ตั้งชื่อใหม่ด้วย เพื่อให้รู้ว่าตัวไหนของเรา ดูตัวอย่างบางรุ่นในเว็บนี้ได้
หมายเหตุ Linksys WRT54GL ที่ผมนำมา upgrade firmware เป็น DD-WRT แล้ว
ผมพบว่า ต้อง Enable DHCP server ให้กับ port LAN 1-4 ของเราเตอร์ด้วย
มันยังคงแจกไอพีให้กับ เครื่องที่ต่อ port LAN 1-4 แต่มันไม่แจกไอพีให้ไวร์เลส
12. เปิดใช้งาน iptables เพื่อทำเป็น firewall ด้วยคำสั่ง
sh /etc/firewall.iptables
ผลลัพธ์

[root@dhcp160 ~]# sh /etc/firewall.iptables
[root@dhcp160 ~]#

13. สั่งให้ chillispot ทำงานด้วยคำสั่ง
service chilli start
ผลลัพธ์

[root@dhcp160 ~]# service chilli start
Starting chilli: [ OK ]

14. ตรวจสอบการทำงานของ chiilispot ว่าสร้างอินเทอร์เฟส tun0 พร้อมใช้งานและมีเลข IP เป็น 10.0.1.1
โดยที่อินเทอร์เฟส eth1 จะไม่มี IP ใด ๆ ส่วน eth0 ก็เป็นเลข IP ที่รับจากเน็ตที่เซิร์ฟเวอร์นี้ต่ออยู่เหมือนเดิม
ด้วยคำสั่ง ifconfig ดังตัวอย่าง
ผลลัพธ์

[root@dhcp160 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:60:97:A5:38:6F
inet addr:192.168.2.220 Bcast:192.168.2.255 Mask:255.255.255.0

eth1 Link encap:Ethernet HWaddr 00:01:03:18:BA:59
inet6 addr: fe80::201:3ff:fe18:ba59/64 Scope:Link
UP BROADCAST RUNNING MTU:1500 Metric:1

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0

tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.0.1.1 P-t-P:10.0.1.1 Mask:255.255.255.0
UP POINTOPOINT RUNNING MTU:1500 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:116 (116.0 b) TX bytes:240 (240.0 b)
[root@dhcp160 ~]#

15. ให้จดเลข Mac address ของโน้ตบุ๊คที่จะนำมาทดสอบการเชื่อมต่อกับ chillispot
และรันคำสั่งตรวจสอบว่าโน้ตบุ๊คได้ IP Address จาก chillispot ดังนี้
tail -f /var/log/messages
จะได้ผลลัพธ์แสดงคล้าย ๆ ตังอย่างข้างล่างนี้
ผลลัพธ์

[root@dhcp160 ~]# tail -f /var/log/messages
Nov 27 20:05:18 dhcp160 Installed: httpd-manual.i386 2.2.6-1.fc6
Nov 27 20:06:54 dhcp160 Installed: distcache.i386 1.4.5-14.1
Nov 27 20:06:57 dhcp160 Installed: mod_ssl.i386 1:2.2.6-1.fc6
Nov 27 20:57:57 dhcp160 chillispot[23328]: ChilliSpot 1.1.0.
Copyright 2002-2005 Mondru AB. Licensed under GPL.
See http://www.chillispot.org for credits.
Nov 27 20:57:57 dhcp160 kernel: tun: Universal TUN/TAP device driver, 1.6
Nov 27 20:57:57 dhcp160 kernel: tun: (C) 1999-2004 Max Krasnyansky <
maxk@qualcomm.com

>
Nov 27 20:57:57 dhcp160 kernel: ADDRCONF(NETDEV_CHANGE): tun0: link becomes ready
Nov 27 20:57:57 dhcp160 kernel: eth1: setting full-duplex.
Nov 27 20:58:00 dhcp160 chillispot[23328]: chilli.c: 3509:
New DHCP request from MAC=00-1D-7E-27-C3-18
Nov 27 20:58:00 dhcp160 chillispot[23328]: chilli.c: 3479:
Client MAC=00-1D-7E-27-C3-18 assigned IP 10.0.1.2
Nov 27 21:16:55 dhcp160 chillispot[23328]: chilli.c: 3509:
New DHCP request from MAC=00-13-02-69-41-FA
Nov 27 21:16:55 dhcp160 chillispot[23328]: chilli.c: 3479:
Client MAC=00-13-02-69-41-FA assigned IP 10.0.1.3
Nov 27 21:20:32 dhcp160 chillispot[23328]: chilli.c: 3759:
Successful UAM login from username=chilli IP=10.0.1.3
Ctrl-C break

โดยที่ 10.0.1.2 จะเป็น IP ของแอคเซสพอยน์ และ 10.0.1.3 จะเป็น IP ของโน้ตบุ๊คตัวแรกที่เชื่อมต่อ
16. เริ่มขั้นตอนทดสอบระบบที่เครื่องโน้ตบุคดังนี้
เริ่มทำการคอนเนค W-IFI
คลิกที่นี่เพื่อดูรูป
ที่บราวเซอร์ให้ยกเลิกการเซ็ตพร็อกซี่เซิร์ฟเวอร์
ที่บราวเซอร์ที่มีการเซ็ตหน้าโฮมเพจไว้ จะถูก redirect ไปยัง welcome.html ทันทีเมื่อเรียกโปรแกรม คลิกที่นี่เพื่อดูรูป
คลิกที่ข้อความ Click here to login แล้วจะมีหน้าต่างเพื่อให้ใส่ username และ password
คลิกที่นี่เพื่อดูรูป
เมื่อ login เข้าได้สำเร็จจะมีหน้าต่าง logged in พร้อมเวลาเริ่มนับ และเอาไว้ใช้สำหรับ logout
คลิกที่นี่เพื่อดูรูป
17. แก้ไขแฟ้ม /etc/rc.local เพื่อให้ firewall.iptables และ chilli มีผลทำงานด้วยเมื่อรีบูตเครื่องใหม่
เพิ่มบรรทัด 2 บรรทัดนี้ต่อท้าย
sh /etc/firewall.iptables
service chilli start
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don’t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/sbin/ntpdate -u pool.ntp.org
sh /etc/firewall.iptables
service chilli start

18. รีบูตเครื่องเซิร์ฟเวอร์ 1 ครั้ง
19. ถึงขั้นตอนนี้เป็นอันเปิดใช้ระบบ chillispot แบบ web login ได้แล้ว
[Day 2]
ตอนที่ 2
2.1 การติดตั้งโปรแกรม Mysql
1. ติดตั้งโปรแกรม mysql ด้วยคำสั่งดังนี้
yum install mysql
yum install mysql-server
ผลลัพธ์

[root@dhcp220 ~]# yum install mysql
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mysql i386 5.0.27-1.fc6 updates 3.3 M

Transaction Summary
=============================================================================

Complete!

[root@dhcp220 ~]# yum install mysql-server
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mysql-server i386 5.0.27-1.fc6 updates 10 M
Installing for dependencies:
perl-DBD-MySQL i386 3.0007-1.fc6 base 147 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp220 ~]#

2. สั่งให้รันทุกครั้งที่รีบูตเครื่อง ด้วยคำสั่งดังนี้
chkconfig mysqld on
ผลลัพธ์

[root@dhcp220 ~]# chkconfig mysqld on
[root@dhcp220 ~]#

3. รัน mysqld ด้วยคำสั่ง
service mysqld start
ผลลัพธ์

[root@dhcp220 ~]# service mysqld start
Initializing MySQL database: Installing all prepared tables
Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h dhcp220.cc.psu.ac.th password ‘new-password’
See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the ‘sql-bench’ directory:
cd sql-bench ; perl run-all-tests

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com
[ OK ]
Starting MySQL: [ OK ]
[root@dhcp220 ~]#

4. เปลี่ยนรหัสผ่านให้กับ admin ของ mysql ด้วยคำสั่งดังนี้
/usr/bin/mysqladmin -u root password ‘abcd1234′
ผลลัพธ์

[root@dhcp220 ~]# /usr/bin/mysqladmin -u root password ‘abcd1234’
[root@dhcp220 ~]#

5. เข้าไปสร้าง database และ user ชื่อ radius เพื่อให้ freeradius ใช้ฐานข้อมูลที่เกี่ยวข้องในการ authentication ได้ ดังนี้
mysql -uroot -pabcd1234
สร้าง database ชื่อ radius ดังนี้
CREATE DATABASE radius;
สร้าง user ที่มีสิทธิใน database ดังนี้
GRANT ALL PRIVILEGES ON radius.* to ‘radius’@’localhost’ IDENTIFIED BY ‘abcd1234′;
FLUSH PRIVILEGES;
ออกจาก mysql ด้วยคำสั่ง
quit
ผลลัพธ์

[root@dhcp220 ~]# mysql -uroot -pabcd1234
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3 to server version: 5.0.27

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql>
mysql> CREATE DATABASE radius;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON radius.* to ‘radius’@’localhost’
IDENTIFIED BY ‘abcd1234’;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@dhcp220 ~]#

6. ใส่ database schema ด้วยคำสั่งดังนี้ (ตรวจสอบเลขเวอร์ชั่นก่อน)
mysql -uroot -pabcd1234 radius < /usr/share/doc/freeradius-?.?.?/examples/mysql.sql
ผลลัพธ์

[root@dhcp220 ~]# mysql -uroot -pabcd1234 radius < /usr/share/doc/freeradius-1.1.*/
examples/mysql.sql
[root@dhcp220 ~]#

7. เข้าไปใน mysql อีกครั้งด้วยคำสั่ง
mysql -uroot -pabcd1234
เปิดใช้ฐานข้อมูลชื่อ radius
use radius;
แล้วใส่ข้อมูลตัวอย่าง
บัญชีผู้ใช้ fredf จะได้รับสิทธิ 3 ชั่วโมงต่อวัน (10800 วินาที) ใช้ได้สูงสุด 90 ชั่วโมง (324000 วินาที)
ถูกกำหนดให้ใช้งานได้ (session) 1 ชั่วโมงต่อครั้ง (3600 วินาที) และสามารถดาวน์โหลดได้ที่ 56K และอัปโหลดได้ที่ 33.4K
บัญชีผู้ใช้ barney จะได้รับสิทธิ 3 ชั่วโมงต่อวัน (10800 วินาที) และถูกกำหนดให้ใช้งานได้ 1 ชั่วโมงต่อครั้ง
บัญชีผู้ใช้ dialrouter จะได้รับสิทธิเดือนละ 90 ชั่วโมง (324000 วินาที) และถูกกำหนดให้ใช้งานได้ 30 นาทีต่อครั้ง
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Password’, ‘==’, ‘wilma’);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Max-Daily-Session’, ‘:=’, ’10800′);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Max-All-Session’, ‘:=’, ’324000′);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘barney’, ‘Password’, ‘==’, ‘betty’);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘barney’, ‘Max-Daily-Session’, ‘:=’, ’10800′);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘dialrouter’, ‘Password’, ‘==’, ‘dialup’);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘dialrouter’, ‘Max-Monthly-Session’, ‘:=’, ’324000′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Idle-Timeout’, ‘:=’, ’1800′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Session-Timeout’, ‘:=’, ’3600′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘WISPr-Bandwidth-Max-Down’, ‘:=’, ’56000′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘WISPr-Bandwidth-Max-Up’, ‘:=’, ’33400′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘barney’, ‘Idle-Timeout’, ‘:=’, ’1800′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘barney’, ‘Session-Timeout’, ‘:=’, ’3600′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘dialrouter’, ‘Idle-Timeout’, ‘:=’, ’900′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘dialrouter’, ‘Session-Timeout’, ‘:=’, ’1800′);
INSERT INTO usergroup (UserName, GroupName) VALUES (‘fredf’, ‘dynamic’);
INSERT INTO usergroup (UserName, GroupName) VALUES (‘barney’, ‘static’);
INSERT INTO usergroup (UserName, GroupName) VALUES (‘dialrouter’, ‘netdial’);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘dynamic’, ‘Auth-Type’, ‘:=’, ‘Local’);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘dynamic’, ‘Simultaneous-Use’, ‘:=’, ’1′);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘static’, ‘Auth-Type’, ‘:=’, ‘Local’);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘static’, ‘Simultaneous-Use’, ‘:=’, ’1′);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘netdial’, ‘Auth-Type’, ‘:=’, ‘Local’);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘netdial’, ‘Simultaneous-Use’, ‘:=’, ’1′);
INSERT INTO radgroupreply (GroupName, Attribute, Op, Value) VALUES (‘dynamic’, ‘Service-Type’, ‘:=’, ‘Login-User’);
INSERT INTO radgroupreply (GroupName, Attribute, Op, Value) VALUES (‘static’, ‘Service-Type’, ‘:=’, ‘Login-User’);
INSERT INTO radgroupreply (GroupName, Attribute, Op, Value) VALUES (‘netdial’, ‘Service-Type’, ‘:=’, ‘Login-User’);
คำสั่งที่ใช้แสดงข้อมูลเรคคอร์ดใน table
show tables;
select * from radcheck;
select * from radreply;
select * from usergroup;
select * from radgroupcheck;
select * from radgroupreply;
แล้วออกจาก mysql
ผลลัพธ์

[root@dhcp220 ~]# mysql -uroot -pabcd1234
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5 to server version: 5.0.27

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql> use radius;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES
(‘fredf’, ‘Password’, ‘==’, ‘wilma’);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO radgroupreply (GroupName, Attribute, Op, Value) VALUES
(‘netdial’, ‘Service-Type’, ‘:=’, ‘Login-User’);
Query OK, 1 row affected (0.00 sec)

mysql> show tables;
+——————+
| Tables_in_radius |
+——————+
| nas |
| radacct |
| radcheck |
| radgroupcheck |
| radgroupreply |
| radippool |
| radpostauth |
| radreply |
| usergroup |
+——————+
9 rows in set (0.00 sec)

mysql> select * from radcheck;
+—-+————+———————+—-+——–+
| id | UserName | Attribute | op | Value |
+—-+————+———————+—-+——–+
| 1 | fredf | Password | == | wilma |
| 2 | fredf | Max-Daily-Session | := | 10800 |
| 3 | fredf | Max-All-Session | := | 324000 |
| 4 | barney | Password | == | betty |
| 5 | barney | Max-Daily-Session | := | 10800 |
| 6 | dialrouter | Password | == | dialup |
| 7 | dialrouter | Max-Monthly-Session | := | 324000 |
+—-+————+———————+—-+——–+
7 rows in set (0.02 sec)

mysql> select * from radreply;
+—-+————+————————–+—-+——-+
| id | UserName | Attribute | op | Value |
+—-+————+————————–+—-+——-+
| 1 | fredf | Idle-Timeout | := | 1800 |
| 2 | fredf | Session-Timeout | := | 3600 |
| 3 | fredf | WISPr-Bandwidth-Max-Down | := | 56000 |
| 4 | fredf | WISPr-Bandwidth-Max-Up | := | 33400 |
| 5 | barney | Idle-Timeout | := | 1800 |
| 6 | barney | Session-Timeout | := | 3600 |
| 7 | dialrouter | Idle-Timeout | := | 900 |
| 8 | dialrouter | Session-Timeout | := | 1800 |
+—-+————+————————–+—-+——-+
8 rows in set (0.00 sec)

mysql> select * from usergroup;
+————+———–+———-+
| UserName | GroupName | priority |
+————+———–+———-+
| fredf | dynamic | 1 |
| barney | static | 1 |
| dialrouter | netdial | 1 |
+————+———–+———-+
3 rows in set (0.01 sec)

mysql> select * from radgroupcheck;
+—-+———–+——————+—-+——-+
| id | GroupName | Attribute | op | Value |
+—-+———–+——————+—-+——-+
| 1 | dynamic | Auth-Type | := | Local |
| 2 | dynamic | Simultaneous-Use | := | 1 |
| 3 | static | Auth-Type | := | Local |
| 4 | static | Simultaneous-Use | := | 1 |
| 5 | netdial | Auth-Type | := | Local |
| 6 | netdial | Simultaneous-Use | := | 1 |
+—-+———–+——————+—-+——-+
6 rows in set (0.00 sec)

mysql> select * from radgroupreply;
+—-+———–+————–+—-+————+
| id | GroupName | Attribute | op | Value |
+—-+———–+————–+—-+————+
| 1 | dynamic | Service-Type | := | Login-User |
| 2 | static | Service-Type | := | Login-User |
| 3 | netdial | Service-Type | := | Login-User |
+—-+———–+————–+—-+————+
3 rows in set (0.00 sec)

mysql> quit
Bye
[root@dhcp220 ~]#

8. ติดตั้งโปรแกรมเพิ่มเพื่อให้ mysql ทำงานร่วมกับ freeradius ได้
yum install freeradius-mysql
ผลลัพธ์

[root@dhcp220 ~]# yum install freeradius-mysql
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
freeradius-mysql i386 1.1.7-3.1.fc6 updates 17 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp220 ~]#

9. แก้ไขไฟล์ /etc/raddb/sql.conf
บรรทัดที่ 21 แก้ไขให้เป็น
login = “radius”
password = “abcd1234″
radius_db = “radius”
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/raddb/sql.conf

# Connect info
server = “localhost”
login = “radius”
password = “abcd1234”

# Database table configuration
radius_db = “radius”

10. แก้ไขไฟล์ /etc/raddb/radiusd.conf
ใน section module {}
บรรทัดที่ 1261 เดิม # $INCLUDE ${confdir}/sql.conf
แก้ไขโดยการเอาคอมเมนต์ออก เป็น $INCLUDE ${confdir}/sql.conf
ใน section authorize {}
บรรทัดที่ 1858 เดิม files
แก้ไขโดยการใส่คอมเมนต์ เป็น #files
บรรทัดที่ 1865 เดิม #sql
แก้ไขโดยการเอาคอมเมนต์ออก เป็น sql
ใน section accounting {}
บรรทัดที่ 2028 เดิม #sql
แก้ไขโดยการเอาคอมเมนต์ออก เป็น sql
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/raddb/radiusd.conf

Line 1261
# Include another file that has the SQL-related configuration.
# This is another file only because it tends to be big.
#
# The following configuration file is for use with MySQL.
#
# For Postgresql, use: ${confdir}/postgresql.conf
# For MS-SQL, use: ${confdir}/mssql.conf
# For Oracle, use: ${confdir}/oraclesql.conf
#
$INCLUDE ${confdir}/sql.conf

Line 1858

#files

Line 1865
#
# Look in an SQL database. The schema of the database
# is meant to mirror the “users” file.
#
# See “Authorization Queries” in sql.conf
sql

Line 2028
#
# Log traffic to an SQL database.
#
# See “Accounting queries” in sql.conf
sql

11. สั่งรีสตาร์ท radius ใหม่ ด้วยคำสั่ง
service radiusd restart
ผลลัพธ์

[root@dhcp220 ~]# service radiusd restart
radiusd (pid 2062) is running…
radiusd (pid 2062) is running…
Stopping RADIUS server: [ OK ]
radiusd is stopped
Starting RADIUS server: Wed Nov 28 09:55:07 2007 : Info: Starting – reading configur
ation files …
[ OK ]
[root@dhcp220 ~]#

12. ทดสอบการเข้าใช้งาน ดังนี้
radtest fredf wilma localhost 0 mytestkey
ผลลัพธ์

[root@dhcp220 ~]# radtest fredf wilma localhost 0 mytestkey
Sending Access-Request of id 124 to 127.0.0.1 port 1812
User-Name = “fredf”
User-Password = “wilma”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=124, length=62
Idle-Timeout = 1800
Session-Timeout = 3600
WISPr-Bandwidth-Max-Down = 56000
WISPr-Bandwidth-Max-Up = 33400
Service-Type = Login-User
[root@dhcp220 ~]#

13. ตรวจสอบข้อผิดพลาดได้ที่ /var/log/radius/radius.log และ /var/log/radius/radius.log
ผลลัพธ์

[root@dhcp220 ~]# tail -f /var/log/radius/radius.log

Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #0
Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #1
Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #2
Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #3
Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #4
Wed Nov 28 09:55:08 2007 : Info: Ready to process requests.
[root@dhcp220 ~]#
[root@dhcp220 ~]# tail -f /var/log/mysqld.log

InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
071128 9:16:14 InnoDB: Started; log sequence number 0 0
071128 9:16:14 [Note] /usr/libexec/mysqld: ready for connections.
Version: ‘5.0.27’ socket: ‘/var/lib/mysql/mysql.sock’ port: 3306 Source distribution
[root@dhcp220 ~]#

14. ตรวจสอบดูข้อมูลของการ login ของผู้ใช้งาน freeradius จะเก็บไว้ที่ไดเรกทอรี
/var/log/radius/radacct/127.0.0.1/
ผลลัพธ์

[root@dhcp220 ~]# more /var/log/radius/radacct/127.0.0.1/detail-20071128
Wed Nov 28 10:11:04 2007
Acct-Status-Type = Start
User-Name = “fredf”
Calling-Station-Id = “00-13-02-69-41-FA”
Called-Station-Id = “00-01-03-18-BA-59”
NAS-Port-Type = Wireless-802.11
NAS-Port = 0
NAS-Port-Id = “00000000”
NAS-IP-Address = 0.0.0.0
NAS-Identifier = “nas01”
Framed-IP-Address = 10.0.1.2
Acct-Session-Id = “474cdc1f00000000”
Client-IP-Address = 127.0.0.1
Acct-Unique-Session-Id = “0db96d0b6e7fdf38”
Timestamp = 1196219464

Wed Nov 28 10:13:39 2007
Acct-Status-Type = Stop
User-Name = “fredf”
Calling-Station-Id = “00-13-02-69-41-FA”
Called-Station-Id = “00-01-03-18-BA-59”
NAS-Port-Type = Wireless-802.11
NAS-Port = 0
NAS-Port-Id = “00000000”
NAS-IP-Address = 0.0.0.0
NAS-Identifier = “nas01”
Framed-IP-Address = 10.0.1.2
Acct-Session-Id = “474cdc1f00000000”
Acct-Input-Octets = 3061
Acct-Output-Octets = 4948
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Packets = 19
Acct-Output-Packets = 23
Acct-Session-Time = 155
Acct-Terminate-Cause = User-Request
Client-IP-Address = 127.0.0.1
Acct-Unique-Session-Id = “0db96d0b6e7fdf38”
Timestamp = 1196219619 [root@dhcp220 ~]#

————————————-
คำแนะนำเพิ่มเติม
การเซ็ตค่า sqlcounter
ใน freeradius เวอร์ชั่น 1.1.7 จะมี modules sqlcounter ให้แล้ว เราเพียงแต่เพิ่ม
noresetcounter
dailycounter
monthlycounter
ใน section ชื่อ authorize แค่นั้นเอง จะทำให้สามารถใช้งาน session-timeout และ อื่น ๆ ได้
ความหมาย
noresetcounter
the counter that never resets, can be used for real session-time cumulation
dailycounter
the counter that resets everyday, can be used for limiting daily access time (eg. 3 hours a day)
monthlycounter
the counter that resets monthly, can be used for limiting monthly access time (eg. 50 hours per month)
ใน freeradius เวอร์ชั่นต่ำกว่า 1.1.7 อาจจำเป็นต้องสร้าง sqlcounter.sql ให้อ่านคำแนะนำเพิ่มเติมได้จากเว็บไซต์
http://wiki.freeradius.org/index.php?title=Rlm_sqlcounter&printable=yes
————————————-
15. แก้ไขแฟ้ม /etc/raddb/radiusd.conf เพื่อเพิ่ม sqlcounter name ทั้ง 3 ชื่อใน section authorize { … }
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/raddb/radiusd.conf

authorize {

…some entries here…
# Append at last line in this section by wiboon
noresetcounter
dailycounter
monthlycounter

}

16. เพิ่ม sqlcounter name ชื่อ noresetcounter พร้อมรายละเอียด เนื่องจากขาดหายไปจากในแฟ้ม /etc/raddb/radiusd.conf
ให้แทรกไว้ใกล้ ๆ กับ sqlcounter name ชื่อ dailycounter
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/raddb/radiusd.conf

sqlcounter noresetcounter {

counter-name = Max-All-Session-Time
check-name = Max-All-Session
sqlmod-inst = sql
key = User-Name
reset = never
query = “SELECT SUM(AcctSessionTime) FROM radacct WHERE UserName=’%{%k}'”

}

2.1 ทดสอบ authentication โดยใช้ username/password ของ Mysql
1. ทดสอบการเข้าใช้งานจากเครื่องโน้ตบุ๊คด้วย username fredf จะเห็นว่ามีตัวเลข session time ลดลงเรื่อย ๆ ผลลัพธ์ดังรูป

2. ทดสอบการเข้าใช้งานเมื่อ username fredf ใช้งานครบ 3 ชั่วโมงใน 1 วันแล้ว ผลลัพธ์ดังรูป

3. ทดสอบการเข้าใช้งานของ username fredf เป็นครั้งที่ 2 ในขณะที่กำลังใช้งานอยู่อีกเครื่อง ผลลัพธ์ดังรูป

————————————-
คำแนะนำเพิ่มเติม
กรณีที่ต้องการลบฐานข้อมูล ชื่อ radius และสร้างใหม่ทำได้ดังนี้
เข้า mysql ด้วยคำสั่งดังนี้
mysql -uroot -pabcd1234
ใช้คำสั่ง
DROP DATABASE radius;
CREATE DATABASE radius;
GRANT ALL PRIVILEGES ON radius.* to ‘radius’@’localhost’ IDENTIFIED BY ‘abcd1234′;
FLUSH PRIVILEGES;
เปิดฐานข้อมูล
use radius;
สร้าง schema โดยใช้คำสั่งนำเข้าคือ . (โปรดระวังเลขเวอร์ชั่นของ freeradius อาจเปลี่ยนไป)
. /usr/share/doc/freeradius-1.1.?/examples/mysql.sql
นำเข้าเรคคอร์ดจากแฟ้ม (คัดลอกข้อมูลตัวอย่างมาเก็บไว้ /root/chilli-sql-example.sql)
. /root/chilli-sql-example.sql
ออก
quit
————————————-
2.3 การติดตั้งโปรแกรม radiusContext เพื่อทำรายงานการใช้งาน Freeradius
————————————-
คัดลอกจาก การติดตั้ง radius server ด้วยโปรแกรม freeradius (18-01-2550)
http://rd.cc.psu.ac.th/content/view/35/46/
การแสดงผลรายงานจำเป็นต้องหาโปรแกรมมาต่างหาก
ขอแนะนำตัวอย่างโปรแกรมแสดงผลรายงาน
* ต้นแหล่งข้อมูลคือ 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/radius-report
จะแสดงผลบนโฮมพจ 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
————————————-
1. ติดตั้งโปรแกรมตามคำแนะนำข้างบนนี้
ผลลัพธ์

[root@dhcp220 ~]# wget ftp://ftp.psu.ac.th/pub/freeradius/radiusContext-1.93.tar.gz
[root@dhcp220 ~]# tar -C /root -zxvf radiusContext-1.93.tar.gz
[root@dhcp220 ~]# mkdir /var/www/html/radius-report
[root@dhcp220 ~]# /root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
[root@dhcp220 ~]# /root/radiusContext-1.93/stdreport -D /var/www/html/radius-report
[root@dhcp220 ~]#

2. เข้าโปรแกรม Mozilla แล้วไปที่ http://127.0.0.1/radius-report/ จะเห็นรายงานการใช้งาน
3. สั่งให้ linux ทำการจัดทำรายงานใหม่ทุกชั่วโมง โดยใช้ crontab
ใช้คำสั่ง more ตรวจสอบดูแฟ้ม /etc/crontab
ผลลัพธ์

[root@dhcp220 ~]# more /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
[root@dhcp220 ~]#

4. สร้างแฟ้มเก็บคำสั่งจัดทำรายงาน ตั้งชื่อว่า radius-report ด้วยคำสั่ง
gedit /etc/cron.hourly/radius-report
ใส่ข้อความ 2 บรรทัดนี้
/root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
/root/radiusContext-1.93/stdreport -D /var/www/html/radius-report
แล้วเปลี่ยนโหมดของแฟ้มเป็น execute ด้วยคำสั่ง
chmod +x /etc/cron.hourly/radius-report
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/cron.hourly/radius-report

/root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
/root/radiusContext-1.93/stdreport -D /var/www/html/radius-report

[root@dhcp220 ~]# chmod +x /etc/cron.hourly/radius-report
[root@dhcp220 ~]#

[Day 3]
ตอนที่ 3
3.1 การติดตั้งโปรแกรม squid
โปรแกรม squid คือโปรแกรมที่ทำงานเป็น proxy / webcache server เพื่อใช้อินเทอร์เน็ตผ่านพร็อกซี่
1. ติดตั้งโปรแกรม squid ด้วยคำสั่ง
yum install squid
ผลลัพธ์

[root@dhcp220 ~]# yum install squid
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
squid i386 7:2.6.STABLE13-1.fc6 updates 1.2 M
Installing for dependencies:
perl-URI noarch 1.35-3 base 116 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp220 ~]#

2. สั่งให้โปรแกรม squid ทำงานในการรีบูตเครื่องในครั้งต่อไป ด้วยคำสั่ง
chkconfig squid on
ผลลัพธ์

[root@dhcp220 ~]# chkconfig squid on
[root@dhcp220 ~]#

3. สร้างไดเรกทอรีเพื่อเก็บข้อมูลเว็บแคช ด้วยคำสั่ง
squid -z
ผลลัพธ์

[root@dhcp220 ~]# squid -z
2007/11/29 10:44:51| Creating Swap Directories
[root@dhcp220 ~]#

4. ปรับแต่งแฟ้มคอนฟิก /etc/squid/squid.conf ให้เหมาะสมดังนี้
ทำเป็น tranparent proxy
http_port 3128 transparent
ใช้ parent cache ในการออกอินเทอร์เน็ต (cache.your.domain คือชื่อ parent proxy ของหน่วยงานคุณ)
โดยที่ parent cache ตั้งใจเปิด port 8080 แทน 3128
cache_peer cache.your.domain parent 8080 0 no-query
(ถ้าไม่มี parent cache หรือ ไม่รู้ว่า parent cache คืออะไร cache_peer ไม่ต้องเซ็ตครับ)
ไม่เก็บ log ชนิด dump memory
cache_store_log none
กำหนดไอพีแอดเดรสเครือข่ายที่อนุญาตให้ใช้งาน proxy server นี้ได้
ตัวอย่างอนุญาตเฉพาะ net ของไวร์เลส
สามารถเพิ่มรายการ our_networks บรรทัดที่ 2,3,… ได้เองจากที่ผมทำไว้ให้
acl our_networks src 10.0.1.0/24 192.168.2.0/24
http_access allow our_networks
กำหนดให้มีแฟ้มเก็บ access.log 2 แฟ้มหมุนเวียนแบบเขียนทับ คือ access.log และ access.log.0
logfile_rotate 1
กำหนดให้ใช้งานผ่าน parent cache เท่านั้น จะไม่มีการ direct port 80 ไปอินเทอร์เน็ตเอง
never_direct allow all
(ถ้าไม่มี parent cache หรือ ไม่รู้ว่า parent cache คืออะไร never_direct ไม่ต้องเซ็ตครับ)
กำหนดให้ไปยังเว็บอินทราเน็ตโดยไม่ต้องใช้ proxy ของเรา เพื่อลดเวลาตอบสนอง
สามารถเพิ่มรายการ intranet_server ได้เองจากที่ผมทำไว้ให้
acl intranet_server dst 192.168.0.0/255.255.0.0
acl intranet_server dst 172.16.0.0/255.240.0.0
acl intranet_server dst 10.0.0.0/255.0.0.0
always_direct allow intranet_server
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/squid/squid.conf

Line 89
http_port 3128 transparent

Line 583
cache_peer cache.your.domain parent 8080 0 no-query

Line 1123
cache_store_log none

Line 2548
acl our_networks src 10.0.1.0/24 192.168.2.0/24
http_access allow our_networks

Line 2987
logfile_rotate 1

Line 3400
never_direct allow all

Line 3366
acl intranet_server dst 192.168.0.0/255.255.0.0
acl intranet_server dst 172.16.0.0/255.240.0.0
acl intranet_server dst 10.0.0.0/255.0.0.0
always_direct allow intranet_server

5. สั่งให้โปรแกรม squid ทำงาน ด้วยคำสั่ง
service squid start
ผลลัพธ์

[root@dhcp220 ~]# service squid start
Starting squid: . [ OK ]
[root@dhcp220 ~]#

3.2 การทำ Transparent proxy ด้วย iptables
1. แก้ไขแฟ้ม /etc/firewall.iptables โดยเพิ่มบรรทัด
##Allow transparent proxy (wiboon 1/2)
$IPTABLES -A INPUT -p tcp -m tcp –dport 3128 –syn -j ACCEPT
และ
##Allow transparent proxy (wiboon 2/2)
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 3128 –syn -j DROP
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 192.168.0.0/16 –dport 80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 172.16.0.0/12 –dport 80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/8 –dport 80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 80 -j REDIRECT –to-ports 3128
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/firewall.iptables

IPTABLES=”/sbin/iptables”
EXTIF=”eth0″
INTIF=”eth1″

#Flush all rules
$IPTABLES -F
$IPTABLES -F -t nat
$IPTABLES -F -t mangle

#Set default behaviour
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT

#Allow related and established on all interfaces (input)
$IPTABLES -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT

#Allow releated, established and ssh on $EXTIF. Reject everything else.
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp –dport 22 –syn -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -j REJECT

#Allow related and established from $INTIF. Drop everything else.
$IPTABLES -A INPUT -i $INTIF -j DROP

#Allow http and https on other interfaces (input).
#This is only needed if authentication server is on same server as chilli
$IPTABLES -A INPUT -p tcp -m tcp –dport 80 –syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp –dport 443 –syn -j ACCEPT

#Allow 3990 on other interfaces (input).
$IPTABLES -A INPUT -p tcp -m tcp –dport 3990 –syn -j ACCEPT
##Allow transparent proxy (wiboon 1/2)
$IPTABLES -A INPUT -p tcp -m tcp –dport 3128 –syn -j ACCEPT

#Allow ICMP echo on other interfaces (input).
$IPTABLES -A INPUT -p icmp –icmp-type echo-request -j ACCEPT

#Allow everything on loopback interface.
$IPTABLES -A INPUT -i lo -j ACCEPT

##Allow transparent proxy (wiboon 2/2)
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 3128 –syn -j DROP
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 192.168.0.0/16 –dport 80
-j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 172.16.0.0/12 –dport 80
-j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/8 –dport 80
-j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 80
-j REDIRECT –to-ports 3128

# Drop everything to and from $INTIF (forward)
# This means that access points can only be managed from ChilliSpot
$IPTABLES -A FORWARD -i $INTIF -j DROP
$IPTABLES -A FORWARD -o $INTIF -j DROP

#Enable NAT on output device
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

————————————-
หากต้องการเปิด port ด้าน eth0 ให้อนุญาต port 443 และ 10000 ให้เพิ่ม 2 บรรทัดข้างล่างนี้ต่อท้ายบรรทัดที่อนุญาต port 22
#Allow https to web account management (wiboon).
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp –dport 443 –syn -j ACCEPT
#Allow any port i.e. 10000 to this server (wiboon).
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp –dport 10000 –syn -j ACCEPT
————————————-
2. สั่งให้ iptables ทำงานเป็น firewall ตามแฟ้ม /etc/firewall.iptables ด้วยคำสั่ง
sh /etc/firewall.iptables
ผลลัพธ์

[root@dhcp220 ~]# sh /etc/firewall.iptables
[root@dhcp220 ~]#

3. ทดสอบการใช้งานที่เครื่องไคลเอนต์ ลองไปยังเว็บไซต์ google
แล้วเช็คดูในแฟ้ม /var/log/squid/access.log
ผลลัพธ์

[root@dhcp220 ~]# tail -f /var/log/squid/access.log
1196309038.756 2449 10.0.1.4 TCP_MISS/200 2551 GET http://www.google.co.th/ – TIMEOUT_FIRST_UP_PARENT/cache.psu.ac.th text/html
1196309220.447 181690 10.0.1.4 TCP_MISS/504 1480 GET http://www.google.co.th/gen_204? – DIRECT/72.14.235.104 text/html
ctrl-c break

3.3 การตั้งเวลาเก็บ access.log ทุกคืน
1. สร้างแฟ้ม shell script ใหม่ชื่อ rotate_and_keep_proxy_log
เพื่อเก็บบรรทัดคำสั่งที่ใช้ในการ rotate log และเก็บ log ในรูปแบบย่อ เพื่อให้อ่านง่ายและประหยัดเนื้อที่
โดยใช้คำสั่ง
gedit /etc/cron.daily/rotate_and_keep_proxy_log
แล้วเปลี่ยนโหมดของแฟ้มเป็น execute
chmod +x /etc/cron.daily/rotate_and_keep_proxy_log
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/cron.daily/rotate_and_keep_proxy_log

#!/bin/bash
day=date '+%Y%m%d'
if [ -f /root/logs/access.log.cache.${day} ]; then
exit 0
fi
squid -k rotate
cat /var/log/squid/access.log.0 | awk ‘{print $1 ” ” $3 ” ” $6 ” ” $7}’ |
perl -pe ‘s/^d+.d+/localtime($&)/e;’ > /root/logs/access.log.cache.${day}

[root@dhcp220 ~]# chmod +x /etc/cron.daily/rotate_and_keep_proxy_log
[root@dhcp220 ~]#

2. หากเนื้อที่ดิสก์ไม่เพียงพอ จำเป็นจะต้องย้ายไปเก็บยังเซิร์ฟเวอร์ตัวอื่น ให้ใช้คำสั่ง scp คัดลอกแฟ้มไป
ต้องแก้ไข shell script อีกเล็กน้อย
ที่มา: http://www.mycools.in.th/archives/46/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%97%E0%B8%B3-wireless-lan-controller-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-chillispot-%E0%B9%81%E0%B8%9A%E0%B8%9A-web-login-freeradius-mysql-transparent-proxy/

การทำ Wireless LAN Controller ด้วย Chillispot แบบ web login + freeradius + mysql + transparent proxy

ก่อนอื่นให้เครดิตผู้เขียนนิดนึงครับ
คุณวิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ มหาวิทยาลัยสงขลานครินทร์ ( wiboon.w (at) psu.ac.th )
ต้นฉบับ http://mamboeasy.psu.ac.th/~wiboon.w/content/view/58/40/
เอกสารอ้างอิง
แหล่งข้อมูลต้นฉบับ chillispot คือ http://www.chillispot.info
ขอขอบคุณ คุณวิภัทร ศรุติพรหม ให้ความรู้ linux server ที่เวบไซต์ http://www.opensource.psu.ac.th เมนู ทำง่าย-ใช้เป็น
ขอขอบคุณ คุณ au ร.ร.จุฬาภรณราชวิทยาลัย ปทุมธานี ให้ตัวอย่าง radius attribute

เอกสารนี้ใช้เพื่อ
เป็นคำแนะนำในการติดตั้งและปรับแต่ง Linux server ให้เป็น Wireless LAN Access Point Controller ด้วยโปรแกรม chillispot
เลือกวิธีการ authentication แบบ web login โดยตรวจสอบ username ที่ freeradius ที่ใช้ mysql เป็น database
รวมทั้งติดตั้ง proxy server ด้วยโปรแกรม squid แบบ transparent proxy เพื่อให้เครื่องไคลเอนต์ (โน้ตบุ๊ค) ที่ไม่เซ็ตค่าพร็อกซี่ก็สามารถใช้งานอินเทอร์เน็ตได้ทันทีภายหลังจากที่ ตรวจสอบ username ผ่านแล้ว
เอกสารนี้แบ่งออกเป็น 3 ตอน
ตอนที่ 1

  • การติดตั้ง Linux server
  • การติดตั้งโปรแกรม Apache web server
  • การติดตั้งโปรแกรม Freeradius
  • ทดสอบ authentication โดยใช้ username/password ของ Unix
  • การติดตั้งโปรแกรม Chillispot แบบ Web login

ตอนที่ 2

  • การติดตั้งโปรแกรม Mysql
  • ตัวอย่าง radius attribute
    • Max-All-Session
    • Max-Daily-Session
    • Max-Monthly-Session
    • Session-Timeout
    • WISPr-Bandwidth-Max-Down
    • WISPr-Bandwidth-Max-Up
    • Simultaneous-Use
  • ทดสอบ authentication โดยใช้ username/password ของ Mysql
  • การติดตั้งโปรแกรม radiusContext เพื่อทำรายงานการใช้งาน Freeradius

ตอนที่ 3

  • การติดตั้งโปรแกรม squid
  • การทำ Transparent proxy ด้วย iptables
  • การตั้งเวลาเก็บ access.log ทุกคืน

ตอนที่ 4

  • รออาสาสมัครที่สามารถใช้ php + mysql เขียนโปรแกรมจัดการบัญชีผู้ใช้ chillispot ด้วย php + mysql

รูปภาพการติดตั้ง

ข้อมูลเครือข่าย

  • eth0 คือ แลนการ์ดใบที่ 1 ต่อกับอินเทอร์เน็ต ได้รับแจก ip จาก dhcp server ในอินเทอร์เน็ต
  • eth1 คือ แลนการ์ดใบที่ 2 ต่อกับแอคเซสพอยต์ ได้รับแจก ip จาก chillispot server
  • แอคเซสพอยต์ได้รับแจก ip จาก chillispot server
  • ไคลเอนต์ที่มาต่อกับแอคเซสพอยต์ได้รับแจก ip จาก chillispot server ส่งต่อโดยแอคเซสพอยต์
  • chillispot server 1 เครื่อง ติดตั้งโปรแกรมดังนี้
    • Linux fedora core 6
    • freeradius 1.1.* (rpm) (ทดสอบแล้ว 1.1.3 – 1.1.7)
    • apache 2.2.* (rpm) (ทดสอบแล้ว 2.2.3 – 2.2.6)
    • chillispot 1.1.0 (rpm)

[Day 1]
ตอนที่ 1
1.1 การติดตั้ง Linux server
คำแนะนำการติดตั้ง

  • ในขั้นตอนที่ติดตั้งจากแผ่นซีดี ให้เลือก Package selection เป็น Software Development
  • ในขั้นตอนที่ติดตั้งจากแผ่นซีดีครบแล้ว เมื่อรีบูตกลับมาให้ปิด SeLinux โดยเปลี่ยนจาก enforcing เป็น disabled

คำแนะนำการใช้งาน

  • การคอนฟิกระบบจะง่ายขึ้น ให้ใช้วิธีการ copy และ paste คำสั่งหรือข้อความจากเอกสารที่กำลังอ่านอยู่นี้
    หากภายหลังการติดตั้งได้รับหน้าจอเป็น text mode ให้เปลี่ยนเป็นกราฟฟิคโหมด ด้วยคำสั่ง startx
  • เปิดวินโดวชื่อ terminal เพื่อใช้ในการปรับแต่งและรันคำสั่ง ดังนี้ คลิก Application, Accessories, Terminal
  • โปรแกรม editor ที่ใช้ในการแก้ไขค่าคือ gedit เป็น full screen editor ใช้เมาส์คลิกวางตำแหน่ง cursor ได้
    จบด้วยคลิกปุ่ม Save และคลิก X เพื่อปิดโปรแกรม

1.1.1 การปรับแต่งระบบลินุกซ์
(ดัดแปลงจาก การปรับแต่งระบบลินุกซ์หลังการติดตั้ง (28-9-2550) วิภัทร ศรุติพรหม http://rd.cc.psu.ac.th/content/view/14/46/ )
1. ตรวจสอบการ์ดแลนพร้อมใช้งานด้วยคำสั่ง
ifconfig -a
ผลลัพธ์

[root@dhcp160 ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:60:97:A5:38:6F
inet addr:192.168.2.220 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: 2001:3c8:9009:300:260:97ff:fea5:386f/64 Scope:Global
inet6 addr: fe80::260:97ff:fea5:386f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:126 errors:0 dropped:0 overruns:0 frame:0
TX packets:46 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:9430 (9.2 KiB) TX bytes:8450 (8.2 KiB)
Interrupt:9 Base address:0x2080

eth1 Link encap:Ethernet HWaddr 00:01:03:18:BA:59
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:431699 errors:0 dropped:0 overruns:520 frame:0
TX packets:858 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:32878596 (31.3 MiB) TX bytes:88551 (86.4 KiB)
Interrupt:5

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:34660 errors:0 dropped:0 overruns:0 frame:0
TX packets:34660 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:9917351 (9.4 MiB) TX bytes:9917351 (9.4 MiB)

2. หากต้องการเปลี่ยนรหัสผ่านของ root ทำด้วยคำสั่ง
passwd
ผลลัพธ์

[root@dhcp160 ~]# passwd
Changing password for user root.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

3. ยกเลิกการตั้งค่า update อัตโนมัติ ด้วยคำสั่งดังนี้คือ
service yum-updatesd stop
chkconfig yum-updatesd off
ผลลัพธ์

[root@dhcp160 ~]# service yum-updatesd stop
Stopping yum-updatesd: [ OK ]
[root@dhcp160 ~]# chkconfig yum-updatesd off [root@dhcp160 ~]#

4. ตั้งเวลาให้ตรงกับสากลด้วยคำสั่ง /usr/sbin/ntpdate -u <ชื่อเซิร์ฟเวอร์>
โดยที่
pool.ntp.org เป็น ntp server ที่เป็นสากลโดยตร
ใช้คำสั่ง
/usr/sbin/ntpdate -u pool.ntp.org
ผลลัพธ์

[root@dhcp160 ~]# /usr/sbin/ntpdate -u pool.ntp.org
27 Nov 17:20:45 ntpdate[22639]: step time server 61.19.242.42 offset -130.874347 sec

ต้องการให้ทุกครั้งที่บูทเครื่องมีการตั้งเวลาใหม่ ให้แก้ไขแฟ้ม /etc/rc.local ใช้คำสั่ง
gedit /etc/rc.local
เพิ่มบรรทัดข้อความว่า
/usr/sbin/ntpdate -u pool.ntp.org
บันทึกและปิดหน้าต่าง gedit
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don’t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/sbin/ntpdate -u pool.ntp.org

ตั้งเวลาให้ตรงกับสากลทุกวัน ให้สร้างแฟ้มข้อมูลชื่อ /etc/cron.daily/ntp.cron ใช้คำสั่ง
gedit /etc/cron.daily/ntp.cron
มีข้อมูลดังนี้
#!/bin/sh
/usr/sbin/ntpdate -u pool.ntp.org
และเปลี่ยนโหมดของแฟ้มเป็น execute ด้วยคำสั่ง
chmod +x /etc/cron.daily/ntp.cron
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/cron.daily/ntp.cron

#!/bin/sh /usr/sbin/ntpdate -u pool.ntp.org

[root@dhcp160 ~]# chmod +x /etc/cron.daily/ntp.cron [root@dhcp160 ~]#

5. เกี่ยวกับ SeLinux อาจทำให้การใช้งานบางอย่างยากขึ้น ให้เปลี่ยนจาก enforcing เป็น disabled โดยแก้ไขแฟ้ม /etc/selinux/config ใช้คำสั่ง
gedit /etc/selinux/config
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing – SELinux security policy is enforced. (default)
# permissive – SELinux prints warnings instead of enforcing.
# disabled – SELinux is fully disabled.
SELINUX=disabled # SELINUXTYPE= type of policy in use. Possible values are:
# targeted – Only targeted network daemons are protected.
# strict – Full SELinux protection.
SELINUXTYPE=targeted

1.1.2 การ update packages linux fedora core 6 ให้ทันสมัย
สั่งปรับปรุงรายชื่อ package ให้ทันสมัยตามแหล่งข้อมูลต้นทาง
yum check-update
สั่งปรับปรุง/ติดตั้ง package ให้ทันสมัย
yum update
ผลลัพธ์

[root@dhcp160 ~]# yum check-update
Loading “installonlyn” plugin
Setting up repositories
extras 100% |=========================| 1.1 kB 00:00
updates 100% |=========================| 1.2 kB 00:00
base 100% |=========================| 951 B 00:00
Reading repository metadata in from local files
primary.xml.gz 100% |=========================| 1.7 MB 00:00

[root@dhcp160 ~]# yum update
Loading “installonlyn” plugin
Setting up Update Process
Setting up repositories
Reading repository metadata in from local files

Transaction Summary
=============================================================================
Install 11 Package(s)
Update 329 Package(s)
Remove 0 Package(s)

Total download size: 524 M
Is this ok [y/N]:y
… more lines…
[root@dhcp160 ~]#

1.2 การติดตั้งโปรแกรม Apache web server
ชื่อแฟ้มที่เกี่ยวข้องเมื่อติดตั้งเสร็จแล้ว
/var/log/httpd/access.log
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/
1. ติดตั้งโปรแกรม httpd พร้อมคู่มือ ด้วยคำสั่ง
yum install httpd
yum install httpd-manual
yum install mod_ssl
ผลลัพธ์

[root@dhcp160 ~]# yum install httpd
=============================================================================
Package Arch Version Repository Size
=============================================================================
Updating:
httpd i386 2.2.6-1.fc6 updates 1.0 M

Transaction Summary
=============================================================================

Complete!
[root@dhcp160 ~]# yum install httpd-manual
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
httpd-manual i386 2.2.6-1.fc6 updates 812 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp160 ~]# yum install mod_ssl
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mod_ssl i386 1:2.2.6-1.fc6 updates 84 k
Installing for dependencies:
distcache i386 1.4.5-14.1 base 120 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp160 ~]#

2. แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
chkconfig httpd on
ผลลัพธ์

[root@dhcp160 ~]# chkconfig httpd on
[root@dhcp160 ~]#

3. สั่งให้ทำงานด้วยคำสั่งว่า
service httpd start
ผลลัพธ์

[root@dhcp160 ~]# service httpd start
Starting httpd: [ OK ]
[root@dhcp160 ~]#

1.3 การติดตั้งโปรแกรม Freeradius
ชื่อแฟ้มที่เกี่ยวข้องเมื่อติดตั้งเสร็จแล้ว
/var/log/radius/radius.log
/etc/raddb/radiusd.conf
/etc/raddb/clients.conf
1. ติดตั้งโปรแกรม freeradius ด้วยคำสั่ง
yum install freeradius
แก้ไขให้ทำงานทุกครั้งที่บูทเครื่อง
chkconfig radiusd on
สั่งให้ทำงานด้วยคำสั่งว่า
service radiusd start
ผลล้ัพธ์

[root@dhcp160 ~]# yum install freeradius
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
freeradius i386 1.1.7-3.1.fc6 updates 1.2 M
Installing for dependencies:
lm_sensors i386 2.10.1-1.fc6 updates 506 k
net-snmp i386 1:5.3.1-15.fc6 updates 695 k
net-snmp-utils i386 1:5.3.1-15.fc6 updates 179 k
perl-DBI i386 1.52-1.fc6 base 605 k

Transaction Summary
=============================================================================
Install 5 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 3.1 M
Is this ok [y/N]: y
Downloading Packages:

Complete!
[root@dhcp160 ~]# chkconfig radiusd on
[root@dhcp160 ~]# service radiusd start
radiusd is stopped
Starting RADIUS server: [ OK ]
[root@dhcp160 ~]#

1.4 ทดสอบ authentication โดยใช้ username/password ของ Unix
1. (หากยังไม่มี) ให้เตรียม username ที่จะใช้ทดสอบชื่อ chilli มีรหัสผ่านเป็น abcd1234 ด้วยคำสั่งดังนี้
adduser chilli
passwd chilli
ผลลัพธ์

[root@dhcp160 ~]# adduser chilli
[root@dhcp160 ~]# passwd chilli
Changing password for user chilli.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully. [root@dhcp160 ~]#

2. เมื่อให้ radiusd ทำงานแล้ว เริ่มขั้นตอนทดสอบระบบโดยป้อนตัวอย่างคำสั่งดังนี้
radtest chilli abcd1234 localhost 0 testing123
จะมีการแจ้งว่า Access-Reject
เป็นสาเหตุเนื่องจากไม่มีสิทธิในการอ่านแฟ้ม /etc/shadow ของระบบ
ผลลัพธ์

[root@dhcp160 ~]# radtest chilli abcd1234 localhost 0 testing123
Sending Access-Request of id 232 to 127.0.0.1 port 1812
User-Name = “chilli”
User-Password = “abcd1234”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
Re-sending Access-Request of id 232 to 127.0.0.1 port 1812
User-Name = “chilli”
User-Password = “abcd1234”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Reject packet from host 127.0.0.1:1812, id=232, length=20 [root@dhcp160 ~]#

หมายเหตุ คำว่า localhost คือ ชื่อโดเมนของไอพีแอดเดรส 127.0.0.1 ก็คือ ตัวเครื่องเซิร์ฟเวอร์เอง
ซึ่งต้องมีระบุไว้ในแฟ้ม /etc/hosts ใช้คำสั่งดูข้อมูลข้างในแฟ้มดังนี้
cat /etc/hosts

[root@dhcp160 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost.localdomain localhost [root@dhcp160 ~]#

3. แก้ไขให้อ่านแฟ้ม /etc/shadow ได้ โดยแก้ไขแฟ้ม /etc/raddb/radiusd.conf
3.1 ให้ทำการสำรองแฟ้มต้นฉบับเก็บไว้ก่อน ด้วยคำสั่ง
cp /etc/raddb/radiusd.conf /etc/raddb/radiusd.conf.save
ผลลัพธ์

[root@dhcp160 ~]# cp /etc/raddb/radiusd.conf /etc/raddb/radiusd.conf.save [root@dhcp160 ~]#

3.2 แก้ไขแฟ้ม /etc/raddb/radiusd.conf เพื่อทำการ comment ยกเลิกบรรทัดข้อความจากเดิม
user = radiusd
group = radiusd
ให้เป็น
#user = radiusd
#group = radiusd
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/raddb/radiusd.conf

Line 114
#user = radiusd #group = radiusd

3.3 เสร็จแล้วให้ restart ระบบ radiusd ใหม่ด้วยคำสั่ง
service radiusd restart
ผลลัพธ์

[root@dhcp160 ~]# service radiusd restart
radiusd (pid 23004) is running…
radiusd (pid 23004) is running…
Stopping RADIUS server: [ OK ]
radiusd is stopped
Starting RADIUS server: [ OK ] [root@dhcp160 ~]#

3.4 ต่อไปลองป้อนตัวอย่างคำสั่งเดิมเพื่อทดสอบดังนี้
radtest chilli abcd1234 localhost 0 testing123
จะมีการแจ้งว่า Access-Accept ถูกต้องตามต้องการ
ผลลัพธ์

[root@dhcp160 ~]# radtest chilli abcd1234 localhost 0 testing123
Sending Access-Request of id 39 to 127.0.0.1 port 1812
User-Name = “chilli”
User-Password = “abcd1234”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=39, length=20
[root@dhcp160 ~]#

3.5 ในการนำไปใช้งานจริง ขอให้แก้ไข secret ใหม่ ตัวอย่างเช่น ตั้งใหม่เป็น mytestkey
ให้แก้ไขแฟ้ม /etc/raddb/clients.conf ของโปรแกรม freeradius ให้มีค่าดังตัวอย่างนี้
client 127.0.0.1 {

บรรทัดที่ 35 เดิม secret = testing123
แก้ไขเป็น secret = mytestkey

}
เสร็จแล้วให้ restart ระบบ radiusd ใหม่ด้วยคำสั่ง
service radiusd restart
ทดสอบ radius อีกครั้งด้วย secret อันใหม่ ดังนี้
radtest chilli abcd1234 localhost 0 mytestkey
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/raddb/clients.conf

Line 35
secret = mytestkey

[root@dhcp160 ~]# service radiusd restart radiusd (pid 23068) is running…
radiusd (pid 23068) is running…
Stopping RADIUS server: [ OK ]
radiusd is stopped
Starting RADIUS server: [ OK ]

[root@dhcp160 ~]# radtest chilli abcd1234 localhost 0 mytestkey
Sending Access-Request of id 166 to 127.0.0.1 port 1812
User-Name = “chilli”
User-Password = “abcd1234”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=166, length=20
[root@dhcp160 ~]#

1.5 การติดตั้งโปรแกรม Chillispot แบบ Web login
ชื่อแฟ้มที่เกี่ยวข้องเมื่อติดตั้งเสร็จแล้ว
/etc/chilli.conf
/var/www/cgi-bin/hotspotlogin.cgi
/var/www/html/welcome.html
/etc/firewall.iptables
————————————-
โปรดตรวจสอบ
เนื่องจาก chillispot จะเป็น dhcp server เอง
กรณีที่นำเครื่องเดิมมาติดตั้ง chillispot เพิ่ม จะต้องเช็คว่าในเครื่องไม่มี dhcp server รันอยู่ ถ้ามีอยู่ก็หยุดดังนี้
service dhcpd stop
chkconfig dhcpd off
————————————-
1. เราต้องทำให้เครื่องนี้ทำหน้าที่เป็นเราเตอร์เพื่อ forward packet ทุกครั้งที่รีบูตเครื่อง
ให้แก้ไขแฟ้ม /etc/sysctl.conf ให้มีค่าดังตัวอย่างนี้
บรรทัดที่ 7 เดิม net.ipv4.ip_forward = 0
แก้ไขเป็น net.ipv4.ip_forward = 1
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/sysctl.conf

# Controls IP packet forwarding
net.ipv4.ip_forward = 1

2. เพื่อให้มีผลทันทีในขณะนี้ ให้เครื่อง forward packet
รันคำสั่ง echo “1″ > /proc/sys/net/ipv4/ip_forward

ผลลัพธ์

[root@dhcp160 ~]# echo “1” > /proc/sys/net/ipv4/ip_forward
[root@dhcp160 ~]#

3. เพื่อให้การ์ดแลน eth1 ไม่รับ dhcp ตอนรีบูตเครื่อง
ให้แก้ไขแฟ้ม /etc/sysconfig/network-scripts/ifcfg-eth1 ให้มีค่าดังตัวอย่างนี้
DEVICE=eth1
ONBOOT=yes
BOOTPROTO=none
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/sysconfig/network-scripts/ifcfg-eth1

# 3Com Corporation 3c905C-TX/TX-M [Tornado]
DEVICE=eth1 BOOTPROTO=none HWADDR=00:01:03:18:BA:59 ONBOOT=yes

4. ดาวน์โหลดโปรแกรม chillispot จากเครื่องเอฟทีพีของม.อ. ด้วยคำสั่ง wget ดังนี้
wget ftp://ftp.psu.ac.th/pub/chillispot/chillispot-1.1.0.i386.rpm
ผลลัพธ์

[root@dhcp160 ~]# wget ftp://ftp.psu.ac.th/pub/chillispot/chillispot-1.1.0.i386.rpm
–20:25:02– ftp://ftp.psu.ac.th/pub/chillispot/chillispot-1.1.0.i386.rpm
=> chillispot-1.1.0.i386.rpm'
Resolving ftp.psu.ac.th... 192.168.100.101
Connecting to ftp.psu.ac.th|192.168.100.101|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD /pub/chillispot ... done.
==> SIZE chillispot-1.1.0.i386.rpm ... 88761
==> PASV ... done. ==> RETR chillispot-1.1.0.i386.rpm ... done.
Length: 88761 (87K)

100%[=======================================>] 88,761 --.-K/s in 0.04s

20:25:03 (2.00 MB/s) - chillispot-1.1.0.i386.rpm’ saved [88761]
[root@dhcp160 ~]#

หรือดาวน์โหลดจากเว็บต้นฉบับที่ http://www.chillispot.info/download.html

http://www.chillispot.info/download.html
Suitable for Redhat 9, Fedora (FC1, FC2 and FC3 and FC4).

http://www.chillispot.info/download/chillispot-1.1.0.i386.rpm

Or other linux distro.

http://www.chillispot.info/download/chillispot-1.1.0.tar.gz

5. แล้วติดตั้ง package rpm ด้วยคำสั่งดังนี้
rpm -Uvh chillispot-1.1.0.i386.rpm
ผลลัพธ์

[root@dhcp160 ~]# rpm -Uvh chillispot-1.1.0.i386.rpm
Preparing… ########################################### [100%]
1:chillispot ########################################### [100%] [root@dhcp160 ~]#

6. แก้ไขแฟ้ม /etc/chilli.conf ให้มีค่าดังตัวอย่างนี้
[หัวข้อ TUN parameters]
บรรทัดที่ 38 เดิม net 192.168.182.0/24
แก้ไขเป็น net 10.0.1.0/24
[หัวข้อ Radius parameters]
บรรทัดที่ 113 เดิม radiusserver1 rad01.chillispot.org
แก้ไขเป็น radiusserver1 127.0.0.1
บรรทัดที่ 120 เดิม radiusserver2 rad02.chillispot.org
แก้ไขเป็น radiusserver2 127.0.0.1
บรรทัดที่ 139 เดิม #radiussecret testing123
แก้ไขเป็น radiussecret mytestkey
(ตรงกับ radius secret ในแฟ้ม /etc/raddb/clients.conf ของ freeradius)
[หัวข้อ Universal access method (UAM) parameters]
บรรทัดที่ 237 เดิม #uamserver https://radius.chillispot.org/hotspotlogin
แก้ไขเป็น uamserver https://10.0.1.1/cgi-bin/hotspotlogin.cgi
บรรทัดที่ 244 เดิม #uamhomepage http://192.168.182.1/welcome.html
แก้ไขเป็น uamhomepage http://10.0.1.1/welcome.html
บรรทัดที่ 248 เดิม #uamsecret ht2eb8ej6s4et3rg1ulp
แก้ไขโดยให้เอาเครื่องหมาย# ออก เป็น uamsecret ht2eb8ej6s4et3rg1ulp
(หรือแก้ไขเป็นรหัสใหม่ แต่ต้องเหมือนกับในแฟ้ม hotspotlogin.cgi ในข้อถัดไป)
บรรทัดที่ 253 เดิม #uamlisten 192.168.182.1
แก้ไขเป็น uamlisten 10.0.1.1
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/chilli.conf

Line 38
net 10.0.1.0/24 radiusserver1 127.0.0.1 radiusserver2 127.0.0.1 radiussecret mytestkey uamserver https://10.0.1.1/cgi-bin/hotspotlogin.cgi uamhomepagehttp://10.0.1.1/welcome.html uamsecret ht2eb8ej6s4et3rg1ulp uamlisten 10.0.1.1

7. ให้คัดลอกแฟ้ม firewall.iptables ด้วยคำสั่ง
cp /usr/share/doc/chillispot-1.1.0/firewall.iptables /etc
ให้คัดลอกแฟ้ม hotspotlogin.cgi ด้วยคำสั่ง
cp /usr/share/doc/chillispot-1.1.0/hotspotlogin.cgi /var/www/cgi-bin/
ผลลัพธ์

[root@dhcp160 ~]# cp /usr/share/doc/chillispot-1.1.0/firewall.iptables /etc
[root@dhcp160 ~]# cp /usr/share/doc/chillispot-1.1.0/hotspotlogin.cgi /var/www/cgi-bin/ [root@dhcp160 ~]#

8. แก้ไขแฟ้ม /var/www/cgi-bin/hotspotlogin.cgi ให้มีค่าดังตัวอย่างนี้
บรรทัดที่ 27 เดิม #$uamsecret = “ht2eb8ej6s4et3rg1ulp”;
แก้ไขโดยให้เอาเครื่องหมาย# ออก เป็น $uamsecret = “ht2eb8ej6s4et3rg1ulp”;
บรรทัดที่ 31 เดิม #$userpassword=1;
แก้ไขโดยให้เอาเครื่องหมาย# ออก เป็น $userpassword=1;
ผลลัพธ์

[root@dhcp160 ~]# gedit /var/www/cgi-bin/hotspotlogin.cgi

Line 27
$uamsecret = “ht2eb8ej6s4et3rg1ulp”;

# Uncomment the following line if you want to use ordinary user-password
# for radius authentication. Must be used together with $uamsecret.
$userpassword=1;

9. สร้างแฟ้ม /var/www/html/welcome.html ให้มีค่าดังตัวอย่างนี้

ผลลัพธ์

[root@dhcp160 ~]# gedit /var/www/html/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” mce_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://10.0.1.1:3990/prelogin” mce_href=”http://10.0.1.1:3990/prelogin”>Click here to login</a></H3>
<p>
<p>Enjoy.
</center>
</body>
</html>

10. ถ้าต้องการรูป chillispot.png ให้ดาวน์โหลดได้ที่นี่
wget http://mamboeasy.psu.ac.th/~wiboon.w/images/stories/chillispot/chillispo…
แล้วคัดลอกแฟ้มนี้ไปไว้ใน /var/www/html ด้วยคำสั่งดังนี้
cp chillispot.png /var/www/html
ผลลัพธ์

[root@dhcp160 ~]# wget http://mamboeasy.psu.ac.th/~wiboon.w/images/stories/ chillispot/chillispot.png
[root@dhcp160 ~]# cp chillispot.png /var/www/html [root@dhcp160 ~]#

11. ก่อนที่จะสตาร์ท chillispot ให้ไปทำการคอนฟิกแอคเซสพอยน์/ไวร์เลสเราเตอร์ ให้พร้อมใช้งาน โดยทำตามเอกสารของแต่ละรุ่น
ความต้องการคือ ให้ทำ factory defaults แล้วกำหนดให้มันจะต้องรับ dhcp ip จาก chillispot และตัวมันเองจะต้องไม่ทำหน้าที่แจก ip
รวมทั้งควรแก้ไข ESSID ตั้งชื่อใหม่ด้วย เพื่อให้รู้ว่าตัวไหนของเรา ดูตัวอย่างบางรุ่นในเว็บนี้ได้
หมายเหตุ Linksys WRT54GL ที่ผมนำมา upgrade firmware เป็น DD-WRT แล้ว
ผมพบว่า ต้อง Enable DHCP server ให้กับ port LAN 1-4 ของเราเตอร์ด้วย
มันยังคงแจกไอพีให้กับ เครื่องที่ต่อ port LAN 1-4 แต่มันไม่แจกไอพีให้ไวร์เลส
12. เปิดใช้งาน iptables เพื่อทำเป็น firewall ด้วยคำสั่ง
sh /etc/firewall.iptables
ผลลัพธ์

[root@dhcp160 ~]# sh /etc/firewall.iptables
[root@dhcp160 ~]#

13. สั่งให้ chillispot ทำงานด้วยคำสั่ง
service chilli start
ผลลัพธ์

[root@dhcp160 ~]# service chilli start
Starting chilli: [ OK ]

14. ตรวจสอบการทำงานของ chiilispot ว่าสร้างอินเทอร์เฟส tun0 พร้อมใช้งานและมีเลข IP เป็น 10.0.1.1
โดยที่อินเทอร์เฟส eth1 จะไม่มี IP ใด ๆ ส่วน eth0 ก็เป็นเลข IP ที่รับจากเน็ตที่เซิร์ฟเวอร์นี้ต่ออยู่เหมือนเดิม
ด้วยคำสั่ง ifconfig ดังตัวอย่าง
ผลลัพธ์

[root@dhcp160 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:60:97:A5:38:6F
inet addr:192.168.2.220 Bcast:192.168.2.255 Mask:255.255.255.0

eth1 Link encap:Ethernet HWaddr 00:01:03:18:BA:59
inet6 addr: fe80::201:3ff:fe18:ba59/64 Scope:Link
UP BROADCAST RUNNING MTU:1500 Metric:1

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0

tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.0.1.1 P-t-P:10.0.1.1 Mask:255.255.255.0
UP POINTOPOINT RUNNING MTU:1500 Metric:1
RX packets:2 errors:0 dropped:0 overruns:0 frame:0
TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:116 (116.0 b) TX bytes:240 (240.0 b)
[root@dhcp160 ~]#

15. ให้จดเลข Mac address ของโน้ตบุ๊คที่จะนำมาทดสอบการเชื่อมต่อกับ chillispot
และรันคำสั่งตรวจสอบว่าโน้ตบุ๊คได้ IP Address จาก chillispot ดังนี้
tail -f /var/log/messages
จะได้ผลลัพธ์แสดงคล้าย ๆ ตังอย่างข้างล่างนี้
ผลลัพธ์

[root@dhcp160 ~]# tail -f /var/log/messages
Nov 27 20:05:18 dhcp160 Installed: httpd-manual.i386 2.2.6-1.fc6
Nov 27 20:06:54 dhcp160 Installed: distcache.i386 1.4.5-14.1
Nov 27 20:06:57 dhcp160 Installed: mod_ssl.i386 1:2.2.6-1.fc6
Nov 27 20:57:57 dhcp160 chillispot[23328]: ChilliSpot 1.1.0.
Copyright 2002-2005 Mondru AB. Licensed under GPL.
See http://www.chillispot.org for credits.
Nov 27 20:57:57 dhcp160 kernel: tun: Universal TUN/TAP device driver, 1.6
Nov 27 20:57:57 dhcp160 kernel: tun: (C) 1999-2004 Max Krasnyansky <
maxk@qualcomm.com

>
Nov 27 20:57:57 dhcp160 kernel: ADDRCONF(NETDEV_CHANGE): tun0: link becomes ready
Nov 27 20:57:57 dhcp160 kernel: eth1: setting full-duplex.
Nov 27 20:58:00 dhcp160 chillispot[23328]: chilli.c: 3509:
New DHCP request from MAC=00-1D-7E-27-C3-18
Nov 27 20:58:00 dhcp160 chillispot[23328]: chilli.c: 3479:
Client MAC=00-1D-7E-27-C3-18 assigned IP 10.0.1.2
Nov 27 21:16:55 dhcp160 chillispot[23328]: chilli.c: 3509:
New DHCP request from MAC=00-13-02-69-41-FA
Nov 27 21:16:55 dhcp160 chillispot[23328]: chilli.c: 3479:
Client MAC=00-13-02-69-41-FA assigned IP 10.0.1.3
Nov 27 21:20:32 dhcp160 chillispot[23328]: chilli.c: 3759:
Successful UAM login from username=chilli IP=10.0.1.3
Ctrl-C break

โดยที่ 10.0.1.2 จะเป็น IP ของแอคเซสพอยน์ และ 10.0.1.3 จะเป็น IP ของโน้ตบุ๊คตัวแรกที่เชื่อมต่อ
16. เริ่มขั้นตอนทดสอบระบบที่เครื่องโน้ตบุคดังนี้
เริ่มทำการคอนเนค W-IFI
คลิกที่นี่เพื่อดูรูป
ที่บราวเซอร์ให้ยกเลิกการเซ็ตพร็อกซี่เซิร์ฟเวอร์
ที่บราวเซอร์ที่มีการเซ็ตหน้าโฮมเพจไว้ จะถูก redirect ไปยัง welcome.html ทันทีเมื่อเรียกโปรแกรม คลิกที่นี่เพื่อดูรูป
คลิกที่ข้อความ Click here to login แล้วจะมีหน้าต่างเพื่อให้ใส่ username และ password
คลิกที่นี่เพื่อดูรูป
เมื่อ login เข้าได้สำเร็จจะมีหน้าต่าง logged in พร้อมเวลาเริ่มนับ และเอาไว้ใช้สำหรับ logout
คลิกที่นี่เพื่อดูรูป
17. แก้ไขแฟ้ม /etc/rc.local เพื่อให้ firewall.iptables และ chilli มีผลทำงานด้วยเมื่อรีบูตเครื่องใหม่
เพิ่มบรรทัด 2 บรรทัดนี้ต่อท้าย
sh /etc/firewall.iptables
service chilli start
ผลลัพธ์

[root@dhcp160 ~]# gedit /etc/rc.local

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don’t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/sbin/ntpdate -u pool.ntp.org
sh /etc/firewall.iptables
service chilli start

18. รีบูตเครื่องเซิร์ฟเวอร์ 1 ครั้ง
19. ถึงขั้นตอนนี้เป็นอันเปิดใช้ระบบ chillispot แบบ web login ได้แล้ว
[Day 2]
ตอนที่ 2
2.1 การติดตั้งโปรแกรม Mysql
1. ติดตั้งโปรแกรม mysql ด้วยคำสั่งดังนี้
yum install mysql
yum install mysql-server
ผลลัพธ์

[root@dhcp220 ~]# yum install mysql
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mysql i386 5.0.27-1.fc6 updates 3.3 M

Transaction Summary
=============================================================================

Complete!

[root@dhcp220 ~]# yum install mysql-server
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mysql-server i386 5.0.27-1.fc6 updates 10 M
Installing for dependencies:
perl-DBD-MySQL i386 3.0007-1.fc6 base 147 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp220 ~]#

2. สั่งให้รันทุกครั้งที่รีบูตเครื่อง ด้วยคำสั่งดังนี้
chkconfig mysqld on
ผลลัพธ์

[root@dhcp220 ~]# chkconfig mysqld on
[root@dhcp220 ~]#

3. รัน mysqld ด้วยคำสั่ง
service mysqld start
ผลลัพธ์

[root@dhcp220 ~]# service mysqld start
Initializing MySQL database: Installing all prepared tables
Fill help tables

To start mysqld at boot time you have to copy support-files/mysql.server
to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h dhcp220.cc.psu.ac.th password ‘new-password’
See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with the benchmarks in the ‘sql-bench’ directory:
cd sql-bench ; perl run-all-tests

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at

http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com
[ OK ]
Starting MySQL: [ OK ]
[root@dhcp220 ~]#

4. เปลี่ยนรหัสผ่านให้กับ admin ของ mysql ด้วยคำสั่งดังนี้
/usr/bin/mysqladmin -u root password ‘abcd1234′
ผลลัพธ์

[root@dhcp220 ~]# /usr/bin/mysqladmin -u root password ‘abcd1234’
[root@dhcp220 ~]#

5. เข้าไปสร้าง database และ user ชื่อ radius เพื่อให้ freeradius ใช้ฐานข้อมูลที่เกี่ยวข้องในการ authentication ได้ ดังนี้
mysql -uroot -pabcd1234
สร้าง database ชื่อ radius ดังนี้
CREATE DATABASE radius;
สร้าง user ที่มีสิทธิใน database ดังนี้
GRANT ALL PRIVILEGES ON radius.* to ‘radius’@’localhost’ IDENTIFIED BY ‘abcd1234′;
FLUSH PRIVILEGES;
ออกจาก mysql ด้วยคำสั่ง
quit
ผลลัพธ์

[root@dhcp220 ~]# mysql -uroot -pabcd1234
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3 to server version: 5.0.27

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.

mysql>
mysql> CREATE DATABASE radius;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON radius.* to ‘radius’@’localhost’
IDENTIFIED BY ‘abcd1234’;
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@dhcp220 ~]#

6. ใส่ database schema ด้วยคำสั่งดังนี้ (ตรวจสอบเลขเวอร์ชั่นก่อน)
mysql -uroot -pabcd1234 radius < /usr/share/doc/freeradius-?.?.?/examples/mysql.sql
ผลลัพธ์

[root@dhcp220 ~]# mysql -uroot -pabcd1234 radius < /usr/share/doc/freeradius-1.1.*/
examples/mysql.sql
[root@dhcp220 ~]#

7. เข้าไปใน mysql อีกครั้งด้วยคำสั่ง
mysql -uroot -pabcd1234
เปิดใช้ฐานข้อมูลชื่อ radius
use radius;
แล้วใส่ข้อมูลตัวอย่าง
บัญชีผู้ใช้ fredf จะได้รับสิทธิ 3 ชั่วโมงต่อวัน (10800 วินาที) ใช้ได้สูงสุด 90 ชั่วโมง (324000 วินาที)
ถูกกำหนดให้ใช้งานได้ (session) 1 ชั่วโมงต่อครั้ง (3600 วินาที) และสามารถดาวน์โหลดได้ที่ 56K และอัปโหลดได้ที่ 33.4K
บัญชีผู้ใช้ barney จะได้รับสิทธิ 3 ชั่วโมงต่อวัน (10800 วินาที) และถูกกำหนดให้ใช้งานได้ 1 ชั่วโมงต่อครั้ง
บัญชีผู้ใช้ dialrouter จะได้รับสิทธิเดือนละ 90 ชั่วโมง (324000 วินาที) และถูกกำหนดให้ใช้งานได้ 30 นาทีต่อครั้ง
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Password’, ‘==’, ‘wilma’);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Max-Daily-Session’, ‘:=’, ’10800′);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Max-All-Session’, ‘:=’, ’324000′);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘barney’, ‘Password’, ‘==’, ‘betty’);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘barney’, ‘Max-Daily-Session’, ‘:=’, ’10800′);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘dialrouter’, ‘Password’, ‘==’, ‘dialup’);
INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES (‘dialrouter’, ‘Max-Monthly-Session’, ‘:=’, ’324000′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Idle-Timeout’, ‘:=’, ’1800′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘Session-Timeout’, ‘:=’, ’3600′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘WISPr-Bandwidth-Max-Down’, ‘:=’, ’56000′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘fredf’, ‘WISPr-Bandwidth-Max-Up’, ‘:=’, ’33400′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘barney’, ‘Idle-Timeout’, ‘:=’, ’1800′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘barney’, ‘Session-Timeout’, ‘:=’, ’3600′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘dialrouter’, ‘Idle-Timeout’, ‘:=’, ’900′);
INSERT INTO radreply (UserName, Attribute, Op, Value) VALUES (‘dialrouter’, ‘Session-Timeout’, ‘:=’, ’1800′);
INSERT INTO usergroup (UserName, GroupName) VALUES (‘fredf’, ‘dynamic’);
INSERT INTO usergroup (UserName, GroupName) VALUES (‘barney’, ‘static’);
INSERT INTO usergroup (UserName, GroupName) VALUES (‘dialrouter’, ‘netdial’);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘dynamic’, ‘Auth-Type’, ‘:=’, ‘Local’);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘dynamic’, ‘Simultaneous-Use’, ‘:=’, ’1′);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘static’, ‘Auth-Type’, ‘:=’, ‘Local’);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘static’, ‘Simultaneous-Use’, ‘:=’, ’1′);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘netdial’, ‘Auth-Type’, ‘:=’, ‘Local’);
INSERT INTO radgroupcheck (GroupName, Attribute, Op, Value) VALUES (‘netdial’, ‘Simultaneous-Use’, ‘:=’, ’1′);
INSERT INTO radgroupreply (GroupName, Attribute, Op, Value) VALUES (‘dynamic’, ‘Service-Type’, ‘:=’, ‘Login-User’);
INSERT INTO radgroupreply (GroupName, Attribute, Op, Value) VALUES (‘static’, ‘Service-Type’, ‘:=’, ‘Login-User’);
INSERT INTO radgroupreply (GroupName, Attribute, Op, Value) VALUES (‘netdial’, ‘Service-Type’, ‘:=’, ‘Login-User’);
คำสั่งที่ใช้แสดงข้อมูลเรคคอร์ดใน table
show tables;
select * from radcheck;
select * from radreply;
select * from usergroup;
select * from radgroupcheck;
select * from radgroupreply;
แล้วออกจาก mysql
ผลลัพธ์

[root@dhcp220 ~]# mysql -uroot -pabcd1234
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 5 to server version: 5.0.27

Type ‘help;’ or ‘h’ for help. Type ‘c’ to clear the buffer.
mysql> use radius;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> INSERT INTO radcheck (UserName, Attribute, Op, Value) VALUES
(‘fredf’, ‘Password’, ‘==’, ‘wilma’);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO radgroupreply (GroupName, Attribute, Op, Value) VALUES
(‘netdial’, ‘Service-Type’, ‘:=’, ‘Login-User’);
Query OK, 1 row affected (0.00 sec)

mysql> show tables;
+——————+
| Tables_in_radius |
+——————+
| nas |
| radacct |
| radcheck |
| radgroupcheck |
| radgroupreply |
| radippool |
| radpostauth |
| radreply |
| usergroup |
+——————+
9 rows in set (0.00 sec)

mysql> select * from radcheck;
+—-+————+———————+—-+——–+
| id | UserName | Attribute | op | Value |
+—-+————+———————+—-+——–+
| 1 | fredf | Password | == | wilma |
| 2 | fredf | Max-Daily-Session | := | 10800 |
| 3 | fredf | Max-All-Session | := | 324000 |
| 4 | barney | Password | == | betty |
| 5 | barney | Max-Daily-Session | := | 10800 |
| 6 | dialrouter | Password | == | dialup |
| 7 | dialrouter | Max-Monthly-Session | := | 324000 |
+—-+————+———————+—-+——–+
7 rows in set (0.02 sec)

mysql> select * from radreply;
+—-+————+————————–+—-+——-+
| id | UserName | Attribute | op | Value |
+—-+————+————————–+—-+——-+
| 1 | fredf | Idle-Timeout | := | 1800 |
| 2 | fredf | Session-Timeout | := | 3600 |
| 3 | fredf | WISPr-Bandwidth-Max-Down | := | 56000 |
| 4 | fredf | WISPr-Bandwidth-Max-Up | := | 33400 |
| 5 | barney | Idle-Timeout | := | 1800 |
| 6 | barney | Session-Timeout | := | 3600 |
| 7 | dialrouter | Idle-Timeout | := | 900 |
| 8 | dialrouter | Session-Timeout | := | 1800 |
+—-+————+————————–+—-+——-+
8 rows in set (0.00 sec)

mysql> select * from usergroup;
+————+———–+———-+
| UserName | GroupName | priority |
+————+———–+———-+
| fredf | dynamic | 1 |
| barney | static | 1 |
| dialrouter | netdial | 1 |
+————+———–+———-+
3 rows in set (0.01 sec)

mysql> select * from radgroupcheck;
+—-+———–+——————+—-+——-+
| id | GroupName | Attribute | op | Value |
+—-+———–+——————+—-+——-+
| 1 | dynamic | Auth-Type | := | Local |
| 2 | dynamic | Simultaneous-Use | := | 1 |
| 3 | static | Auth-Type | := | Local |
| 4 | static | Simultaneous-Use | := | 1 |
| 5 | netdial | Auth-Type | := | Local |
| 6 | netdial | Simultaneous-Use | := | 1 |
+—-+———–+——————+—-+——-+
6 rows in set (0.00 sec)

mysql> select * from radgroupreply;
+—-+———–+————–+—-+————+
| id | GroupName | Attribute | op | Value |
+—-+———–+————–+—-+————+
| 1 | dynamic | Service-Type | := | Login-User |
| 2 | static | Service-Type | := | Login-User |
| 3 | netdial | Service-Type | := | Login-User |
+—-+———–+————–+—-+————+
3 rows in set (0.00 sec)

mysql> quit
Bye
[root@dhcp220 ~]#

8. ติดตั้งโปรแกรมเพิ่มเพื่อให้ mysql ทำงานร่วมกับ freeradius ได้
yum install freeradius-mysql
ผลลัพธ์

[root@dhcp220 ~]# yum install freeradius-mysql
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
freeradius-mysql i386 1.1.7-3.1.fc6 updates 17 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp220 ~]#

9. แก้ไขไฟล์ /etc/raddb/sql.conf
บรรทัดที่ 21 แก้ไขให้เป็น
login = “radius”
password = “abcd1234″
radius_db = “radius”
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/raddb/sql.conf

# Connect info
server = “localhost”
login = “radius”
password = “abcd1234”

# Database table configuration
radius_db = “radius”

10. แก้ไขไฟล์ /etc/raddb/radiusd.conf
ใน section module {}
บรรทัดที่ 1261 เดิม # $INCLUDE ${confdir}/sql.conf
แก้ไขโดยการเอาคอมเมนต์ออก เป็น $INCLUDE ${confdir}/sql.conf
ใน section authorize {}
บรรทัดที่ 1858 เดิม files
แก้ไขโดยการใส่คอมเมนต์ เป็น #files
บรรทัดที่ 1865 เดิม #sql
แก้ไขโดยการเอาคอมเมนต์ออก เป็น sql
ใน section accounting {}
บรรทัดที่ 2028 เดิม #sql
แก้ไขโดยการเอาคอมเมนต์ออก เป็น sql
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/raddb/radiusd.conf

Line 1261
# Include another file that has the SQL-related configuration.
# This is another file only because it tends to be big.
#
# The following configuration file is for use with MySQL.
#
# For Postgresql, use: ${confdir}/postgresql.conf
# For MS-SQL, use: ${confdir}/mssql.conf
# For Oracle, use: ${confdir}/oraclesql.conf
#
$INCLUDE ${confdir}/sql.conf

Line 1858

#files

Line 1865
#
# Look in an SQL database. The schema of the database
# is meant to mirror the “users” file.
#
# See “Authorization Queries” in sql.conf
sql

Line 2028
#
# Log traffic to an SQL database.
#
# See “Accounting queries” in sql.conf
sql

11. สั่งรีสตาร์ท radius ใหม่ ด้วยคำสั่ง
service radiusd restart
ผลลัพธ์

[root@dhcp220 ~]# service radiusd restart
radiusd (pid 2062) is running…
radiusd (pid 2062) is running…
Stopping RADIUS server: [ OK ]
radiusd is stopped
Starting RADIUS server: Wed Nov 28 09:55:07 2007 : Info: Starting – reading configur
ation files …
[ OK ]
[root@dhcp220 ~]#

12. ทดสอบการเข้าใช้งาน ดังนี้
radtest fredf wilma localhost 0 mytestkey
ผลลัพธ์

[root@dhcp220 ~]# radtest fredf wilma localhost 0 mytestkey
Sending Access-Request of id 124 to 127.0.0.1 port 1812
User-Name = “fredf”
User-Password = “wilma”
NAS-IP-Address = 255.255.255.255
NAS-Port = 0
rad_recv: Access-Accept packet from host 127.0.0.1:1812, id=124, length=62
Idle-Timeout = 1800
Session-Timeout = 3600
WISPr-Bandwidth-Max-Down = 56000
WISPr-Bandwidth-Max-Up = 33400
Service-Type = Login-User
[root@dhcp220 ~]#

13. ตรวจสอบข้อผิดพลาดได้ที่ /var/log/radius/radius.log และ /var/log/radius/radius.log
ผลลัพธ์

[root@dhcp220 ~]# tail -f /var/log/radius/radius.log

Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #0
Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #1
Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #2
Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #3
Wed Nov 28 09:55:08 2007 : Info: rlm_sql_mysql: Starting connect to MySQL server for #4
Wed Nov 28 09:55:08 2007 : Info: Ready to process requests.
[root@dhcp220 ~]#
[root@dhcp220 ~]# tail -f /var/log/mysqld.log

InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
071128 9:16:14 InnoDB: Started; log sequence number 0 0
071128 9:16:14 [Note] /usr/libexec/mysqld: ready for connections.
Version: ‘5.0.27’ socket: ‘/var/lib/mysql/mysql.sock’ port: 3306 Source distribution
[root@dhcp220 ~]#

14. ตรวจสอบดูข้อมูลของการ login ของผู้ใช้งาน freeradius จะเก็บไว้ที่ไดเรกทอรี
/var/log/radius/radacct/127.0.0.1/
ผลลัพธ์

[root@dhcp220 ~]# more /var/log/radius/radacct/127.0.0.1/detail-20071128
Wed Nov 28 10:11:04 2007
Acct-Status-Type = Start
User-Name = “fredf”
Calling-Station-Id = “00-13-02-69-41-FA”
Called-Station-Id = “00-01-03-18-BA-59”
NAS-Port-Type = Wireless-802.11
NAS-Port = 0
NAS-Port-Id = “00000000”
NAS-IP-Address = 0.0.0.0
NAS-Identifier = “nas01”
Framed-IP-Address = 10.0.1.2
Acct-Session-Id = “474cdc1f00000000”
Client-IP-Address = 127.0.0.1
Acct-Unique-Session-Id = “0db96d0b6e7fdf38”
Timestamp = 1196219464

Wed Nov 28 10:13:39 2007
Acct-Status-Type = Stop
User-Name = “fredf”
Calling-Station-Id = “00-13-02-69-41-FA”
Called-Station-Id = “00-01-03-18-BA-59”
NAS-Port-Type = Wireless-802.11
NAS-Port = 0
NAS-Port-Id = “00000000”
NAS-IP-Address = 0.0.0.0
NAS-Identifier = “nas01”
Framed-IP-Address = 10.0.1.2
Acct-Session-Id = “474cdc1f00000000”
Acct-Input-Octets = 3061
Acct-Output-Octets = 4948
Acct-Input-Gigawords = 0
Acct-Output-Gigawords = 0
Acct-Input-Packets = 19
Acct-Output-Packets = 23
Acct-Session-Time = 155
Acct-Terminate-Cause = User-Request
Client-IP-Address = 127.0.0.1
Acct-Unique-Session-Id = “0db96d0b6e7fdf38”
Timestamp = 1196219619 [root@dhcp220 ~]#

————————————-
คำแนะนำเพิ่มเติม
การเซ็ตค่า sqlcounter
ใน freeradius เวอร์ชั่น 1.1.7 จะมี modules sqlcounter ให้แล้ว เราเพียงแต่เพิ่ม
noresetcounter
dailycounter
monthlycounter
ใน section ชื่อ authorize แค่นั้นเอง จะทำให้สามารถใช้งาน session-timeout และ อื่น ๆ ได้
ความหมาย
noresetcounter
the counter that never resets, can be used for real session-time cumulation
dailycounter
the counter that resets everyday, can be used for limiting daily access time (eg. 3 hours a day)
monthlycounter
the counter that resets monthly, can be used for limiting monthly access time (eg. 50 hours per month)
ใน freeradius เวอร์ชั่นต่ำกว่า 1.1.7 อาจจำเป็นต้องสร้าง sqlcounter.sql ให้อ่านคำแนะนำเพิ่มเติมได้จากเว็บไซต์
http://wiki.freeradius.org/index.php?title=Rlm_sqlcounter&printable=yes
————————————-
15. แก้ไขแฟ้ม /etc/raddb/radiusd.conf เพื่อเพิ่ม sqlcounter name ทั้ง 3 ชื่อใน section authorize { … }
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/raddb/radiusd.conf

authorize {

…some entries here…
# Append at last line in this section by wiboon
noresetcounter
dailycounter
monthlycounter

}

16. เพิ่ม sqlcounter name ชื่อ noresetcounter พร้อมรายละเอียด เนื่องจากขาดหายไปจากในแฟ้ม /etc/raddb/radiusd.conf
ให้แทรกไว้ใกล้ ๆ กับ sqlcounter name ชื่อ dailycounter
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/raddb/radiusd.conf

sqlcounter noresetcounter {

counter-name = Max-All-Session-Time
check-name = Max-All-Session
sqlmod-inst = sql
key = User-Name
reset = never
query = “SELECT SUM(AcctSessionTime) FROM radacct WHERE UserName=’%{%k}'”

}

2.1 ทดสอบ authentication โดยใช้ username/password ของ Mysql
1. ทดสอบการเข้าใช้งานจากเครื่องโน้ตบุ๊คด้วย username fredf จะเห็นว่ามีตัวเลข session time ลดลงเรื่อย ๆ ผลลัพธ์ดังรูป

2. ทดสอบการเข้าใช้งานเมื่อ username fredf ใช้งานครบ 3 ชั่วโมงใน 1 วันแล้ว ผลลัพธ์ดังรูป

3. ทดสอบการเข้าใช้งานของ username fredf เป็นครั้งที่ 2 ในขณะที่กำลังใช้งานอยู่อีกเครื่อง ผลลัพธ์ดังรูป

————————————-
คำแนะนำเพิ่มเติม
กรณีที่ต้องการลบฐานข้อมูล ชื่อ radius และสร้างใหม่ทำได้ดังนี้
เข้า mysql ด้วยคำสั่งดังนี้
mysql -uroot -pabcd1234
ใช้คำสั่ง
DROP DATABASE radius;
CREATE DATABASE radius;
GRANT ALL PRIVILEGES ON radius.* to ‘radius’@’localhost’ IDENTIFIED BY ‘abcd1234′;
FLUSH PRIVILEGES;
เปิดฐานข้อมูล
use radius;
สร้าง schema โดยใช้คำสั่งนำเข้าคือ . (โปรดระวังเลขเวอร์ชั่นของ freeradius อาจเปลี่ยนไป)
. /usr/share/doc/freeradius-1.1.?/examples/mysql.sql
นำเข้าเรคคอร์ดจากแฟ้ม (คัดลอกข้อมูลตัวอย่างมาเก็บไว้ /root/chilli-sql-example.sql)
. /root/chilli-sql-example.sql
ออก
quit
————————————-
2.3 การติดตั้งโปรแกรม radiusContext เพื่อทำรายงานการใช้งาน Freeradius
————————————-
คัดลอกจาก การติดตั้ง radius server ด้วยโปรแกรม freeradius (18-01-2550)
http://rd.cc.psu.ac.th/content/view/35/46/
การแสดงผลรายงานจำเป็นต้องหาโปรแกรมมาต่างหาก
ขอแนะนำตัวอย่างโปรแกรมแสดงผลรายงาน
* ต้นแหล่งข้อมูลคือ 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/radius-report
จะแสดงผลบนโฮมพจ 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
————————————-
1. ติดตั้งโปรแกรมตามคำแนะนำข้างบนนี้
ผลลัพธ์

[root@dhcp220 ~]# wget ftp://ftp.psu.ac.th/pub/freeradius/radiusContext-1.93.tar.gz
[root@dhcp220 ~]# tar -C /root -zxvf radiusContext-1.93.tar.gz
[root@dhcp220 ~]# mkdir /var/www/html/radius-report
[root@dhcp220 ~]# /root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
[root@dhcp220 ~]# /root/radiusContext-1.93/stdreport -D /var/www/html/radius-report
[root@dhcp220 ~]#

2. เข้าโปรแกรม Mozilla แล้วไปที่ http://127.0.0.1/radius-report/ จะเห็นรายงานการใช้งาน
3. สั่งให้ linux ทำการจัดทำรายงานใหม่ทุกชั่วโมง โดยใช้ crontab
ใช้คำสั่ง more ตรวจสอบดูแฟ้ม /etc/crontab
ผลลัพธ์

[root@dhcp220 ~]# more /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
[root@dhcp220 ~]#

4. สร้างแฟ้มเก็บคำสั่งจัดทำรายงาน ตั้งชื่อว่า radius-report ด้วยคำสั่ง
gedit /etc/cron.hourly/radius-report
ใส่ข้อความ 2 บรรทัดนี้
/root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
/root/radiusContext-1.93/stdreport -D /var/www/html/radius-report
แล้วเปลี่ยนโหมดของแฟ้มเป็น execute ด้วยคำสั่ง
chmod +x /etc/cron.hourly/radius-report
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/cron.hourly/radius-report

/root/radiusContext-1.93/raddetail /var/log/radius/radacct/*/*
/root/radiusContext-1.93/stdreport -D /var/www/html/radius-report

[root@dhcp220 ~]# chmod +x /etc/cron.hourly/radius-report
[root@dhcp220 ~]#

[Day 3]
ตอนที่ 3
3.1 การติดตั้งโปรแกรม squid
โปรแกรม squid คือโปรแกรมที่ทำงานเป็น proxy / webcache server เพื่อใช้อินเทอร์เน็ตผ่านพร็อกซี่
1. ติดตั้งโปรแกรม squid ด้วยคำสั่ง
yum install squid
ผลลัพธ์

[root@dhcp220 ~]# yum install squid
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
squid i386 7:2.6.STABLE13-1.fc6 updates 1.2 M
Installing for dependencies:
perl-URI noarch 1.35-3 base 116 k

Transaction Summary
=============================================================================

Complete!
[root@dhcp220 ~]#

2. สั่งให้โปรแกรม squid ทำงานในการรีบูตเครื่องในครั้งต่อไป ด้วยคำสั่ง
chkconfig squid on
ผลลัพธ์

[root@dhcp220 ~]# chkconfig squid on
[root@dhcp220 ~]#

3. สร้างไดเรกทอรีเพื่อเก็บข้อมูลเว็บแคช ด้วยคำสั่ง
squid -z
ผลลัพธ์

[root@dhcp220 ~]# squid -z
2007/11/29 10:44:51| Creating Swap Directories
[root@dhcp220 ~]#

4. ปรับแต่งแฟ้มคอนฟิก /etc/squid/squid.conf ให้เหมาะสมดังนี้
ทำเป็น tranparent proxy
http_port 3128 transparent
ใช้ parent cache ในการออกอินเทอร์เน็ต (cache.your.domain คือชื่อ parent proxy ของหน่วยงานคุณ)
โดยที่ parent cache ตั้งใจเปิด port 8080 แทน 3128
cache_peer cache.your.domain parent 8080 0 no-query
(ถ้าไม่มี parent cache หรือ ไม่รู้ว่า parent cache คืออะไร cache_peer ไม่ต้องเซ็ตครับ)
ไม่เก็บ log ชนิด dump memory
cache_store_log none
กำหนดไอพีแอดเดรสเครือข่ายที่อนุญาตให้ใช้งาน proxy server นี้ได้
ตัวอย่างอนุญาตเฉพาะ net ของไวร์เลส
สามารถเพิ่มรายการ our_networks บรรทัดที่ 2,3,… ได้เองจากที่ผมทำไว้ให้
acl our_networks src 10.0.1.0/24 192.168.2.0/24
http_access allow our_networks
กำหนดให้มีแฟ้มเก็บ access.log 2 แฟ้มหมุนเวียนแบบเขียนทับ คือ access.log และ access.log.0
logfile_rotate 1
กำหนดให้ใช้งานผ่าน parent cache เท่านั้น จะไม่มีการ direct port 80 ไปอินเทอร์เน็ตเอง
never_direct allow all
(ถ้าไม่มี parent cache หรือ ไม่รู้ว่า parent cache คืออะไร never_direct ไม่ต้องเซ็ตครับ)
กำหนดให้ไปยังเว็บอินทราเน็ตโดยไม่ต้องใช้ proxy ของเรา เพื่อลดเวลาตอบสนอง
สามารถเพิ่มรายการ intranet_server ได้เองจากที่ผมทำไว้ให้
acl intranet_server dst 192.168.0.0/255.255.0.0
acl intranet_server dst 172.16.0.0/255.240.0.0
acl intranet_server dst 10.0.0.0/255.0.0.0
always_direct allow intranet_server
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/squid/squid.conf

Line 89
http_port 3128 transparent

Line 583
cache_peer cache.your.domain parent 8080 0 no-query

Line 1123
cache_store_log none

Line 2548
acl our_networks src 10.0.1.0/24 192.168.2.0/24
http_access allow our_networks

Line 2987
logfile_rotate 1

Line 3400
never_direct allow all

Line 3366
acl intranet_server dst 192.168.0.0/255.255.0.0
acl intranet_server dst 172.16.0.0/255.240.0.0
acl intranet_server dst 10.0.0.0/255.0.0.0
always_direct allow intranet_server

5. สั่งให้โปรแกรม squid ทำงาน ด้วยคำสั่ง
service squid start
ผลลัพธ์

[root@dhcp220 ~]# service squid start
Starting squid: . [ OK ]
[root@dhcp220 ~]#

3.2 การทำ Transparent proxy ด้วย iptables
1. แก้ไขแฟ้ม /etc/firewall.iptables โดยเพิ่มบรรทัด
##Allow transparent proxy (wiboon 1/2)
$IPTABLES -A INPUT -p tcp -m tcp –dport 3128 –syn -j ACCEPT
และ
##Allow transparent proxy (wiboon 2/2)
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 3128 –syn -j DROP
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 192.168.0.0/16 –dport 80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 172.16.0.0/12 –dport 80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/8 –dport 80 -j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 80 -j REDIRECT –to-ports 3128
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/firewall.iptables

IPTABLES=”/sbin/iptables”
EXTIF=”eth0″
INTIF=”eth1″

#Flush all rules
$IPTABLES -F
$IPTABLES -F -t nat
$IPTABLES -F -t mangle

#Set default behaviour
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT

#Allow related and established on all interfaces (input)
$IPTABLES -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT

#Allow releated, established and ssh on $EXTIF. Reject everything else.
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp –dport 22 –syn -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -j REJECT

#Allow related and established from $INTIF. Drop everything else.
$IPTABLES -A INPUT -i $INTIF -j DROP

#Allow http and https on other interfaces (input).
#This is only needed if authentication server is on same server as chilli
$IPTABLES -A INPUT -p tcp -m tcp –dport 80 –syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp –dport 443 –syn -j ACCEPT

#Allow 3990 on other interfaces (input).
$IPTABLES -A INPUT -p tcp -m tcp –dport 3990 –syn -j ACCEPT
##Allow transparent proxy (wiboon 1/2)
$IPTABLES -A INPUT -p tcp -m tcp –dport 3128 –syn -j ACCEPT

#Allow ICMP echo on other interfaces (input).
$IPTABLES -A INPUT -p icmp –icmp-type echo-request -j ACCEPT

#Allow everything on loopback interface.
$IPTABLES -A INPUT -i lo -j ACCEPT

##Allow transparent proxy (wiboon 2/2)
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 3128 –syn -j DROP
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 192.168.0.0/16 –dport 80
-j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 172.16.0.0/12 –dport 80
-j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp -d 10.0.0.0/8 –dport 80
-j RETURN
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp –dport 80
-j REDIRECT –to-ports 3128

# Drop everything to and from $INTIF (forward)
# This means that access points can only be managed from ChilliSpot
$IPTABLES -A FORWARD -i $INTIF -j DROP
$IPTABLES -A FORWARD -o $INTIF -j DROP

#Enable NAT on output device
$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE

————————————-
หากต้องการเปิด port ด้าน eth0 ให้อนุญาต port 443 และ 10000 ให้เพิ่ม 2 บรรทัดข้างล่างนี้ต่อท้ายบรรทัดที่อนุญาต port 22
#Allow https to web account management (wiboon).
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp –dport 443 –syn -j ACCEPT
#Allow any port i.e. 10000 to this server (wiboon).
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp –dport 10000 –syn -j ACCEPT
————————————-
2. สั่งให้ iptables ทำงานเป็น firewall ตามแฟ้ม /etc/firewall.iptables ด้วยคำสั่ง
sh /etc/firewall.iptables
ผลลัพธ์

[root@dhcp220 ~]# sh /etc/firewall.iptables
[root@dhcp220 ~]#

3. ทดสอบการใช้งานที่เครื่องไคลเอนต์ ลองไปยังเว็บไซต์ google
แล้วเช็คดูในแฟ้ม /var/log/squid/access.log
ผลลัพธ์

[root@dhcp220 ~]# tail -f /var/log/squid/access.log
1196309038.756 2449 10.0.1.4 TCP_MISS/200 2551 GET http://www.google.co.th/ – TIMEOUT_FIRST_UP_PARENT/cache.psu.ac.th text/html
1196309220.447 181690 10.0.1.4 TCP_MISS/504 1480 GET http://www.google.co.th/gen_204? – DIRECT/72.14.235.104 text/html
ctrl-c break

3.3 การตั้งเวลาเก็บ access.log ทุกคืน
1. สร้างแฟ้ม shell script ใหม่ชื่อ rotate_and_keep_proxy_log
เพื่อเก็บบรรทัดคำสั่งที่ใช้ในการ rotate log และเก็บ log ในรูปแบบย่อ เพื่อให้อ่านง่ายและประหยัดเนื้อที่
โดยใช้คำสั่ง
gedit /etc/cron.daily/rotate_and_keep_proxy_log
แล้วเปลี่ยนโหมดของแฟ้มเป็น execute
chmod +x /etc/cron.daily/rotate_and_keep_proxy_log
ผลลัพธ์

[root@dhcp220 ~]# gedit /etc/cron.daily/rotate_and_keep_proxy_log

#!/bin/bash
day=date '+%Y%m%d'
if [ -f /root/logs/access.log.cache.${day} ]; then
exit 0
fi
squid -k rotate
cat /var/log/squid/access.log.0 | awk ‘{print $1 ” ” $3 ” ” $6 ” ” $7}’ |
perl -pe ‘s/^d+.d+/localtime($&)/e;’ > /root/logs/access.log.cache.${day}

[root@dhcp220 ~]# chmod +x /etc/cron.daily/rotate_and_keep_proxy_log
[root@dhcp220 ~]#

2. หากเนื้อที่ดิสก์ไม่เพียงพอ จำเป็นจะต้องย้ายไปเก็บยังเซิร์ฟเวอร์ตัวอื่น ให้ใช้คำสั่ง scp คัดลอกแฟ้มไป
ต้องแก้ไข shell script อีกเล็กน้อย
ที่มา: http://www.mycools.in.th/archives/46/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%97%E0%B8%B3-wireless-lan-controller-%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2-chillispot-%E0%B9%81%E0%B8%9A%E0%B8%9A-web-login-freeradius-mysql-transparent-proxy/

การติดตั้ง 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

การติดตั้ง 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