วันศุกร์ที่ 5 พฤศจิกายน พ.ศ. 2553

mrtg บน freebsd

1. ติดตั้ง snmp ผ่าน ports
#cd /usr/ports/net-mgmt/net-snmp/
#make ; make install clean
#rehash

แก้ไข config ไฟล์ ในที่นี้ผมใช้ editor ee นะครับ ท่านจะใช้ pico ก็ได้
#ee /usr/local/share/snmp/snmpd.conf
พิมพ์ 4 บรรทัดนี้ลงไปครับ ของเดิมหากมี ลบ ให้หมด เอา 4 บรรทัดนี้พอ
rouser public noauth
rocommunity public localhost
syslocation gateway at service room
syscontact webmaster@xxx.com
(2 บรรทัดสุดท้าย แก้ไขตามใจชอบครับ)
แล้ว save ครับ

เรียก snmpd ให้ทำงาน
#snmpd &

ตรวจดูว่ามี process snmpd จริงป่าว....
#ps -ax | grep snmpd

หากอยากให้ snmp ทำงานทุกครั้งก็แก้ไข /etc/rc.conf เพิ่ม สองบรรทัดนี้ลงไป

snmpd_enable="YES"
snmpd_flags="-a -Lsd -p /var/run/snmpd.pid"

2. ติดตั้ง MRTG ผ่าน port
#cd /usr/ports/net-mgmt/mrtg/
#make ; make install clean
#rehash
#cfgmaker public@localhost> /usr/local/etc/mrtg/mrtg.cfg

แก้ไข config
#ee /usr/local/etc/mrtg/mrtg.cfg

WorkDir: /home/webmrtg/public_html
Options[_]:growright,bits

***ผม adduser มา 1 คนชื่อ webmrtg แล้วสร้าง public_html ไว้เพื่อใช้เป็น mrtg เวบครับ

#indexmaker --columns=1 --output=/home/webmrtg/public_html/index.html /usr/local/etc/mrtg/mrtg.cfg

#mrtg /usr/local/etc/mrtg/mrtg.cfg
รันไป 3 ครั้ง ก็จะไม่มี warning ครับ

#ee /etc/crontab
พิมพ์ บรรทัดนี้ ต่อท้ายของเดิม
*/5 * * * * root /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg

เพื่อให้กราฟ update ทุก ๆ 5 นาที


ถ้าอยากให้กราฟแสดง cpu และ ram ก็เพิ่ม
code ด้านล่างลงไปในไฟล์ mrtg.cfg
แทรกต่อจาก code html ที่เค้าแสดงสาถานะครับเข้าไปดูแล้วจะรู้เองครับว่าควรแทรกแถวไหน ครับ
### Load Average ###
Target[cpu]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.2:public@127.0.0.1
MaxBytes[cpu]: 100
Unscaled[cpu]: dwmy
Options[cpu]: gauge, absolute, growright, noinfo, nopercent
YLegend[cpu]: CPU Load(%)
ShortLegend[cpu]: (%)
LegendI[cpu]:   CPU System
LegendO[cpu]:   CPU User
Title[cpu]: CPU Analysis
PageTop[cpu]:

CPU Analysis



### Memory Free ###
Target[mem]: .1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:public@127.0.0.1
MaxBytes1[mem]: 1030288
MaxBytes2[mem]: 1052216
Unscaled[mem]: dwmy
Options[mem]: gauge, absolute, growright, noinfo
YLegend[mem]: Memory Free
ShortLegend[mem]: Bytes
kilo[mem]: 1024
kMG[mem]: k,M,G,T,P
LegendI[mem]: Real
LegendO[mem]: Swap
Legend1[mem]: (MBytes)
Legend2[mem]: (MBytes)
Title[mem]: Memory Analysis
PageTop[mem]:

Memory Analysis

วันจันทร์ที่ 1 พฤศจิกายน พ.ศ. 2553

cpu 64 bit กับการทำ authen บน freebsd

บทความจากเวบ thaibsd.comโดยครูมานิส

ทำเหมือนเดิมครับ แต่เปลี่ยนมาใช้ FreeBSD8.0-amd64 แทน FreeBSD8.0-i386

ยกเลิกการใช้งาน natd แล้วใช้ PF แทน การปรับค่า Config ประมาณนี้ สรุป คือ ใช้ PF เป็น NAT แต่ Squid ให้ใช้ ipfw เหมือนเดิม

# nano /etc/pf.conf

int_if = "em1"
ext_if = "em0"
chilli_if = "tun0"

tcp_services = "{ 80 , 2000, 9000 , 21 }"
icmp_types = "echoreq"

priv_nets = "{ 10.8.0.0/16, 192.168.2.0/24, 192.168.212.0/24 }"


อธิบาย
int_if ="ชื่อการ์ดแลนวงใน"
ext_if ="ชื่อการ์ดแลนวงนอก"

tcp_services = "{ หมายเลข port ที่ต้องการเปิดใช้งาน }"

priv_nets = "{Class IP ของวงภายในที่อนุญาตให้ใช้งานได้}"


แก้ไขไฟล์ /etc/rc.conf

ยกเลิก natd แล้วใช้ pf แทนดังนี้

#natd_enable="YES"
#natd_interface="LAN ขา WAN"
#natd_flags="-s -u -m"

pf_enable="YES"
pf_rules="/etc/pf.conf"
pf_flags=""
pflog_enable="YES"
pflog_logfile="/var/log/pflog"
pflog_flags=""

บันทึกไฟล์

# reboot

ตอนนี้ผมเอา FreeBSD 5-6 เครื่อง ที่มี FreeBSD ต่าง versionกัน เช่น
FreeBSD 5.4 , 6.1 , 6.2 , 6.3 , 8.0 , 8.1 ที่ติดตั้งต่างกรรมต่างวาระเพื่อให้เป็น server ที่ให้บริการต่างๆ ในเครือข่าย Cloning มาวิ่งบน VMware EXSi 4.0 นิ่งมากครับ....
RAM 8 GB บนเครื่อง host ยังเหลืออีกเยอะเลยครับ... แบ่งให้ FreeBSDไป เครื่องละ 256 , 512 , 1024 MB. แล้วแต่ว่า load มากน้อยครับ...

วันอาทิตย์ที่ 31 ตุลาคม พ.ศ. 2553

วิธีแก้ไข apahe22 error กรณี libtool

บทความจากเวบ www.kroonis.org

มีเทคนิคมาฝากครับ จะไม่พบกับ Error-code1 อีกเลย สำหรับมือใหม่ เปิดแล้ว 997 | แสดงความคิดเห็น : 1
มีเทคนิคมาฝากครับ จะไม่พบกับ Error-code1 อีกเลย สำหรับมือใหม่

1. Setup FreeBSD รุ่นที่ชอบ ล่าสุดก็ FreeBSD8.0

2. ตรวจสอบเวลาเครื่องก่อน ว่าเป็นปัจจุบันไหม

# date

ถ้าไม่ตรง ตั้งใหม่ date ปีค.ศ.เดือนวันชั่วโมงนาทีวินาที เช่น

# date 201005110915

3. Update Ports ก่อน ทำตามนี้

# cd /usr/ports/lang/perl5.8

# make install clean

# rehash

# cd /usr/ports/net/cvsup/

# make install clean

ระบบถามอะไร ก็เลือก ตอบ Ok ไปเรื่อยครับ

# rehash

# /usr/local/bin/cvsup -g -L 2 -h cvsup5.freebsd.org /usr/share/examples/cvsup/ports-supfile

# cd /usr/ports && make fetchindex

หลังจาก Update Ports เสร็จใหม่ ๆ อย่าเพิ่งติดตั้งโปรแกรมเสริมนะ ให้ใช้คำสั่งด้านล่างก่อน

# cd /usr/ports/devel/libtool22/ && make FORCE_PKG_REGISTER=yes install && make clean

# rehash

Start ตาม STEP ได้เลย

1. Compile Kernel

2. Setup FAMP (Mysql5 + Apache22 + PHP5 / extensions)

3. โปรแกรมอื่น ๆ

จะไม่พบกับคำว่า Error-code1 อีกเลยครับ

ถ่ายทอดจากประสบการณ์ตรง จริง ๆ ครับ คัดลอกบรรทัดต่อบรรทัด

ฝากจากคุณพรหมมาศ แซ่ลั่ว

ช่วยให้การ error ลดลงแต่อาจจะยังมีบ้างครับ แนะนำอีกอย่างว่าควรทำการ update ports tree ด้วย โดยใช้คำสั่งต่อไปนี้ในครั้งแรก
# portsnap fetch extract update
และในการ update ครั้งต่อ ๆ ไปใช้คำสั่งนี้ครับ
# portsnap fetch update

วันเสาร์ที่ 9 ตุลาคม พ.ศ. 2553

การติดตั้ง dhcpd บน freebsd

การติดตั้ง DHCP บน FreeBSD 7.0 บทความโดย dekdar แห่ง www.thaibsd.com

1. เริ่มจากค้นหา พอร์ตของ dhcp
freebsd# cd /usr/ports/

2. ค้นหาพอร์ตของ dhcp
freebsd# make search name=dhcpd
Port: isc-dhcp3-server-3.0.5_2
Path: /usr/ports/net/isc-dhcp3-server

3. เข้าไดเรกทรอรี่ dhcp เพื่อทำการติดตั้งโปรแกรม
freebsd# cd /usr/ports/net/isc-dhcp3-server

4. เลือกออพชั่น การติดตั้งโปรแกรม
freebsd# make config
Options for isc-dhcp3-server 3.0.5_2
[X] DHCP_PARANOIA add -user, -group and -chroot options
[ ] DHCP_JAIL add -chroot and -jail options
[ ] DHCP_SOCKETS use sockets instead of /dev/bpf (jail-only)
[ ] DHCP_LDAP add experimental LDAP backend support
[X] DHCP_LDAP_SSL support LDAP connection over SSL/TLS
[X] OPENSSL_BASE use the base system OpenSSL (required by TLS)
[ ] OPENSSL_PORT use OpenSSL from ports (required by TLS)
[ ] DHCP_LQ DHCPLEASEQUERY support used by Cisco uBR's
[ OK ] Cancel

5. ทำการติดตั้งโปรแกรม
freebsd# make
freebsd# make install

6. สร้างไฟล์คอนฟิก dhcpd.conf
freebsd# cp /usr/local/etc/dhcpd.conf.sample /usr/local/etc/dhcpd.conf.sample
หรือ
freebsd# touch /usr/local/etc/dhcpd.conf

7. กำหนดค่าคอนฟิกไฟล์
freebsd# pico /usr/local/etc/dhcpd.conf
ddns-update-style ad-hoc;
option domain-name "yiu.edu";
option domain-name-servers 118.175.87.11, 203.113.24.199;
default-lease-time 6000;
max-lease-time 72000;
subnet 118.175.87.8 netmask 255.255.255.248 {
}
# This is a very basic subnet declaration.
subnet 172.30.2.0 netmask 255.255.255.0
{ range 172.30.2.20 172.30.2.250;
option routers 172.30.2.1;
option broadcast-address 172.30.2.255;
}
host server_controll {
hardware ethernet 00:04:e2:80:f7:f0;
fixed-address 172.30.2.254;
} //เป็นการกำหนดค่า แจกไอพี แบบกำหนด

8. สร้างไฟล์จัดเก็บรายละเอียดไอพี ปกติมีมาให้เรียบร้อยแล้วครับ หากไม่มีก็ให้ทำ
freebsd# touch /var/db/dhcpd.leases
freebsd# chmod 777 /var/db/dhcpd.leases

9. ทดสอบการให้บริการ DHCP
//แจกทางการ์ดทุกใบที่เชื่อมต่อ เราสามารถกำหนดเฉพาะการ์ด Network ที่ต้องการได้
freebsd# /usr/local/sbin/dhcpd &
[1] 22810
freebsd# Internet Systems Consortium DHCP Server V3.0.5
Copyright 2004-2006 Internet Systems Consortium.All rights reserved.
For info, please visithttp://www.isc.org/sw/dhcp/
Wrote 0 deleted host decls to leases file.
Wrote 0 new dynamic host decls to leases file.
Wrote 32 leases to leases file.
Listening on BPF/vr0/00:13:d3:11:5c:98/118.175.87.8/29
Sending on BPF/vr0/00:13:d3:11:5c:98/118.175.87.8/29
Listening on BPF/rl0/00:e0:4c:5a:5f:0a/172.30.2/24
Sending on BPF/rl0/00:e0:4c:5a:5f:0a/172.30.2/24
Sending on Socket/fallback/fallback-net
[1] Done /usr/local/sbin/dhcpd

10. ตรวจสอบโปรเซส dhcpd
freebsd# ps ax | grep dhcpd
22811 ?? Is 0:00.00 /usr/local/sbin/dhcpd



11. เพิ่มคำสั่งใน /etc/rc.local
freebsd# echo ‘/usr/local/sbin/dhcpd rl0 &’ >> /etc/rc.local //กรณีที่ต้องการแจกทางการ์ด rl0 เท่านั้น

12. เพิ่มคำสั่งใน /etc/rc.conf
freebsd# echo ‘dhcpd_enable="YES"’ >> /etc/rc.conf

สามารถให้งานบริการ DHCP แล้วละครับ ลง reboot เครื่องสักรอบก็ได้ครับ
freebsd# shutdown –r now

ตัวอย่าง ไฟล์ข้อมูลที่แจกไอพีให้แก่เครื่องลูกข่าย จาก /var/db/dhcpd.leases
freebsd# cat /var/db/dhcpd.leases
lease 172.30.2.247 {
starts 5 2008/07/11 15:52:07;
ends 5 2008/07/11 17:32:07;
binding state active;
next binding state free;
hardware ethernet 00:15:af:8b:83:20;
uid "\001\000\025\257\213\203 ";
client-hostname "codename";
}

ตัวอย่าง การคอนฟิกพาธใน เว็ปมิน
System configuration
DHCP server config file /usr/local/etc/dhcpd.conf
DHCP server executable /usr/local/sbin/dhcpd
Path to DHCP server PID file /var/run/dhcpd.pid
DHCP server lease file /var/db/dhcpd.leases

***แนะนำ เมื่อทำถึงขั้นตอนที่ 5 แล้ว ปกติดสามารถทำผ่าน เว็ปมิน
ได้เลยครับ และง่ายกว่าที่ต้องมาพิมพ์และคอนฟิกเอง มีเครื่องมือ
อำนวยความสะดวกก็ใช้ดีกว่าครับ หากจะพิมพ์เองก็ไม่ว่าอะไร (แต่
มันช้า และโอกาสผิดพลาดมีสูงครับ หุหุหุ++)

Detail Test : Install DHCP3 on FreeBSD 7.0
OS : FreeBSD7.0 After Update Ports
Software : Install Ports Program
Apache apache-2.2.9
MySQL mysql-server-5.1.25
PHP php5-5.2.6
Test by dekdard @ gmail.com

ใช้ FreeBSD 7 เป็น DHCP Server ใช้งานได้ปกติ แต่มีข้อความที่ Server ตลอดเมื่อเครื่องลูกข่ายขอหรือ dhcp หมดเวลา ทั้งที่สร้าง /var/db/dhcpd.leases และ chmod 777 แล้ว แก้ไขไงครับ ขอบคุณครับ

แก้ไข dhcpd.conf บรรทัดนี้ครับ
ddns-update-style แก้ไขเป็น ddns-update-style none;
อย่าลืม restart dhcpd ด้วยนะครับ

วันเสาร์ที่ 18 กันยายน พ.ศ. 2553

update ports tree บน freebsd

บทความ จาก thaibsd.com xdisc
ไหนๆจะอัพเดทล่ะก็เอาให้หมดทีเดียวไปเลยครับใช้เวลาไม่นานหรอก แพคเกจบางตัวก็จำเป็นใช้งานร่วมกัน ถ้าตัวใดตัวหนึ่งเก่าเกินไปเวลาติดตั้งอาจมีปัญหาได้

การทำ cvsup เพื่อปรับปรุง ports(ส่วนที่ใช้ในการติดตั้งโปรแกรมอัตโนมัติผ่านอินเตอร์เน็ต)
cvsup จะใช้เพื่อทำการปรับปรุง ports ต่างๆ ของเราให้ทันสมัย เพราะบาง package จำเป็นต้องปรับปรุงให้เป็นเวอร์ชั่นใหม่

ติดตั้ง cvsup ก่อน
# cd /usr/ports/net/cvsup-without-gui
# make install && make clean
# rehash
หรือ
# pkg_add -r cvsup-without-gui
# rehash

ทำการ synchronize ports index กับ cvsup server
# /usr/local/bin/cvsup -g -L 2 -h cvsup.freebsd.org /usr/share/examples/cvsup/ports-supfile
รอจนกว่าจะติดตั้งเสร็จ
# cd /usr/ports && make fetchindex

จากนั้นก็จะทำให้เราได้โปรแกรมใน /usr/ports เป็นตัวใหม่ล่าสุดแล้ว
อันนี้ของ ครูมานิส..น่าสนใจ..
.................................
1. Setup FreeBSD รุ่นที่ชอบ ล่าสุดก็ FreeBSD8.0

2. ตรวจสอบเวลาเครื่องก่อน ว่าเป็นปัจจุบันไหม

# date

ถ้าไม่ตรง ตั้งใหม่ date ปีค.ศ.เดือนวันชั่วโมงนาทีวินาที เช่น

# date 201005110915

3. Update Ports ก่อน ทำตามนี้

# cd /usr/ports/lang/perl5.8

# make install clean

# rehash

# cd /usr/ports/net/cvsup/

# make install clean

ระบบถามอะไร ก็เลือก ตอบ Ok ไปเรื่อยครับ

# rehash

# /usr/local/bin/cvsup -g -L 2 -h cvsup5.freebsd.org /usr/share/examples/cvsup/ports-supfile

# cd /usr/ports && make fetchindex

หลังจาก Update Ports เสร็จใหม่ ๆ อย่าเพิ่งติดตั้งโปรแกรมเสริมนะ ให้ใช้คำสั่งด้านล่างก่อน

# cd /usr/ports/devel/libtool22/ && make FORCE_PKG_REGISTER=yes install && make clean

# rehash

Start ตาม STEP ได้เลย

1. Compile Kernel

2. Setup FAMP (Mysql5 + Apache22 + PHP5 / extensions)

3. โปรแกรมอื่น ๆ

จะไม่พบกับคำว่า Error-code1 อีกเลยครับ

ถ่ายทอดจากประสบการณ์ตรง จริง ๆ ครับ คัดลอกบรรทัดต่อบรรทัด

วันจันทร์ที่ 13 กันยายน พ.ศ. 2553

clear squid อัตโนมัติ...

สร้างไฟล์ /usr/local/sbin/clear-squid-cache.sh
#!/bin/sh
#clear squid cache script
/usr/local/etc/rc.d/squid stop
/bin/sleep 10
rm -rf /var/cache/*
/bin/sleep 10
/usr/local/sbin/squid -z
/bin/sleep 10
/usr/local/etc/rc.d/squid start



กำหนดโหมดไฟล์
# chmod 755 /usr/local/sbin/clear-squid-cache.sh



การกำหนดเวลาการทำ log rotate แก้ไขไฟล์ /etc/crontab
0 0 * * * root /usr/local/sbin/squid -k rotate -f /usr/local/etc/squid/squid.conf
0 0 * * 0 root /usr/local/sbin/clear-squid-cache.sh

คำสั่งแรกจะทำการ rotate logfile ของ squid ทุกวัน
คำสั่งที่สองจะทำการเคลียร์ cache ของ squid ทุกสัปดาห์

ขอบคุณ คุณพรหมมาศ

วันพุธที่ 14 กรกฎาคม พ.ศ. 2553

tip ป้องกัน Ultrasurf

ป้องกัน Ultrasurf tips จาก yim แห่งthaibsd
สำหรับ freebsd ใช้ route add -net 65.49.2.0/24 10.00.2
สำหรับ linux ใช้ route add -net 65.49.2.0/24 gw 127.0.0.1

ของท่าน chet แห่ง linuxthai
ไฟล์วอลผมครับ

#!/bin/sh
#
# Firewall script for ChilliSpot
# A Wireless LAN Access Point Controller
#
# Uses $EXTIF (eth0) as the external interface (Internet or intranet) and
# $INTIF (eth1) as the internal interface (access points).
#
#
# SUMMARY
# * All connections originating from chilli are allowed.
# * Only ssh is allowed in on external interface.
# * Nothing is allowed in on internal interface.
# * Forwarding is allowed to and from the external interface, but disallowed
# to and from the internal interface.
# * NAT is enabled on the external interface.

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 ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT

#Block Ultrasurf
iptables -A FORWARD -p tcp --dport 9666 -j DROP
iptables -A FORWARD -p udp --dport 9666 -j DROP

$IPTABLES -A INPUT -s 67.15.183.30 -j DROP
$IPTABLES -A FORWARD -s 67.15.183.30 -j DROP
$IPTABLES -A OUTPUT -s 67.15.183.30 -j DROP

$IPTABLES -A INPUT -p tcp -m tcp --dport 9666 -j DROP
$IPTABLES -A FORWARD -p tcp -m tcp --dport 9666 -j DROP
$IPTABLES -A OUTPUT -p tcp -m tcp --dport 9666 -j DROP

#iptables -A FORWARD -p tcp --dport 443 -j DROP_CUSTOM
#iptables -A FORWARD -p udp --dport 443 -j DROP_CUSTOM


IPALLOW=`cat /root/special.txt | awk '{print $1}'`
iptables -N DROP_CUSTOM
for ipall in $IPALLOW
do
iptables -A DROP_CUSTOM -s $ipall -j ACCEPT
iptables -A DROP_CUSTOM -d $ipall -j ACCEPT
done
iptables -A DROP_CUSTOM -j DROP

# เจอคำพวกนี้ผ่านตา อย่าให้เล็ดลอด
iptables -A FORWARD -m string --string "info_hash" --algo bm --to 65535 -j DROP
iptables -A FORWARD -m string --string ".torrent" --algo bm --to 65535 -j DROP
iptables -A FORWARD -m string --string "get_peers" --algo bm --to 65535 -j DROP
iptables -A FORWARD -m string --string "announce_peers" --algo bm --to 65535 -j DROP

#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
$IPTABLES -A INPUT -p tcp -m tcp --dport 22 --syn -j ACCEPT

#Allow 3990 on other interfaces (input).
$IPTABLES -A INPUT -p tcp -m tcp --dport 3990 --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

# 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

##### chalee edit
#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 -p tcp -m tcp --dport 80 --syn -j ACCEPT
$IPTABLES -A INPUT -i $EXTIF -p tcp -m tcp --dport 10000 --syn -j ACCEPT

#Allow 3990 on other interfaces (input).
$IPTABLES -A INPUT -p tcp -m tcp --dport 3990 --syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp --dport 3128 --syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp --dport 3306 --syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp --dport 22 --syn -j ACCEPT
$IPTABLES -A INPUT -p tcp -m tcp --dport 10000 --syn -j ACCEPT

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

##Allow transparent proxy ##
$IPTABLES -A INPUT -p tcp -m tcp --dport 8080 --syn -j ACCEPT
$IPTABLES -t nat -A PREROUTING -i tun0 -p tcp -m tcp --dport 8080 --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 8080

# Drop package wrom Virus Input, Output
$IPTABLES -A INPUT -p tcp --dport 135 -j DROP
$IPTABLES -A INPUT -p udp --dport 135 -j DROP
$IPTABLES -A INPUT -p tcp --dport 445 -j DROP
$IPTABLES -A INPUT -p udp --dport 445 -j DROP
$IPTABLES -A INPUT -p tcp --dport 4444 -j DROP
$IPTABLES -A INPUT -p udp --dport 4444 -j DROP
$IPTABLES -A INPUT -p tcp --dport 5554 -j DROP
$IPTABLES -A INPUT -p udp --dport 5554 -j DROP
$IPTABLES -A INPUT -p tcp --dport 9996 -j DROP
$IPTABLES -A INPUT -p udp --dport 9996 -j DROP
$IPTABLES -A INPUT -p tcp --dport 137 -j DROP
$IPTABLES -A INPUT -p udp --dport 137 -j DROP
$IPTABLES -A INPUT -p tcp --dport 138 -j DROP
$IPTABLES -A INPUT -p udp --dport 138 -j DROP
$IPTABLES -A INPUT -p tcp --dport 139 -j DROP
$IPTABLES -A INPUT -p udp --dport 139 -j DROP

$IPTABLES -A OUTPUT -p tcp --dport 135 -j DROP
$IPTABLES -A OUTPUT -p udp --dport 135 -j DROP
$IPTABLES -A OUTPUT -p tcp --dport 445 -j DROP
$IPTABLES -A OUTPUT -p udp --dport 445 -j DROP
$IPTABLES -A OUTPUT -p tcp --dport 4444 -j DROP
$IPTABLES -A OUTPUT -p udp --dport 4444 -j DROP
$IPTABLES -A OUTPUT -p tcp --dport 5554 -j DROP
$IPTABLES -A OUTPUT -p udp --dport 5554 -j DROP
$IPTABLES -A OUTPUT -p tcp --dport 9996 -j DROP
$IPTABLES -A OUTPUT -p udp --dport 9996 -j DROP
$IPTABLES -A OUTPUT -p tcp --dport 137 -j DROP
$IPTABLES -A OUTPUT -p udp --dport 137 -j DROP
$IPTABLES -A OUTPUT -p tcp --dport 138 -j DROP
$IPTABLES -A OUTPUT -p udp --dport 138 -j DROP
$IPTABLES -A OUTPUT -p tcp --dport 139 -j DROP


ส่วนไอพีที่ผมใส่ไปมีแค่นี้ครับ
217.12.8.76
64.4.20.169
97.74.144.165

วันเสาร์ที่ 26 มิถุนายน พ.ศ. 2553

kick user บน freebsd

บทความจากเวบไซด์ ครูมานิส www.kroonis.org
โปรแกรม Kick User ใช้งานได้แล้วครับ โดยให้ผู้ใช้งานสามารถ Clear Login ของตนเองได้แล้ว ทำตามดังนี้

1. Setup sudo

# cd /usr/ports/security/sudo
# make install clean

เลือกรายการ 1 และ 2 กดแท็บไปที่ OK กดปุ่ม Enter รอจนกว่าระบบจะติดตั้ง sudo เสร็จ



2. ปรับแต่งไฟล์ sudoers ใช้คำสั่งดังนี้



# echo 'www-data ALL=NOPASSWD: /bin/echo, /usr/bin/radclient' >> /usr/local/etc/sudoers
# echo 'www-data ALL=NOPASSWD: /usr/local/etc/rc.d/squid restart' >> /usr/local/etc/sudoers
# echo 'www-data ALL=NOPASSWD: /usr/local/sbin/squid -k reconfig' >> /usr/local/etc/sudoers

3. กำหนดสิทธิไฟล์ sudoers และ radiusd ใหม่

# chmod 777 /usr/local/etc/sudoers

# chmod 711 /usr/local/etc/raddb

# chmod 755 /usr/local/etc/raddb/dictionary

# rehash

4. เตรียมไฟล์ user_online.php และ kick.php ดาวโหลดจากเว็บไซต์ด้านล่าง

http://www.kroonis.org/Authen6.4/kick.rar (อับไฟล์ให้ใหม่ครับ)

จากนั้นให้ใช้โปรแกรม SSH โยนไฟล์ user_online.php และ kick.php

ไปไว้ที่ห้อง /usr/local/www/apache22/data/admin

5. เข้าเว็บ http://10.0.0.1/admin แล้วคลิกเมนู รายชื่อผู้ที่กำลังใช้งานอยู่ ให้คลิกรูป กากบาท ตรง user ที่ค้างในระบบ



เพียงเท่านี้ admin ก็สามารถเคลียร์ผู้ใช้งานที่ค้างในระบบโดยใช้ผ่านโปรแกรม ม.บูรพาได้แล้วครับ



6. กำหนดสิทธิ sudo ใหม่ดังนี้

# chmod 440 /usr/local/etc/sudoers

ถ้าต้องการให้ผู้ใช้งาน clear Login ตนเองได้ ทำตามดังนี้

1. เข้าเว็บ http://10.0.0.1/admin/kick.php

2. กรอกข้อมูลเข้าสู่ระบบให้ถูกต้อง แล้วคลิกปุ่ม clear user



3. ระบบจะรายงานว่าได้เคลียร์ข้อมูลผู้ใช้งานแล้ว สามารถ Login เพื่อเข้าสู่ระบบใหม่ได้



ขอขอบคุณ เพื่อน ๆ ที่ร่วมแลกเปลี่ยนประสบการณ์ ที่พัฒนาโปรแกรม kick user จากเว็บบอร์ด

ที่มา : http://www.linuxthai.org/forum/index.php?board=18.0

หลักการ clonefreebsd แบบคร่าว ๆ

หลักการ clone freebsd แบบคร่าว จากเวบไซด์ www.kroonis.org

1. Setup FreeBSD แบบ Express ใช้เวลาราว ๆ 2 นาที เร็วมาก ๆ

2. ให้บีบอัดห้องหลัก ๆ คือ usr var etc root boot home

โดยใช้คำสั่ง

# cd เข้าไปที่ห้องหลัก ๆ ก่อน เช่น cd /usr

# tar -cvf - * | gzip > /home/admin/usr.tar.gz

ทำแบบนี้ไปเรื่อย ๆ จนครบ ทุกห้องที่กล่าวมาแล้ว

จากนั้นก็ใช้โปรแกรม SSH ดึงไฟล์มาไว้ที่เครื่องของเรา

แล้วเขียน Shellscript ติดตั้ง EasyInstall123 ก็พร้อมใช้งานแล้วครับ ใช้เวลาโดยรวมแล้วไม่น่าจะเกิน 25 นาที



script"""ต้องปรับเอานะครับ..บางเครื่องอาจมีปัญหา
#!/bin/sh
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/usr/X11R6/bin:/root/bin
echo "#############################################################"
echo " Script Auto Install Authen and Log Server System By FreeBSDAuthen "
echo " www.kroonis.org "
echo " E-mail namo_nis@hotmail.com Setup Time 20 -30 Minute "
echo " ############################################################"
mkdir /home/admin/
cp /etc/fstab /cdrom/
cp /cdrom/usr.tar.gz /usr/
cp /cdrom/etc.tar.gz /etc/
cp /cdrom/var.tar.gz /var/
cp /cdrom/root.tar.gz /root/
cp /cdrom/boot.tar.gz /boot/
cp /cdrom/home.tar.gz /home/

cd /usr/
tar xvf usr.tar.gz
rm -rf usr.tar.gz
cd /etc/
tar xvf etc.tar.gz
rm -rf etc.tar.gz
cd /var/
tar xvf var.tar.gz
rm -rf var.tar.gz
cd /root/
tar xvf root.tar.gz
rm -rf root.tar.gz
cd /boot/
tar xvf boot.tar.gz
rm -rf boot.tar.gz
cd /home/
tar xvf home.tar.gz
rm -rf home.tar.gz

/usr/local/www/lightsquid/lightparser.pl
cp /home/admin/fstab /etc
chmod -R 777 /tmp
cp -R /cdrom/kroomanis /root
#bash /cdrom/kroomanis/netconfig.bash
echo " Install1 FreeBSD6.4 & Authen Finish By Manis Slangsingha Thank You "
reboot

หลักการ clonefreebsd แบบคร่าว ๆ

หลักการ clone freebsd แบบคร่าว จากเวบไซด์ www.kroonis.org

1. Setup FreeBSD แบบ Express ใช้เวลาราว ๆ 2 นาที เร็วมาก ๆ

2. ให้บีบอัดห้องหลัก ๆ คือ usr var etc root boot home

โดยใช้คำสั่ง

# cd เข้าไปที่ห้องหลัก ๆ ก่อน เช่น cd /usr

# tar -cvf - * | gzip > /home/admin/usr.tar.gz

ทำแบบนี้ไปเรื่อย ๆ จนครบ ทุกห้องที่กล่าวมาแล้ว

จากนั้นก็ใช้โปรแกรม SSH ดึงไฟล์มาไว้ที่เครื่องของเรา

แล้วเขียน Shellscript ติดตั้ง EasyInstall123 ก็พร้อมใช้งานแล้วครับ ใช้เวลาโดยรวมแล้วไม่น่าจะเกิน 25 นาที

วันอาทิตย์ที่ 13 มิถุนายน พ.ศ. 2553

ใช้ axel แทน fetch

TIPSจาก thaibsd.com
โปรแกรม axel เป็นเครื่องมือที่ใช้ในการ download file จาก URL ที่เราต้องการซึ่งจะเป็นโปรแกรมที่มีความเร็วมากกว่า wget , fetch หลายเท่าตัว หากเปรียบกับ Win ก็ประมาณ flashget และมีจุดเด่นคือ สามารถ download ต่อจากจุดที่ทำงานเสร็จก่อนหน้านี้ได้

cd /usr/ports/ftp/axel
make install
rehash

การใช้งาน axel

axel
edit /etc/make.conf

insert
FETCH_CMD = /usr/local/bin/axel

มันจะใช้ axel แทน fetch ไวเร็วดุจนรก

ผมใช้ prozilla อยู่ครับ ก็ดีเหมือนกัน
#cd /usr/ports/ftp/prozilla
#make; make install

การใช้งาน
#proz
ค่า default ตั้งไว้ที่ 4 connections หาก server รองรับการ resume

หรือ

#proz -k=n
กำหนดให้เพิ่มจำนวน connect ได้ เช่น -k=10

หากตั้งไว้หลัง proxy ที่มีการ authen ก็ไปแก้ไขไปได้ที่
/root/.prozilla/prozconfig

ทำให้ userไม่ใช้ตัวหนอนทำเวบได้

TIPS จากเวบไซด์ www.thaibsd.com/
แก้ไข httpd.conf ดังนี้

# pico /usr/local/etc/apache22/httpd.conf

กด Ctrl + w พิมพ์ DocumentRoot
เปลี่ยนเป็น

DocumentRoot "/home/"

ไปที่กลุ่มบรรทัด


AllowOverride None
Order deny,allow
Deny from all


แล้วเปลี่ยนใหม่เป็น


Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all


แทรกคำสั่ง


Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all


บันทึกไฟล์และออก

# /usr/local/sbin/apachectl restart


อ้างอิง::http://gotoknow.org/blog/tammarat/308437

วันเสาร์ที่ 5 มิถุนายน พ.ศ. 2553

mrtg บน centos


บทความจากเวบ linuxthai.org/forum โดย dbus
ทำตามนี้เลยครับ

# cd /root
# wget http://mytotoe.isgreat.org/files/mrtg-rhel.sh
# chmod 775 mrtg-rhel.sh
# sh ./mrtg-rhel.sh

พอติดตั้งเสร็จก็เข้า http://IP/mrtg
รอ 5 นาทีก่อนนะครับ ถึงกราฟจะขึ้น อันนี้วัดแบบ Physical นะครับ

proftpd บน centos

บทความโดย mr.gril

โดยปกติแล้ว CentOS จะไม่สามารถติดตั้ง proftpd ผ่านคำสั่ง yum ได้จำเป็นต้องติดตั้ง third-party yum repository เสียก่อน

1.) ติดตั้ง third-party yum repository ผมใช้ repository ของ securityteam.us นะครับ

# rpm -Uvh http://repo.securityteam.us/repository/redhat/securityteamus-repo-latest.rpm
# rpm --import http://repo.securityteam.us/repository/RPM-GPG-KEY


2.) ติดตั้ง ProFTPd

# yum install proftpd

หลังจากติดตั้งเสร็จแล้วไฟล์คอนฟิกของ ProFTPd จะอยู่ที่ /etc/proftpd.conf ซึ่งสามารถใช้ค่าปกตินี้ได้เลย


3.) หากบนเครื่องเซิร์ฟเวอร์มีโปรแกรมให้บริการ FTP ตัวอื่นเช่น vsFTPd ก็ควรหยุดการทำงานของโปรแกรมดังกล่าวเสียก่อนหรือถอนการติดตั้งเสียก่อน(หากไม่มีข้ามขั้นตอนนี้ไปได้เลย)

# yum remove vsftpd


4.) กำหนดให้ ProFTPd ทำงานทุกครั้งเมื่อเริ่มต้นระบบและเริ่มการทำงานของ ProFTPd

# chkconfig proftpd on
# /etc/init.d/proftpd start


5.) ทดสอบว่า ProFTPd ทำงานจริงหรือไม่

# netstat -pant | grep 21

tcp 0 0 :::21 :::* LISTEN 31150/proftpd: (acc

# ps aux | grep proftpd

nobody 31150 0.0 0.1 5068 1236 ? Ss 18:30 0:00 proftpd: (accepting connections)

# ftp localhost
Connected to localhost.localdomain.
220 FTP Server ready.
500 AUTH not understood
500 AUTH not understood
KERBEROS_V4 rejected as an authentication type
Name (localhost:root): webmaster << กรอกชื่อ user เข้าไป
331 Password required for webmaster
Password: << กรอกรหัสผ่าน
230 User webmaster logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> #แสดงว่า login ได้แล้ว

***หมายเหตุ กรณีที่เครื่องเซิร์ฟเวอร์อยู่หลังไฟล์วอล์หรือมีการเปิดการใช้งานไฟล์วอล์ เช่น iptables จำเป็นต้อง allow TCP port 21 ด้วย

ปรับ apache บน centos ให้รองรับภาษาไทย

บทความจาก http://totiz.exteen.com/20090512/apache

•สำหรับ Windows ให้เข้าไปที่ "C:\AppServ\Apache2.2\conf\httpd.conf"
•สำหรับ Linux/Unix ให้เข้าไปที่ "/etc/httpd/conf/httpd.conf" (Redhat)
•หลังจากเข้าไปแก้ไขดังนี้
- AddLanguage th .th
- LanguagePriority th en ...
- AddCharset TIS-620 .tis-620 .th

วันพุธที่ 26 พฤษภาคม พ.ศ. 2553

tip backup mysql ผ่าน command line

tip จาก อ.กิตติพงษ์ แห่ง thaibsd.com

เราสามารถใช้คำสั่งนี้ได้ครับ

mysqldump --all-databases > backup.sql -u root -pXXXXX
เมื่อ XXXXX คือรหัสผ่านครับ
ส่วน backup.sql คือ ชื่อไฟล์ที่ต้องการสำรอง
เพิ่มเติมโดย yim แห่ง thaibsd.com
แถม
mysqldump -uroot -pxxx syslog | gzip > syslog.tar.gz
บีบอัดไปในตัว
บางทีทำ crontab บีบไฟล์แล้วโยนไปที่ server อีกตัว ก็ได้

วันอาทิตย์ที่ 2 พฤษภาคม พ.ศ. 2553

freebsd บูตไม่ขึ้นไฟดับ

แนวทางแก้ไขไฟฟ้าดับบน freebsd บูตไม่ได้วิธีแก้ไขโดยพี่มะขาม...คุณพรมมาศ
# fsck -p
# mount -u /
# mount -a -t ufs

หาก fsck -p ไม่ผ่าน ลอง fsck -f ดูครับ
ท่าที่เคยทำ ไม่ได้เม้าหรอก ลุยเลย

# /sbin/adjkerntz -i
อาจจะไม่ได้เน้อ ตอนนี้ ผ่านไป ถ้ามันติด
# fsck_ufs /dev/da0s1a
ถ้าว่า root partition นั้นอยู่ที่ /dev/da0s1a น่ะ อย่ไปลบวาย (-y) ทนเอาครับ ทนทำเอา รึอยากจะใส่แต่ทีแรกเลย ก็ไม่ว่า

แล้วก็ไล่ทำไปทีละ partition น่ะ จนหมด

จากนั้นค่อยสั่งเม้าลบเอ mount -a แล้วก็ exit ไปสู่ multiuser mode

โชคดีน่ะ
อ้าว มาโพสไล่ๆกัน

จำไว้ เวลาอยู่ใน single user mode อย่าลบ

/etc/fstab ถ้าหาย ก็โชคร้ายแล้ว เว้นเสียแต่จะจำได้ว่า partition ไหน mount device อะไรไว้

ซึ่ง ถ้าจำได้ ก็ทำฟิ้สกี้ไป พอจบอย่างสะอาดแล้ว ก็ไล่ mount ไปทีละ partition ซะ แล้วก็เขียนแฟ้ม /etc/fstab ใหม่น่ะ

ถ้าลบ /etc/fstab ก็คงจะหมดทางที่จะบูตด้วยระบบเดิมครับ เพราะไฟล์นี้จะมีรายการ partition ทั้งหมด คงต้องบูตด้วยแผ่น live fs ครับ ไปที่เมนู Fix จะเข้าสู่ shell ได้ ทำการ mount partition แล้วคัดลอกข้อมูลออกมาครับ
โดยส่วนใหญ่จะชื่อ dev จะเป็นแบบนี้ครับ
/dev/ad0s1a
/dev/ad0s1d
/dev/ad0s1e
/dev/ad0s1f
บางเครื่องอาจไม่เหมืือนกันเป็น ad0, ad1, da0
พอจะสังเกตได้โดยใช้คำสั่ง ls /dev ครับ
ดาวน์โหลดแผ่น live fs
ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/ISO-IMAGES/8.0/8.0-RELEASE-i386-livefs.iso
บูตด้วยแผ่น live fs เลือก fix จนเข้า shell ได้
mount patition / โดย
# mount -t ufs /dev/ad0s1a /mnt
ตอนนี้ก็จะเข้า partition / ของระบบเดิมได้โดยจะอยู่ใน /mnt
ถ้าจำได้ว่า /home อยู่ partition ไหนก็ทำการ mount โดยใช้คำสั่งรูปแบบเีดียวกับ mount partition /
แล้วคัดลอกไฟล์ fstab ไปไว้ที่ /mnt/etc หรือจะสร้างใหม่ก็ได้ครับดูตัวอย่างจากเครื่องอื่นก็ได้ครับ เอาแค่ partition ที่จำเป็นก็พอ
วิธีค่อนข้างยุ่งยากครับ ผมอธิบายย่อ ๆ ไว้ก่อนครับ
อยู่บ้านรึ
ปกติ ถ้าพอจำได้ว่ามีแค่ /, /var, /usr, /home ละก็ มันจะอยู่ partition สุดท้ายแหละ f ไง

ลองดูน่ะ fsck_ufs /dev/da0s1f

ลำดับของมันจะแปลกๆ คือ /, /home, /usr, /var และ partition ที่อยู่จะเป็น a, f, e, d ตามลำดับ และ /etc/fstab เท่าที่ใช้ ก็เป็น

/dev/ad0s1b none swap sw 0 0
/dev/da0s1b none swap sw 0 0
/dev/ad0s1a / ufs rw 1 1
/dev/ad0s1f /home ufs rw 2 2
/dev/ad0s1e /usr ufs rw 2 2
/dev/ad0s1d /var ufs rw 2 2
/dev/da0s1d /kaitag ufs rw 2 2
/dev/acd0 /cdrom cd9660 ro,noauto 0 0

ดูยากหน่อยน่ะ เพราะที่นี่เขามีสวยๆกันไม่ได้ สวยๆ เป็นโดนเก็บไปหมดรึไงก็ไม่รู้แฮะ
นี่นี่ ในแฟ้ม /etc/fstab นั้น ลำดับที่ ๒ เป็น swap partition ที่ หาค่าเทอม ใช้เองน่ะ ปกติ มีแต่ swap partition แรกเท่านั้นระวังให้มากมาก

[~] % cat /etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/ad0s1b none swap sw 0 0
/dev/ad0s1a / ufs rw 1 1
/dev/ad0s1f /home ufs rw 2 2
/dev/ad0s1e /usr ufs rw 2 2
/dev/ad0s1d /var ufs rw 2 2
/dev/da0s1d /kaitag ufs rw 2 2
/dev/acd0 /cdrom cd9660 ro,noauto 0 0
proc /proc procfs rw 0 0

นั่นแหละ เอามาเถอะ คือ ปกติ คนเรามักจะทำอะไรซ้ำๆกันน่ะ เพราะฉะนั้น ลูกใหม่ที่ลงมา มันก็คงใช้ partition เดิมๆแหละ

ส่วน dmesg นั้นก็เพียงอยากทราบชื่อของ hard disk ลูกนั้นเท่านั้นเอง ไม่มีอะไรปิดบังกันหรอก เห็นบอกว่ามันเป็นลูกแรกไม่ใช่หรือ ดังนี้แล้ว unit number จะเป็น 0 และถ้าใช้ทั้งลูก slice number ก็คงเป็น 1

พอรู้ ก็เอามาประกอบได้เลย สังเคราะห์ได้เลย

/dev/XX0s1a คือ partition / ของ hard disk ที่ชื่อ XX

พอได้ก็สั่งฟิ้สกี้ได้เลย

fsck_ufs /dev/XX0s1a

แล้วก็ไล่ไปทีละ partition จาก d,e,f สำหรับ /var, /usr, /home เท่านั้นเอง

เดาเอาน่ะ ว่ามีเพียง usr, var , home

เฮ้อ
พอดี รายการทีวีช่องหนึ่งออกรายการให้ทารกมาร้องเพลงหาค่าเทอม มันมาออกรายการเอาตอนตอบ เลยใช้ชื่อว่า หาค่าเทอม
ความจริง ก็กำลังจะบอกว่า ให้ boot ด้วยแผ่นที่สามารถให้ระบบวิ่งได้ซะก่อน
จากนั้น สั่ง
# fsck_ufs /dev/da0s1g
# fsck_ufs /dev/da0s1a
จากนั้น ถ้า มันจบอย่างสะอาดน่ะ ให้สั่ง
# mount /dev/da0s1g /mnt
แล้วก็ ไปเอาแฟ้ม fstab ที่ว่า เอาไว้ที่ /home นั่นแหละ จด คัดลอกออกมา
แล้วก็ umount /mnt ซะ แล้วก็สั่ง
# mount /dev/da0s1a /mnt
แล้วถึงเรียก หรือสั่ง
# vi /mnt/etc/fstab
แล้วก็พิพม์ลงไป ข้อความที่ได้คัดลอกออกมาแล้วนั่นแหละ แล้วก็ save และ exit จาก vi ซะ
แล้วก็ reboot ด้วยก้อนแรก ก้อนที่เพิ่งเขียนแฟ้ม /etc/fstab ไปนี่แหละ ซึ่งน่าจะได้ และมาจบที่ single user mode ตามเดิม

แต่เมื่อ file system พัง ก็เป็นอันจบเห่กันพอดี
ยังไงก็ตามทีเหอะ น่ะ ขอให้โชคดี และสนุกกับ FreeBSD น่ะ

วันอาทิตย์ที่ 25 เมษายน พ.ศ. 2553

ลืมรหัส root บน centos

บทความจากคุณสกอร์เปี้ยน เวบ www.thaiadmin.org
ในกรณี ที่ท่านใช้ GRUB
1. ให้ทำการ Reboot เครื่อง
2. ถ้าท่านตั้ง password ใน GRUB ให้กด p แล้วใส่ Password (ถ้าไม่ได้ตั้ง password ของ GRUB ไว้ให้ทำการข้ามขั้นตอนนี้)
3. ให้เลือก Linux version ที่ท่านต้องการ boot (ในกรณีที่ท่าน ได้ลง linux หลายค่าย หรือ หลาย version )
4. กด e ( เพื่อเข้าไปทำการแก้ไข )
5. ให้กด ลูกศร เพื่อเลื่อนไป บรรทัดที่ขึ้น ต้นคำว่า "kernel" แล้ว พิมพ์ e อีก เพื่อทำการแก้ไข เช่น
kernal /vmlinuz-2.4.18.14 ro root=LABEL=/ hdc=ide-scsi

6. ให้เลื่อนไปท้าย สุด แล้ว กด Spacebar เพื่อเว้นวรรค แล้วพิมพ์ "single"
จากนั้นให้ กด Enter เพื่อสิ้นสุดการแก้ไข ตัวอย่าง
kernal /vmlinuz-2.4.18.14 ro root=LABEL=/ hdc=ide-scsi single

7. พิมพ์ b เพื่อ boot แบบ single mode
8. เมื่อ อยู่ ใน single mode ท่านอยู่ในสถานะของ root สามารถ แก้ไข password โดยการใช้คำสั่ง "passwd"
9. ทำการ reboot โดยใช้คำสั่ง "reboot" หรือ "shutdown -r now"


Password root ใช้ GRUB เป็นบูตโหลดเดอร์ ที่ง่ายกว่า
1. ให้ทำการ Reboot เครื่อง

2. เมื่อเครื่องถึงหน้าจอบูตโหลดเดอร์ของ Grub แล้วให้กด ปุ่ม A

3. ให้ไปท้ายคำสั่ง กด Spacebar เพื่อเว้นวรรค แล้วพิมพ์ "single" ต่อท้าย แล้วกด Enter

การเปลี่ยน Password ในกรณีที่ท่านใช้ LILO
1. ให้ทำการ Reboot เครื่อง
2. ถ้าอยู่ในรูปแบบ LILO boot Prompt ให้พิมพ์ "linux single"
แต่ถ้าอยู่ในรูปแบบ กราฟฟิค ให้ทำการกด Ctrl-x เพื่อออกจากรูปแบบกราฟฟิคก่อน แล้วพิมพ์ "linux single"
3. เมื่อ อยู่ ใน single mode ท่านอยู่ในสถานะของ root สามารถ แก้ไข password โดยการใช้คำสั่ง "passwd"
4. ทำการ reboot โดยใช้คำสั่ง "reboot" หรือ "shutdown -r now"

วันอังคารที่ 20 เมษายน พ.ศ. 2553

ความหมาย iptables

บทความจากคุณ upper แห่ง linuxthai.org/forum/

1:#iptables -A INPUT -s 192.168.1.0/24 -d 0/0 -p tcp --dport 21 --syn -j ACCEPT
2:#iptables -A INPUT -s 192.168.1.0/24 -d 0/0 -p tcp --dport 23 --syn -j ACCEPT
3:#iptables -A INPUT -s 0/0 -d 0/0 -t tcp --dport 25 --syn -j ACCEPT
4:#iptables -A INPUT -s 0/0 -d 0/0 -p tcp --dport 80 --syn -j ACCEPT
5:#iptables -A INPUT -s 192.168.1.0/24 -d 0/0 -p tcp --dport 110 --syn -j ACCEPT
6:#iptables -A INPUT -s 192.168.1.0/24 -d 0/0 -p tcp --dport 143 --syn -j ACCEPT
7:#iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -p tcp --dport 143 --syn -j ACCETP
8:#iptables -A INPUT -s 192.168.1.0/24 -d 0/0 -p tcp --dport 443 --syn -j ACCEPT
9:#iptables -A INPUT -s 0/0 -d 0/0 -p udp --dport 53 -j ACCEPT
10:#iptables -A INPUT -s 192.168.1.0/24 -d 0/0 -p udp --dport 4000 -j ACCEPT
11:#iptables -A INPUT -s 192.168.1.0/24 -d 0/0 -p tcp --dport 8080 --syn -j ACCEPT
12:#iptables -A INPUT -s 0/0 -d 0/0 -p tcp --dport 0:1023 --syn -j REJECT
13:#iptables -A INPUT -s 0/0 -d 0/0 -p tcp --dport 2049 --syn -j REJECT
14:#iptables -A INPUT -s 0/0 -d 0/0 -p udp --dport 0:1023 -j REJECT
15:#iptables -A INPUT -s 0/0 -d 0/0 -p udp --dport 2049 -j REJECT
16:#iptables -A INPUT -s 0/0 -d 0/0 -p tcp --dport 6000:6009 --syn -j REJECT
17:#iptables -A INPUT -s 0/0 -d 0/0 -p tcp --dport 7100 --syn -j REJECT

ความหมายแต่ละบรรทัด:
1.อนุญาตให้เครือข่ายภายใน ftp ไปยังปลายทางที่ไหนก็ได้
2.อนญาติให้เครือข่ายภายใน telnet ไปยังปลายทางที่ไหนก็ ได้
3.อนุญาตให้รับส่งเมล์ผ่าน smtp ได้ไม่ว่าจะเป็นต้นทางและปลายทางที่ไหน
4.อนุญาตให้ใช้เรียกใช้งาน เว็บได้ไม่ว่าจะเรียกจากที่ไหน และเรียกไปที่ไหนก็ได้
5.อนุญาตให้ mail client ของเครือข่ายภายในรับส่งเมล์ กับ mail server ที่ไหนก็ ได้ผ่าน POP3
6.อนุญาตให้ mail client ของเครือข่ายภายในรับส่งเมล์ กับ mail server ที่ไหนก็ ได้ผ่าน IMAP
7.อนุญาตให้ localhost สามารถใช้ imap ติดต่อกับ localhost ได้ เพื่อทำ webmail
8.อนุญาตให้เครือข่ายภายในใช้ https ได้
9.อนุญาตให้ใช้งาน DNS ได้ ไม่ว่าต้นทางและปลายทางอยู่ที่ไหน
10.อนุญาตให้เครือข่ายภายใน ใช้ ICQ ได้
11.ไม่ อนุญาตให้เครือข่ายที่นอกเหนือจากเครือข่ายภายในสามารถใช้งาน Proxy Server ได้
12.ไม่อนุญาตให้ใช้งาน tcp พอร์ต 0-1023 ไม่ว่าจะเป็นต้นทางและปลายทางที่ไหน
13.ไม่อนุญาตให้ใช้งาน tcp พอร์ต 2049 (NFS) ไม่ว่าจะเป็นต้นทางและปลายทาง ที่ไหน
14.ไม่อนุญาตให้ใช้งาน udp พอร์ต 0-1023 ไม่ว่าจะเป็นต้นทางและปลายทางที่ไหน
15.ไม่อนุญาตให้ใช้งาน udp พอร์ต 2049 (NFS) ไม่ว่าจะเป็นต้นทางและปลายทาง ที่ไหน
16.ไม่อนุญาตให้ใช้งาน tcp พอร์ต 6000-6009 (เป็น x11 สำหรับ X-windows) ไม่ว่าจะเป็นต้นทางและปลายทางที่ไหน
17.ไม่อนุญาตให้ใช้งาน tcp พอร์ต 7100 (X Font Service) ไม่ว่าจะเป็นต้นทางและปลายทางที่ไหน

วันเสาร์ที่ 17 เมษายน พ.ศ. 2553

tip จากเวบ รวมพลคนรัก freebsd

tip จากเวบรวมพลคนรัก freebsd
Tips Tips เปิด Ports ที่เราต้องการใช้งานในระบบปฏิบัติการ FreeBSD

ตัวอย่าง ต้องการเปิดใช้งาน Ports 8443 ใช้คำสั่งดังนี้

# ipfw add 250 allow tcp from any to any dst-port 8443

หรือ


# ipfw add 250 allow udp from any to any dst-port 8443





--------------------------------------------------------------------------------


#/etc/rc.conf

firewall_enable="YES"
firewall_type="OPEN"
firewall_script="/etc/ipfw.rules"
firewall_quite="YES"
firewall_logging="YES"

++++++++++++++++++

#/etc/ipfw.rules
cmd="ipfw -q add"
ipfw -q -f flush
$cmd 05 allow all from any to any via lo0
$cmd 10 deny all from any to 127.0.0.0/8
$cmd 15 deny all from 127.0.0.0/8 to any
$cmd 20 deny tcp from any to any frag
$cmd 25 check-state
$cmd 30 allow tcp from any to any established
$cmd 35 allow all from any to any out keep-state
$cmd 40 allow icmp from any to any
$cmd 45 allow udp from any to any 21 in keep-state
$cmd 46 allow tcp from any to any 21 in setup keep-state
$cmd 50 allow tcp from any to any 22 in setup keep-state
$cmd 55 allow tcp from any to any 25 in setup keep-state
$cmd 60 allow udp from any to any 53 in keep-state
$cmd 61 allow tcp from any to any 53 in setup keep-state
$cmd 65 allow tcp from any to any 80 in setup keep-state
$cmd 70 allow tcp from any to any 443 in setup keep-state
$cmd 75 allow tcp from any to any 110 in setup keep-state
$cmd 80 allow tcp from any to any 143 in setup keep-state
$cmd 85 allow tcp from any to any 8080 in setup keep-state
$cmd 500 pass all from any to me limit src-addr 2
$cmd 999 deny log all from any to any

อีก tip
The following rules go into /etc/ipfw.rules.

################ Start of IPFW rules file ################################ Flush out the list before we begin.ipfw -q -f flush# Set rules command prefixcmd="ipfw -q add"pif="dc0" # public interface name of NIC # facing the public Internet################################################################## No restrictions on Inside LAN Interface for private network# Not needed unless you have LAN.# Change xl0 to your LAN NIC interface name##################################################################$cmd 00005 allow all from any to any via xl0################################################################## No restrictions on Loopback Interface#################################################################$cmd 00010 allow all from any to any via lo0################################################################## Allow the packet through if it has previous been added to the# the "dynamic" rules table by a allow keep-state statement.#################################################################$cmd 00015 check-state################################################################## Interface facing Public Internet (Outbound Section)# Interrogate session start requests originating from behind the# firewall on the private network or from this gateway server# destine for the public Internet.################################################################## Allow out access to my ISP's Domain name server.# x.x.x.x must be the IP address of your ISP.s DNS# Dup these lines if your ISP has more than one DNS server# Get the IP addresses from /etc/resolv.conf file$cmd 00110 allow tcp from any to x.x.x.x 53 out via $pif setup keep-state$cmd 00111 allow udp from any to x.x.x.x 53 out via $pif keep-state# Allow out access to my ISP's DHCP server for cable/DSL configurations.# This rule is not needed for .user ppp. connection to the public Internet.# so you can delete this whole group.# Use the following rule and check log for IP address.# Then put IP address in commented out rule & delete first rule$cmd 00120 allow log udp from any to any 67 out via $pif keep-state#$cmd 00120 allow udp from any to x.x.x.x 67 out via $pif keep-state# Allow out non-secure standard www function$cmd 00200 allow tcp from any to any 80 out via $pif setup keep-state# Allow out secure www function https over TLS SSL$cmd 00220 allow tcp from any to any 443 out via $pif setup keep-state# Allow out send & get email function$cmd 00230 allow tcp from any to any 25 out via $pif setup keep-state$cmd 00231 allow tcp from any to any 110 out via $pif setup keep-state# Allow out FBSD (make install & CVSUP) functions# Basically give user root "GOD" privileges.$cmd 00240 allow tcp from me to any out via $pif setup keep-state uid root# Allow out ping$cmd 00250 allow icmp from any to any out via $pif keep-state# Allow out Time$cmd 00260 allow tcp from any to any 37 out via $pif setup keep-state# Allow out nntp news (i.e. news groups)$cmd 00270 allow tcp from any to any 119 out via $pif setup keep-state# Allow out secure FTP, Telnet, and SCP# This function is using SSH (secure shell)$cmd 00280 allow tcp from any to any 22 out via $pif setup keep-state# Allow out whois$cmd 00290 allow tcp from any to any 43 out via $pif setup keep-state# deny and log everything else that.s trying to get out.# This rule enforces the block all by default logic.$cmd 00299 deny log all from any to any out via $pif################################################################## Interface facing Public Internet (Inbound Section)# Check packets originating from the public Internet# destined for this gateway server or the private network.################################################################## Deny all inbound traffic from non-routable reserved address spaces$cmd 00300 deny all from 192.168.0.0/16 to any in via $pif #RFC 1918 private IP$cmd 00301 deny all from 172.16.0.0/12 to any in via $pif #RFC 1918 private IP$cmd 00302 deny all from 10.0.0.0/8 to any in via $pif #RFC 1918 private IP$cmd 00303 deny all from 127.0.0.0/8 to any in via $pif #loopback$cmd 00304 deny all from 0.0.0.0/8 to any in via $pif #loopback$cmd 00305 deny all from 169.254.0.0/16 to any in via $pif #DHCP auto-config$cmd 00306 deny all from 192.0.2.0/24 to any in via $pif #reserved for docs$cmd 00307 deny all from 204.152.64.0/23 to any in via $pif #Sun cluster interconnect$cmd 00308 deny all from 224.0.0.0/3 to any in via $pif #Class D & E multicast# Deny public pings$cmd 00310 deny icmp from any to any in via $pif# Deny ident$cmd 00315 deny tcp from any to any 113 in via $pif# Deny all Netbios service. 137=name, 138=datagram, 139=session# Netbios is MS/Windows sharing services.# Block MS/Windows hosts2 name server requests 81$cmd 00320 deny tcp from any to any 137 in via $pif$cmd 00321 deny tcp from any to any 138 in via $pif$cmd 00322 deny tcp from any to any 139 in via $pif$cmd 00323 deny tcp from any to any 81 in via $pif# Deny any late arriving packets$cmd 00330 deny all from any to any frag in via $pif# Deny ACK packets that did not match the dynamic rule table$cmd 00332 deny tcp from any to any established in via $pif# Allow traffic in from ISP's DHCP server. This rule must contain# the IP address of your ISP.s DHCP server as it.s the only# authorized source to send this packet type.# Only necessary for cable or DSL configurations.# This rule is not needed for .user ppp. type connection to# the public Internet. This is the same IP address you captured# and used in the outbound section.#$cmd 00360 allow udp from any to x.x.x.x 67 in via $pif keep-state# Allow in standard www function because I have apache server$cmd 00400 allow tcp from any to me 80 in via $pif setup limit src-addr 2# Allow in secure FTP, Telnet, and SCP from public Internet$cmd 00410 allow tcp from any to me 22 in via $pif setup limit src-addr 2# Allow in non-secure Telnet session from public Internet# labeled non-secure because ID & PW are passed over public# Internet as clear text.# Delete this sample group if you do not have telnet server enabled.$cmd 00420 allow tcp from any to me 23 in via $pif setup limit src-addr 2# Reject & Log all incoming connections from the outside$cmd 00499 deny log all from any to any in via $pif# Everything else is denied by default# deny and log all packets that fell through to see what they are$cmd 00999 deny log all from any to any################ End of IPFW rules file ###############################--------------------------------------------------------------------------------ลอง netstat -an |grep LIST ดูนะครับว่ามี listen port ไหนอยู่บ้าง

netstat -na|grep tcp ดูเครื่องตัวเองว่าเปิด port อะไรไว้

sockstat -4
อีก tips
http://gotoknow.org/blog/patrickz/18859
msql ให้เป็นภาษาไทย

วิธีแก้ให้เวบไม่ต้องมีตัวหนอนบน freebsd

บทความจากครูมานิส
แก้ไข httpd.conf ดังนี้

# pico /usr/local/etc/apache22/httpd.conf

กด Ctrl + w พิมพ์ DocumentRoot
เปลี่ยนเป็น

DocumentRoot "/home/"

ไปที่กลุ่มบรรทัด


AllowOverride None
Order deny,allow
Deny from all


แล้วเปลี่ยนใหม่เป็น


Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all


แทรกคำสั่ง


Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all


บันทึกไฟล์และออก

# /usr/local/sbin/apachectl restart

ลองเรียกเว็บ user ดูครับ เช่น

http://10.0.0.1/admin

ก็เรียกเว็บ user โดยไม่ต้องพิมพ์ http://10.0.0.1/~admin แล้วครับ และก็ไม่ต้องสร้างห้อง public_html ด้วย

ลองดูนะครับ สำหรับน้องใหม่ ที่กำลังหาคำตอบ

วันพุธที่ 24 มีนาคม พ.ศ. 2553

ไฟล์วอลล์บน freebsd ตั้งแต่ 6.4 เป็นต้นไป

บทความจาก san แห่งเวบ thaibsd

#kldload ipfw.ko

ค่าดีฟอล์คจะบล๊อคหมดทุกพอร์ต

ตั้งแต่เวอร์ชั่น 6.4 ขึ้นไปสามารถ โหลดที่ kernel ได้เลยไม่ต้องคอมไล์เคอร์แนลก็ได้ ให้ไปใส่ค่า
firewall_enable="YES" ที่ rc.conf

#ee /etc/rc.conf

#### FIREWALL #####
firewall_enable="YES"
#firewall_type="/etc/myrules.conf" -->เขียนกฏไฟล์วอล์เพื่อควบคุม เปิดและปิดพอร์ตเฉพาะที่จะใช้งาน
firewall_type="OPEN"
firewall_quiet="YES"
firewall_logging="YES"

#### NAT #####
natd_enable="YES"
natd_flags="-s -u -m"
natd_interface="interface to nat"

#myrules.conf
ipfw add 100 divert 8668 ip4 from any to any via "nat interface" <--- เปิด NAT
ipfw add 200 allow ip from any to any via lo0
ipfw add 300 deny ip from any to 127.0.0.0/8
ipfw add 400 deny ip from 127.0.0.0/8 to any

ipfw add 500 allow me to any 80 <--WEB
ipfw add 500 allow any to me 22 <--SSH

แก้ไขปัญหา apache ล้มโดยใช้ squid ช่วย

บทความของท่าน yim แห่งเวบไทยบีเอสดี...เกี่ยวกับการทำsquid ช่วย apache ป้องกันเวบล้ม
กรณีทีเว็บมีโหลดมาก ๆ เรามีวิธีการง่าย ๆ ในการลดโหลด apapche ไม่ให้ทำงานหนักจนเกินไปจนเว็บล่ม

ขั้นแรกลง squid ตามปกติ ผมเลือกใช้ squid 2.6.STABLE23

ทำการคอมพาย
cd squid-2.6.STABLE23
--prefix=/usr --exec_prefix=/usr --bindir=/usr/sbin --sbindir=/usr/sbin --libexecdir=/usr/lib/squid --sysconfdir=/etc/squid --localstatedir=/var/spool/squid --datadir=/usr/share/squid --enable-async-io --with-pthreads --enable-storeio=ufs,aufs,diskd,null --enable-removal-policies=lru,heap --enable-snmp --enable-htcp --enable-cache-digests --enable-referer-log --enable-auth=basic,digest,ntlm --enable-carp --enable-follow-x-forwarded-for --with-large-files --enable-useragent-log --enable-ipf-transparent

make
make all
make install

เสร็จแล้ว squid.conf จะอยู่ที่ /etc/squid/squid.conf
แก้เป็น

offline_mode on
http_port 8888 transparent
icp_port 3130

#============================================================$
# LOGFILE PATHNAMES AND CACHE DIRECTORIES
#============================================================$

cache_dir diskd /data/cache 300 128 128 Q1=72 Q2=64
cache_mem 100 MB
cache_replacement_policy heap LFUDA
memory_replacement_policy heap GDSF

logformat TLOG %{%d-%m-%Y %H:%M:%S}tl %6tr %>a %Ss/%03Hs %cache_access_log /var/log/squid/access.log TLOG
cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
pid_filename /tmp/squid.pid
logfile_rotate 2
debug_options ALL,1
buffered_logs off
emulate_httpd_log off

#============================================================$
# FTP section
#============================================================$
ftp_user anonymous
ftp_list_width 32
ftp_passive on
ftp_sanitycheck on




#===================================================================$
#DEFAULT ACL
#===================================================================$
acl all src 0.0.0.0/0.0.0.0
#acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.0/8
acl to_localhost dst 127.0.0.0/8
acl systemnetworkcare src 192.168.0.0/16 # RFC1918 possible internal network
acl reverse_tomcatapplication dst xxxxxx # แก้ xxx เป็น IPADDRESS SERVER
acl SSL_ports port 443 # https
acl SSL_ports port 563 # snews
acl SSL_ports port 873 # rsync
acl Safe_ports port 80 # http
acl Safe_ports port 81 # http
acl Safe_ports port 31 # http
acl Safe_ports port 32 # http
acl Safe_ports port 35 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl Safe_ports port 631 # cups
acl Safe_ports port 873 # rsync
acl Safe_ports port 901 # SWAT
acl SSL_ports port 8888 # https
acl CONNECT method CONNECT
acl SSL method CONNECT
miss_access allow all
http_access allow reverse_tomcatapplication
http_access allow all
miss_access allow reverse_tomcatapplication
http_reply_access allow all
never_direct allow SSL all
http_access allow all
http_access allow localhost
http_access allow to_localhost
http_access allow Safe_ports
http_access allow CONNECT SSL_ports
http_access allow systemnetworkcare
icp_access allow systemnetworkcare
icp_access allow all

acl QUERY urlpath_regex cgi-bin download files login member
cache deny QUERY
#============================================================$
# Parameter Administratif $
#============================================================$
cache_mgr admin@thaigqsoft.com
cache_effective_user nobody
cache_effective_group nobody
visible_hostname ICache
unique_hostname admin@thaigqsoft.com

#============================================================$
# SNMP
#============================================================$

quick_abort_min 0 KB
quick_abort_max 0 KB
quick_abort_pct 98
negative_ttl 3 minutes
positive_dns_ttl 53 seconds
negative_dns_ttl 29 seconds
forward_timeout 4 minutes
connect_timeout 2 minutes
peer_connect_timeout 1 minutes
pconn_timeout 120 seconds
shutdown_lifetime 10 seconds
read_timeout 15 minutes
client_lifetime 60 minutes
half_closed_clients off

อย่าลืมแก้ acl reverse_tomcatapplication dst xxxxxx เป็นไอพีเว็บ server

เสร็จแล้วใส่ ipfw
ipfw add 137 fwd 202.143.148.36,8888 tcp from any to 202.143.148.36 80 via fxp0
ipfw add 138 fwd 202.143.148.36,8888 tcp from 127.0.0.1 to any 80 via fxp0
ipfw add 139 fwd 202.143.148.36,80 tcp from any to 202.143.148.36 8888 via fxp0

fxp0 คือแลนที่แจกเว็บ
สามบรรทัดนี้จะกันไม่ให้คนอื่นมาแอบใช้ proxy เราโดยตรง
จบแล้วสั่งรัน squid
/usr/sbin/squid

ปล 202.143.148.36 คือไอพี เว็บ server

วันเสาร์ที่ 20 มีนาคม พ.ศ. 2553

ป้องกัน root ssh บน centos

บทความจากอินเตอร์เน็ตจำคนเขียนไม่ได้ขออภัยไม่ได้เอ่ยนามนะครับ..

วิธีการ Set SSH ไม่ให้ root login เข้ามา
วันนี้จะมาสอน security เบื้องต้นของ linux ฮับ

นั่นคือ การไม่ให้ Root Access เครื่องโดยตรง แต่ต้องผ่าน user คนอื่นก่อน

มาดูวิธีกันเลยดีกว่า

[root@valkyrie ~]# useradd
เพื่อสร้าง user ใหม่ครับ ใช้ในการที่เอาไว้ login ssh แทน root

[root@valkyrie ~]# passwd
ทีนี้ก็กำหนด Password ให้มันครับ (แนะนำให้คนละอันกับ root)

[root@valkyrie ~]# vi /etc/ssh/sshd_config
เข้าไปแก้ไข sshd_config ครับ
ตั้ง PermitRootLogin เป็น no
ซึ่งในตอนแรก มันจะปรับเป็น yes แล้ว comment ด้วย # ไว้ เอาออกด้วยนะครับ
แล้วเลื่อนลงมาล่างสุดครับ ให้พิมพ์บรรทัดนี้เพิ่มเข้าไป
AllowUsers
แล้ว save ไฟล์ ปิด ออกมานะครับ

ทีนี้ สั่ง service sshd restart เพื่อสั่งรี service sshd

ระหว่างนี้ ห้ามปิด SSH นี้ก่อนนะครับ เพราะเรายังไม่รู้ว่า config ที่เราใช้ มีปัญหาทำให้ login ไม่ได้หรือไม่
ถ้าไม่ทดสอบก่อน อาจจะต้องเดินไปแก้ไฟล์หน้าเครื่องได้นะครับ เพราะจะ ssh ไม่ได้อีกเลย
ดังนั้นให้เปิด terminal ssh เข้าไปยัง server อีกครั้งนะครับ แล้วลอง login ด้วย root ดู
จะพบว่า มัน login ไม่ได้
ให้ปิด terminal นั้นแล้วเปิด ssh ไปอีกหน้าหนึ่ง แล้วทดสอบ login ด้วย user ที่เราสร้างไปเมื่อตอนแรก
ถ้าได้ ก็ ok ครับ ฉลุย ผ่าน

ถ้าเราต้องการใช้สิทธิ Root
คือเนื่องจาก user ที่สร้างใหม่นั้น มันจะไม่มีสิทธิเทียบเท่า Root ดังนั้น วิธีการที่จะทำให้เราเข้าไปใน Root ได้ นั่นคือคำสั่ง
[newusers@valkyrie ~]$ su -
มันจะให้พิมพ์ password root เราก็พิมพ์ root

จบแล้วครับ ^^”

นี่ก็เป็น Security พื้นฐาน ในการทำ ssh นะครับ ลองๆเอาไปใช้ดูละกันครับ

วันศุกร์ที่ 19 มีนาคม พ.ศ. 2553

การแก้ไขระบบพังบน freebsd

บทความจาก mr.T แห่งเวบไทยบีเอสดี..ครับ
วันนี้เครื่อง server มีปัญหา ไม่สามารถใช้งานได้ เนื่องจากว่าไม่สามารถ Mount พาทิชั่นของระบบได้ ไปค้นหาวิธีแก้ ทำไปทำมาทำถูก เลยมาเขียนในกระทู้เพื่อเป็นแนวทางในการแก้ไขครับ
ระบบที่มีปัญหา
พอหลังจากที่รีบู๊ตแล้วจะเข้า single usr mode ซึ่งก็คือ
ระบบจะแจ้งประมาณดังนี้
Enter full pathname of shell or RETURN for /bin/sh:
พอเรากด Enter ระบบกดจะคืน Shell มาให้
#

เนื่องจากว่า / พาทิชั่นไม่สามารถ mount (/etc/fstab) ได้ จึงทำให้ไม่สามารถใช้คำสั่งใดๆ ได้ จากที่ค้นหาข้อมูลในเว็บบอร์ด มีเพียงคำแนะนำสั้นๆ

# mount -u / <---mount: not found
# mount -a <---mount: not found
#fsck -y
ระบบจะตอบกลับมาว่า mount: not found

จากในกรณีของผม
ที่ระบบตอบกลับมาว่าไม่เห็นคำสั่งนี้ เพราะ คำสั่ง mount อยู่ใน Path: /sbin/mount แต่เนื่องจากตอนนี้ระบบเราเสียหายไม่สามารถ mount พาทิชั่นใดๆได้ แม้แต่
Harddisk ที่ลงFreeBSDไว้ก็ถูกล๊อคเป็นแบบ Read Only
ls ดูจะเห็น เพียง / พาทิชั่น กับอีกพาทิชั่นนึง จำไม่ได้แล้ว จริงๆแล้ว / พาทิชั่นนี้ถูกโหลดจาก single user mode ซึ่งเป็นโหมดเอาไว้ Repair ระบบ มีคำสั่งที่จำเป็น
สำหรับใช้ Repair ระบบเท่านั้น ดังนั้น แนวทางแก้ไขคือ เราต้อง mount harddisk แบบแมนนวล

#cd /
#cd rescue <--ที่เก็บรวบรวมคำสั่งเอาไว้ Repair ระบบ
#/rescue/fsck -y /dev/ar0s1 <-- ให้ระบบมันซ่อมแซมตัวเองก่อน
#/rescue/mount /dev/ar0s1 <-- mount HDD ได้แล้ว
#/rescue/reboot

เสร็จแล้วครับ เราซ่อมแซมระบบเรียบร้อยแล้ว หลังจากรีบูต ระบบก็จะใช้งานได้ตามปรกติ

วันอังคารที่ 2 กุมภาพันธ์ พ.ศ. 2553


VDO การติดตั้ง freebsd ของอ.มานิส
http://www.doctorsawat.com/nisauthen/
บทความอ.กิตติพงษ์ แห่ง www.thaibsd.com

โปรแกรม axel เป็นเครื่องมือที่ใช้ในการ download file จาก URL ที่เราต้องการซึ่งจะเป็นโปรแกรมที่มีความเร็วมากกว่า wget , fetch หลายเท่าตัว หากเปรียบกับ Win ก็ประมาณ flashget และมีจุดเด่นคือ สามารถ download ต่อจากจุดที่ทำงานเสร็จก่อนหน้านี้ได้

cd /usr/ports/ftp/axel
make install
rehash

การใช้งาน axel

axel

edit /etc/make.conf

insert
FETCH_CMD = /usr/local/bin/axel

มันจะใช้ axel แทน fetch ไวเร็วดุจนรก