วันอังคารที่ 19 กรกฎาคม พ.ศ. 2554

ป้องกันการบุกรุก centos ด้วย denyhosts

บทความจากท่าน voip4share
ใช้ DenyHosts จับตายพวกชอบแอบ Login เข้า CentOS
โดย voip4share » 18 มี.ค. 2010 10:28

เคยลองดูข้อมูลในไฟล์ /var/log/secure มั๊ยครับ ไฟล์นี้จะเก็บข้อมูลทุกอย่างถ้ามีความพยายามจะล๊อกอินเข้าเครื่อง CentOS ด้วย Secure Shell ทั้งล๊อกอินสำเร็จและไม่สำเร็จ ลองดูตัวอย่างข้างล่างนี้ครับ

Mar 17 14:55:46 supercall sshd[4727]: Failed password for root from 218.207.158.7 port 46665 ssh2
Mar 17 14:55:46 supercall sshd[4728]: Received disconnect from 218.207.158.7: 11: Bye Bye
Mar 17 14:55:47 supercall sshd[4729]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=218.20

จะเห็นว่ามีคนพยายามที่จะล๊อกอินเข้ามาด้วย root มาจาก 218.207.158.7 ด้วย ssh2 ถ้าเราตั้งพาสเวอร์ด root ให้ง่ายต่อการเดาหล่ะก็ เสร็จเขาครับ เขาจะเข้ามาเป็น root และก็จะทำอะไรเครื่อง CentOS ของเราก็ได้ ก็ไม่จำเป็นว่าเขาจะพยายามเข้ามาเป็น root นะครับ เขาอาจจะพยายามล๊อกอินเข้ามาด้วยยูสเซอร์อะไรก็ได้

วิธีป้องกันที่ผมชอบใช้มีอยู่ 2 วิธีครับ คือ ปิดไม่ให้ใช้ root ล๊อกอินเข้าทาง SSH (ใช้ยูสเซอร์อื่นแทน แล้วใช้คำสั่ง su - root เมื่อต้องการเป็น root) และใช้โปรแกรม DenyHosts ล๊อกไอพีต้นทางไว้เลย ถ้าเข้ามาผิดเงื่อนไขก็จะเอาไอพีนั้นไปใส่ไว้ในไฟล์ /etc/hosts.deny ผลก็คือไอพีนั้นจะเข้ามาเครื่องเราไม่ได้อีก เราไม่ต้องทำเองครับโปรแกรม DenyHosts ทำให้

เว็บไซต์โปรแกรม DenyHosts
http://denyhosts.sourceforge.net

วิธีการติดตั้งและใช้งานโปรแกรม DenyHosts
โปรแกรม DenyHosts ใช้ Python ด้วยนะครับ มีให้ดาวน์โหลดทั้งแบบ RPM และ Source Code ถ้าเลือกแบบ RPM ต้องเช็คว่าในเครื่องเราติดตั้ง Python เวอร์ชั่นอะไรแล้วเลือกดาวน์โหลดให้ตรง เช็คเวอร์ชั่น Python

โค้ด: เลือกทั้งหมด
python -V

1. ดาวน์โหลด DenyHosts 2.6
สำหรับ Python 2.3

โค้ด: เลือกทั้งหมด
http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6-python2.3.noarch.rpm?use_mirror=nchc

สำหรับ Python 2.4

โค้ด: เลือกทั้งหมด
wget http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6-python2.4.noarch.rpm?use_mirror=nchc

สำหรับ Python 2.5

โค้ด: เลือกทั้งหมด
wget http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6-python2.5.rpm?use_mirror=nchc

และนี่สำหรับท่านที่จะสร้าง RPM เอง

โค้ด: เลือกทั้งหมด
wget http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6-1.src.rpm?use_mirror=nchc

และถ้าต้องการจะคอมไพล์เอง

โค้ด: เลือกทั้งหมด
wget http://downloads.sourceforge.net/project/denyhosts/denyhosts/2.6/DenyHosts-2.6.tar.gz?use_mirror=nchc

2. ติดตั้ง DenyHosts
เครื่องผมเป็น Python 2.4

โค้ด: เลือกทั้งหมด
rpm -ivh DenyHosts-2.6-python2.4.noarch.rpm

ไฟล์และไดเร็คตอรี่ที่เกี่ยวข้อง
ไฟล์ /usr/bin/denyhosts.py
ไดเร็คตอรี่ /usr/share/denyhosts

3. สร้างไฟล์คอนฟิก

โค้ด: เลือกทั้งหมด
cd /usr/share/denyhosts
cp denyhosts.cfg-dist denyhosts.cfg

ไฟล์ denyhosts.cfg เป็นไฟล์คอนฟิกของ DenyHosts ครับ รายละเอียดทั้งหมดผมขอยกไว้ไปอยู่ตอนท้ายบทความ

4. ทำให้ DenyHosts ทำงานในโหมด Daemon

โค้ด: เลือกทั้งหมด
cp daemon-control-dist daemon-controlแก้ไขบรรทัดต่อไปนี้ (ถ้าไฟล์เหล่านี้ไม่ได้อยู่ในตำแหน่งดีฟอลท์) ถ้าติดตั้งจาก RPM จะเป็นดีฟอลท์อยู่แล้วครับ จึงไม่ต้องแก้ไขอะไรในไฟล์นี้

DENYHOSTS_BIN = "/usr/bin/denyhosts.py"
DENYHOSTS_LOCK = "/var/lock/subsys/denyhosts"
DENYHOSTS_CFG = "/usr/share/denyhosts/denyhosts.cfg"
PYTHON_BIN = "/usr/bin/env python"

เปลี่ยน Onwer และ Permission

โค้ด: เลือกทั้งหมด
chown root daemon-control
chmod 700 daemon-control


5. ทดสอบรัน DenyHosts แบบ Daemon

โค้ด: เลือกทั้งหมด
./daemon-control start
ถ้ารันได้สำเร็จ จะมีข้อความแบบนี้
starting DenyHosts: /usr/bin/env python /usr/bin/denyhosts.py --daemon --config=/usr/share/denyhosts/denyhosts.cfg
โปรแกรมจะไปดูที่ไฟล์ /var/log/secure และจะเอารายชื่อ IP Address ที่พยายามจะล๊อกอินเข้า CentOS แต่ไม่สำเร็จไปไว้ในไฟล์ /etc/hosts.deny และไฟล์ /usr/share/denyhosts/data/hosts-restricted และจะมีไดเร็คตอรี่ /usr/share/denyhosts/data ถูกสร้างขึ้นมา
แสดงว่าเรารัน DenyHosts แบบ Daemon ได้

6. ทำให้ DenyHosts รันทุกครั้งที่เปิดเครื่อง

โค้ด: เลือกทั้งหมด
cd /etc/init.d
ln -s /usr/share/denyhosts/daemon-control denyhosts
chkconfig --level 35 denyhosts on


มารู้จักกับไฟล์ต่างๆในไดเร็คตอรี่ /usr/share/denyhosts/data และหน้าที่ของมัน
1. ไฟล์ hosts
เป็นรายชื่อ IP Address ที่พยายามล๊อกอินเข้ามาในวันที่และเวลาที่ระบุ ทั้งที่ล๊อกอินสำเร็จและไม่สำเร็จ
66.18.176.160:4:Thu Mar 18 10:20:00 2010
67.52.158.237:265:Thu Mar 18 10:19:59 2010

2. ไฟล์ hosts-restricted
เป็นรายชื่อ IP Address ที่ถูกนำไปใส่ไว้ในไฟล์ /etc/hosts.deny

3. ไฟล์ hosts-root
เป็นรายชื่อ IP Address ที่พยายามจะล๊อกอินเข้ามาด้วย root ดังตัวอย่าง
110.164.66.222:0:Thu Mar 18 10:20:00 2010
112.143.13.139:0:Thu Mar 18 10:19:58 2010
124.127.117.105:13:Thu Mar 18 10:19:58 2010
183.89.134.100:1:Thu Mar 18 10:20:00 2010

4. ไฟล์ hosts-valid
เป็นรายชื่อ IP Address ที่พยายามล๊อกอินเข้ามาด้วยยูสเซอร์ที่มีอยู่ในไฟล์ /etc/passwd รวมทั้งที่ล๊อกอินสำเร็จและไม่สำเร็จ
202.173.222.125:0:Thu Mar 18 10:20:00 2010
203.130.33.50:0:Thu Mar 18 10:20:00 2010
203.179.88.218:0:Thu Mar 18 10:20:00 2010
218.207.158.7:31:Thu Mar 18 10:20:00 2010

5. ไฟล์ offset
บันทึกการสตาร์ทของโปรแกรม sshd
Mar 17 05:25:10 supercall sshd[2842]: Server listening on :: port 22.2068379

6. ไฟล์ suspicious-logins

7. ไฟล์ users-hosts
เป็นรายชื่อยูสเซอร์ที่มีผู้พยายามสุ่มล๊อกอินเข้ามา พร้อมกับ IP Address เป็นยูสเซอร์ที่มีอยู่ในไฟล์ /etc/passwd ตัวอย่าง
mailnull - 67.52.158.237:1:Thu Mar 18 10:19:59 2010
news - 61.19.255.53:1:Thu Mar 18 10:20:00 2010
news - 67.52.158.237:1:Thu Mar 18 10:19:59 2010
nfsnobody - 67.52.158.237:1:Thu Mar 18 10:19:59 2010
nobody - 67.52.158.237:1:Thu Mar 18 10:19:59 2010
operator - 67.52.158.237:1:Thu Mar 18 10:19:59 2010
root - 124.127.117.105:13:Thu Mar 18 10:19:58 2010

8. ไฟล์ users-invalid
เป็นรายชื่อยูสเซอร์ที่มีผู้พยายามสุ่มล๊อกอินเข้ามา เป็นยูสเซอร์ที่ไม่มีอยู่ในระบบ คือไม่มีอยู่ในไฟล์ /etc/passwd ตัวอย่าง
ion:2:Thu Mar 18 10:19:59 2010
iraf:2:Thu Mar 18 10:20:00 2010
irc:2:Thu Mar 18 10:19:59 2010
iresha:2:Thu Mar 18 10:20:00 2010
irina:2:Thu Mar 18 10:19:59 2010

9. ไฟล์ users-valid
เป็นรายชื่อยูสเซอร์ที่มีผู้พยายามสุ่มล๊อกอินเข้ามา เป็นยูสเซอร์ที่มีอยู่ในไฟล์ /etc/passwd ตัวอย่าง
adm:1:Thu Mar 18 10:19:59 2010
apache:2:Thu Mar 18 10:20:00 2010
bin:2:Thu Mar 18 10:20:00 2010
daemon:1:Thu Mar 18 10:19:59 2010
ftp:21:Thu Mar 18 10:20:00 2010

ตัวอย่างข้อมูลในไฟล์ /etc/hosts.deny
ซึ่งถ้า CentOS พบว่า IP Address เหล่านี้พยายามจะใช้ SSH ล๊อกอินเข้ามาไม่ว่าจะด้วยยูสเซอร์อะไรก็ตาม มันจะ Reject ทันที และถ้าเราเปลี่ยนจาก sshd เป็น ALL (ตั้งในไฟล์ denyhosts.cfg ได้) ก็จะเข้าไม่ได้ทุกเซอร์วิสบน CentOS
sshd: 66.18.176.160
sshd: 67.52.158.237
sshd: 203.130.33.50

ไฟล์ allowed-hosts
ไฟล์นี้ดีฟอลท์ไม่มีอยู่ใน DenyHosts นะครับ แต่เราสร้างขึ้นมาได้ ข้อมูลในไฟล์นี้จะเป็น IP Address หรือ Network Address ที่ DenyHosts จะไม่เอาไปไว้ในไฟล์ /etc/hosts.deny ซึ่งหมายความว่าจะล๊อกอินผิดๆยังไงก็ได้ กี่ครั้งก็ได้

โค้ด: เลือกทั้งหมด
vi /usr/share/denyhosts/data/allowed-hosts
192.168.0.*
127.0.0.1
58.59.60.1


ไฟล์ restricted-usernames
ใส่ชื่อยูสเซอร์ที่ DenyHosts จะไม่ยอมให้ล๊อกอินเข้ามาในเครื่องเลย โดยเมื่อ DenyHosts พบว่ามีใครก็ตามที่พยายามล๊อกอินด้วยยูสเซอร์นี้ จะบล๊อก IP เลย

โค้ด: เลือกทั้งหมด
vi /usr/share/denyhosts/data/restricted-usernames

root
mysql
apache


ไฟล์คอนฟิก denyhosts.cfg

############ THESE SETTINGS ARE REQUIRED ############

#
# SECURE_LOG: the log file that contains sshd logging info if you are not sure, grep "sshd:" /var/log/*
#
# The file to process can be overridden with the --file command line argument
#
# Redhat or Fedora Core:
SECURE_LOG = /var/log/secure
#
# Mandrake, FreeBSD or OpenBSD:
#SECURE_LOG = /var/log/auth.log
#
# SuSE:
#SECURE_LOG = /var/log/messages
#
# Mac OS X (v10.4 or greater - also refer to: http://www.denyhosts.net/faq.html#macos
#SECURE_LOG = /private/var/log/asl.log
#
# Mac OS X (v10.3 or earlier):
#SECURE_LOG=/private/var/log/system.log
#

#
# HOSTS_DENY: the file which contains restricted host access information
#
# Most operating systems:
HOSTS_DENY = /etc/hosts.deny
#
# Some BSD (FreeBSD) Unixes:
#HOSTS_DENY = /etc/hosts.allow
#
# Another possibility (also see the next option):
#HOSTS_DENY = /etc/hosts.evil

#
# PURGE_DENY: removed HOSTS_DENY entries that are older than this time when DenyHosts is invoked with the --purge flag
#
# format is: i[dhwmy]
# Where 'i' is an integer (eg. 7)
# 'm' = minutes
# 'h' = hours
# 'd' = days
# 'w' = weeks
# 'y' = years
#
# never purge:
PURGE_DENY =
#
# purge entries older than 1 week
#PURGE_DENY = 1w
#
# purge entries older than 5 days
#PURGE_DENY = 5d

#
# PURGE_THRESHOLD: defines the maximum times a host will be purged. Once this value has been exceeded then this host will not be purged.
# Setting this parameter to 0 (the default) disables this feature.
# default: a denied host can be purged/re-added indefinitely
#PURGE_THRESHOLD = 0
#
# a denied host will be purged at most 2 times.
#PURGE_THRESHOLD = 2
#

#
# BLOCK_SERVICE: the service name that should be blocked in HOSTS_DENY
#
# man 5 hosts_access for details
#
# eg. sshd: 127.0.0.1 # will block sshd logins from 127.0.0.1
#
# To block all services for the offending host:
BLOCK_SERVICE = ALL
# To block only sshd:
#BLOCK_SERVICE = sshd
# To only record the offending host and nothing else (if using an auxilary file to list the hosts). Refer to:
# http://denyhosts.sourceforge.net/faq.html#aux
#BLOCK_SERVICE =
#
#
# DENY_THRESHOLD_INVALID: block each host after the number of failed login attempts has exceeded this value. This value applies to invalid
# user login attempts (eg. non-existent user accounts)
#
DENY_THRESHOLD_INVALID = 5
#

#
# DENY_THRESHOLD_VALID: block each host after the number of failed login attempts has exceeded this value. This value applies to valid
# user login attempts (eg. user accounts that exist in /etc/passwd) except for the "root" user
#
DENY_THRESHOLD_VALID = 10
#

#
# DENY_THRESHOLD_ROOT: block each host after the number of failed login attempts has exceeded this value. This value applies to
# "root" user login attempts only.
#
DENY_THRESHOLD_ROOT = 1
#

#
# DENY_THRESHOLD_RESTRICTED: block each host after the number of failed login attempts has exceeded this value. This value applies to
# usernames that appear in the WORK_DIR/restricted-usernames file only.
#
DENY_THRESHOLD_RESTRICTED = 1
#

#
# WORK_DIR: the path that DenyHosts will use for writing data to (it will be created if it does not already exist).
#
# Note: it is recommended that you use an absolute pathname for this value (eg. /home/foo/denyhosts/data)
#
WORK_DIR = /usr/share/denyhosts/data
#
#
# SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS
#
# SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES|NO
# If set to YES, if a suspicious login attempt results from an allowed-host then it is considered suspicious. If this is NO, then suspicious logins
# from allowed-hosts will not be reported. All suspicious logins from ip addresses that are not in allowed-hosts will always be reported.
#
SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES

#
# HOSTNAME_LOOKUP
#
# HOSTNAME_LOOKUP=YES|NO
# If set to YES, for each IP address that is reported by Denyhosts, the corresponding hostname will be looked up and reported as well (if available).
#
HOSTNAME_LOOKUP=YES
#

#
# LOCK_FILE
#
# LOCK_FILE=/path/denyhosts
# If this file exists when DenyHosts is run, then DenyHosts will exit immediately. Otherwise, this file will be created upon invocation
# and deleted upon exit. This ensures that only one instance is running at a time.
#
# Redhat/Fedora:
LOCK_FILE = /var/lock/subsys/denyhosts
#
# Debian
#LOCK_FILE = /var/run/denyhosts.pid
#
# Misc
#LOCK_FILE = /tmp/denyhosts.lock
#
######################################################################


############ THESE SETTINGS ARE OPTIONAL ############


#######################################################################
#
# ADMIN_EMAIL: if you would like to receive emails regarding newly restricted hosts and suspicious logins, set this address to
# match your email address. If you do not want to receive these reports leave this field blank (or run with the --noemail option)
#
# Multiple email addresses can be delimited by a comma, eg:
# ADMIN_EMAIL = foo@bar.com, bar@foo.com, etc@foobar.com
#
ADMIN_EMAIL = alert@voip4share.com
#

#
# SMTP_HOST and SMTP_PORT: if DenyHosts is configured to email reports (see ADMIN_EMAIL) then these settings specify the
# email server address (SMTP_HOST) and the server port (SMTP_PORT)
#
SMTP_HOST = localhost
SMTP_PORT = 25
#

#
# SMTP_USERNAME and SMTP_PASSWORD: set these parameters if your
# smtp email server requires authentication
#
#SMTP_USERNAME=foo
#SMTP_PASSWORD=bar
#

#
# SMTP_FROM: you can specify the "From:" address in messages sent from DenyHosts when it reports thwarted abuse attempts
#
SMTP_FROM = DenyHosts
#

#
# SMTP_SUBJECT: you can specify the "Subject:" of messages sent by DenyHosts when it reports thwarted abuse attempts
SMTP_SUBJECT = DenyHosts Report on 192.168.4.55
#

#
# SMTP_DATE_FORMAT: specifies the format used for the "Date:" header when sending email messages.
#
# for possible values for this parameter refer to: man strftime
#
# the default:
#
#SMTP_DATE_FORMAT = %a, %d %b %Y %H:%M:%S %z
#

#
# SYSLOG_REPORT
#
# SYSLOG_REPORT=YES|NO
# If set to yes, when denied hosts are recorded the report data will be sent to syslog (syslog must be present on your system).
# The default is: NO
#
#SYSLOG_REPORT=NO
#
#SYSLOG_REPORT=YES
#

#
# ALLOWED_HOSTS_HOSTNAME_LOOKUP
#
# ALLOWED_HOSTS_HOSTNAME_LOOKUP=YES|NO
# If set to YES, for each entry in the WORK_DIR/allowed-hosts file, the hostname will be looked up. If your versions of tcp_wrappers
# and sshd sometimes log hostnames in addition to ip addresses then you may wish to specify this option.
#
#ALLOWED_HOSTS_HOSTNAME_LOOKUP=NO
#

#
# AGE_RESET_VALID: Specifies the period of time between failed login attempts that, when exceeded will result in the failed count for
# this host to be reset to 0. This value applies to login attempts to all valid users (those within /etc/passwd) with the
# exception of root. If not defined, this count will never be reset.
#
# See the comments in the PURGE_DENY section (above) for details on specifying this value or for complete details
# refer to: http://denyhosts.sourceforge.net/faq.html#timespec
#
AGE_RESET_VALID=5d
#

#
# AGE_RESET_ROOT: Specifies the period of time between failed login attempts that, when exceeded will result in the failed count for
# this host to be reset to 0. This value applies to all login attempts to the "root" user account. If not defined,
# this count will never be reset.
#
# See the comments in the PURGE_DENY section (above) for details on specifying this value or for complete details
# refer to: http://denyhosts.sourceforge.net/faq.html#timespec
#
AGE_RESET_ROOT=25d
#

#
# AGE_RESET_RESTRICTED: Specifies the period of time between failed login attempts that, when exceeded will result in the failed count for
# this host to be reset to 0. This value applies to all login attempts to entries found in the WORK_DIR/restricted-usernames file.
# If not defined, the count will never be reset.
#
# See the comments in the PURGE_DENY section (above) for details on specifying this value or for complete details
# refer to: http://denyhosts.sourceforge.net/faq.html#timespec
#
AGE_RESET_RESTRICTED=25d
#
#
# AGE_RESET_INVALID: Specifies the period of time between failed login attempts that, when exceeded will result in the failed count for
# this host to be reset to 0. This value applies to login attempts made to any invalid username (those that do not appear
# in /etc/passwd). If not defined, count will never be reset.
#
# See the comments in the PURGE_DENY section (above) for details on specifying this value or for complete details
# refer to: http://denyhosts.sourceforge.net/faq.html#timespec
#
AGE_RESET_INVALID=10d
#

#
# RESET_ON_SUCCESS: If this parameter is set to "yes" then the failed count for the respective ip address will be reset to 0
# if the login is successful.
#
# The default is RESET_ON_SUCCESS = no
#
#RESET_ON_SUCCESS = yes
#

#
# PLUGIN_DENY: If set, this value should point to an executable program that will be invoked when a host is added to the
# HOSTS_DENY file. This executable will be passed the host that will be added as it's only argument.
#
#PLUGIN_DENY=/usr/bin/true
#

#
# PLUGIN_PURGE: If set, this value should point to an executable program that will be invoked when a host is removed from the
# HOSTS_DENY file. This executable will be passed the host that is to be purged as it's only argument.
#
#PLUGIN_PURGE=/usr/bin/true
#

#
# USERDEF_FAILED_ENTRY_REGEX: if set, this value should contain a regular expression that can be used to identify additional
# hackers for your particular ssh configuration. This functionality extends the built-in regular expressions that DenyHosts uses.
# This parameter can be specified multiple times.
# See this faq entry for more details: http://denyhosts.sf.net/faq.html#userdef_regex
#
#USERDEF_FAILED_ENTRY_REGEX=
#

######### THESE SETTINGS ARE SPECIFIC TO DAEMON MODE ##########

#
# DAEMON_LOG: when DenyHosts is run in daemon mode (--daemon flag) this is the logfile that DenyHosts uses to report it's status.
# To disable logging, leave blank. (default is: /var/log/denyhosts)
#
DAEMON_LOG = /var/log/denyhosts
#
# disable logging:
#DAEMON_LOG =
#

#
# DAEMON_LOG_TIME_FORMAT: when DenyHosts is run in daemon mode (--daemon flag) this specifies the timestamp format of
# the DAEMON_LOG messages (default is the ISO8061 format: ie. 2005-07-22 10:38:01,745)
#
# for possible values for this parameter refer to: man strftime
#
# Jan 1 13:05:59
#DAEMON_LOG_TIME_FORMAT = %b %d %H:%M:%S
#
# Jan 1 01:05:59
#DAEMON_LOG_TIME_FORMAT = %b %d %I:%M:%S
#

#
# DAEMON_LOG_MESSAGE_FORMAT: when DenyHosts is run in daemon mode (--daemon flag) this specifies the message format of each logged
# entry. By default the following format is used:
#
# %(asctime)s - %(name)-12s: %(levelname)-8s %(message)s
#
# Where the "%(asctime)s" portion is expanded to the format defined by DAEMON_LOG_TIME_FORMAT
#
# This string is passed to python's logging.Formatter contstuctor. For details on the possible format types please refer to:
# http://docs.python.org/lib/node357.html
#
# This is the default:
#DAEMON_LOG_MESSAGE_FORMAT = %(asctime)s - %(name)-12s: %(levelname)-8s %(message)s
#

#
# DAEMON_SLEEP: when DenyHosts is run in daemon mode (--daemon flag) this is the amount of time DenyHosts will sleep between polling
# the SECURE_LOG. See the comments in the PURGE_DENY section (above) for details on specifying this value or for complete details
# refer to: http://denyhosts.sourceforge.net/faq.html#timespec
#
#
DAEMON_SLEEP = 30s
#

#
# DAEMON_PURGE: How often should DenyHosts, when run in daemon mode, run the purge mechanism to expire old entries in HOSTS_DENY
# This has no effect if PURGE_DENY is blank.
#
DAEMON_PURGE = 1h
#

######### THESE SETTINGS ARE SPECIFIC TO ##########
######### DAEMON SYNCHRONIZATION ##########

#
# Synchronization mode allows the DenyHosts daemon the ability to periodically send and receive denied host data such that
# DenyHosts daemons worldwide can automatically inform one another regarding banned hosts. This mode is disabled by
# default, you must uncomment SYNC_SERVER to enable this mode.
#
# for more information, please refer to: http:/denyhosts.sourceforge.net/faq.html#sync
#

# SYNC_SERVER: The central server that communicates with DenyHost daemons. Currently, denyhosts.net is the only available server
# however, in the future, it may be possible for organizations to install their own server for internal network synchronization
#
# To disable synchronization (the default), do nothing.
#
# To enable synchronization, you must uncomment the following line:
#SYNC_SERVER = http://xmlrpc.denyhosts.net:9911
#

#
# SYNC_INTERVAL: the interval of time to perform synchronizations if SYNC_SERVER has been uncommented. The default is 1 hour.
#
#SYNC_INTERVAL = 1h
#

#
# SYNC_UPLOAD: allow your DenyHosts daemon to transmit hosts that have been denied? This option only applies if SYNC_SERVER has
# been uncommented. The default is SYNC_UPLOAD = yes
#
#SYNC_UPLOAD = no
#SYNC_UPLOAD = yes
#

#
# SYNC_DOWNLOAD: allow your DenyHosts daemon to receive hosts that have been denied by others? This option only applies if SYNC_SERVER
# has been uncommented. The default is SYNC_DOWNLOAD = yes
#
#SYNC_DOWNLOAD = no
#SYNC_DOWNLOAD = yes
#

#
# SYNC_DOWNLOAD_THRESHOLD: If SYNC_DOWNLOAD is enabled this parameter filters the returned hosts to those that have been blocked this many
# times by others. That is, if set to 1, then if a single DenyHosts server has denied an ip address then you will receive the denied host.
#
# See also SYNC_DOWNLOAD_RESILIENCY
#
#SYNC_DOWNLOAD_THRESHOLD = 10
#
# The default is SYNC_DOWNLOAD_THRESHOLD = 3
#
#SYNC_DOWNLOAD_THRESHOLD = 3
#

#
# SYNC_DOWNLOAD_RESILIENCY: If SYNC_DOWNLOAD is enabled then the value specified for this option limits the downloaded data
# to this resiliency period or greater.
#
# Resiliency is defined as the timespan between a hackers first known attack and it's most recent attack. Example:
#
# If the centralized denyhosts.net server records an attack at 2 PM and then again at 5 PM, specifying a SYNC_DOWNLOAD_RESILIENCY = 4h
# will not download this ip address.
#
# However, if the attacker is recorded again at 6:15 PM then the ip address will be downloaded by your DenyHosts instance.
#
# This value is used in conjunction with the SYNC_DOWNLOAD_THRESHOLD and only hosts that satisfy both values will be downloaded.
# This value has no effect if SYNC_DOWNLOAD_THRESHOLD = 1
#
# The default is SYNC_DOWNLOAD_RESILIENCY = 5h (5 hours)
#
# Only obtain hackers that have been at it for 2 days or more:
#SYNC_DOWNLOAD_RESILIENCY = 2d
#
# Only obtain hackers that have been at it for 5 hours or more:
#SYNC_DOWNLOAD_RESILIENCY = 5h
#

เทคนิคการลบ IP Address ที่ถูก Block
ถ้าจะลบ IP ที่ถูกบล๊อกออก ต้องลบออกจากหลายไฟล์ครับ เพื่อไม่ให้มันกลับมาอยู่ใน /etc/hosts.deny อีกแม้ว่าจะล๊อกอินถูกแล้วก็ตาม
1. หยุดการทำงานของ DenyHosts

โค้ด: เลือกทั้งหมด
service denyhosts stop
2. ลบบรรทัด IP Address นั้นออกจากไฟล์ /etc/hosts.deny
3. ลบบรรทัด IP Address นั้นออกจากไฟล์ /usr/share/denyhosts/data/hosts
4. ลบบรรทัด IP Address นั้นออกจากไฟล์ /usr/share/denyhosts/data/hosts-restricted
5. ลบบรรทัด IP Address นั้นออกจากไฟล์ /usr/share/denyhosts/data/hosts-root
6. ลบบรรทัด IP Address นั้นออกจากไฟล์ /usr/share/denyhosts/data/hosts-valid
7. ลบบรรทัด IP Address นั้นออกจากไฟล์ /usr/share/denyhosts/data/user-hosts
8. (ออปชั่น) เพิ่ม IP Address นั้นในไฟล์ /usr/share/denyhosts/data/allowed-hosts
9. สตาร์ท DenyHosts

โค้ด: เลือกทั้งหมด
service denyhosts startvoip4share
Administrator

โพสต์: 689
ลงทะเบียนเมื่อ: 18 พ.ย. 2009 11:26
ที่อยู่: รามคำแหง กรุงเทพฯ
เว็บไซต์ ข้างบน
--------------------------------------------------------------------------------
ตอบกระทู้1 โพสต์ • หน้า 1 จากทั้งหมด 1

ย้อนกลับไปยัง CentOS - The Community Enterprise Operating System
ไปที่: เลือกบอร์ด ------------------ ประกาศจากเว็บบอร์ด การสมัครสมาชิกเว็บบอร์ด พื้นฐานเกี่ยวกับ VoIP Elastix - Unified Communications Software Asterisk SIP Server PHPAGI - Where PHP Connects To Asterisk A2Billing - Calling Card & Billing Application CentOS - The Community Enterprise Operating System AstBill - Billing, Routing and Management for Asterisk and VoIP VOS3000 - SIP/H.323 High Performance Soft Switch OpenSIPS - Reliable and High-Performance SIP Server คุณสมบัติของโปรแกรม VoipSwitch - Affordable Communication Solutions สินค้ารุ่นใหม่ Gateway / ATA / WiFi ATA IP PBX GSM VoIP ผลิตภัณฑ์รุ่นใหม่ สินค้ารุ่นใหม่ สินค้ารุ่นใหม่ IP Phone Gateway / ATA สินค้ารุ่นใหม่ สินค้ารุ่นใหม่ SoftPhone โปรแกรมบน Windows โปรแกรมบน Mac OS โปรแกรมบน Linux โปรแกรมบน Symbian OS โปรแกรมบน Windows Mobile โปรแกรมบน Smartphone โปรแกรมบน Android ซื้อ-ขาย-แลกเปลี่ยน ตัวแทนจำหน่ายสินค้า กระทู้ทั่วไป - ฝากคำถาม ข่าวน่าสนใจ - งานประชาสัมพันธ์
ผู้ใช้งานขณะนี้
กำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และ บุคคลทั่วไป 3 ท่าน

หน้าเว็บบอร์ด ทีมงาน • ลบ Cookies • ไทม์โซน GMT + 7 ชั่วโมง

© 2009 VoIP4Share
ภาษาไทยโดย Mindphp.com และ phpBBThailand.com
phpBB SEO

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

tip การรักษาความปลอดภัยบน centos

Tip : การรักษาความปลอดภัย โดยปิด Service ที่ไม่ได้ใช้งาน บน CentOS สำหรับ Gateway อย่างเดียว
จากท่าน ton-or""""
Ton-Or — 26 September, 2009 - 11:41
กรณีที่เราไม่ได้ใช้งานด้านอื่นๆ เช่น mail server เน้นนำมาใช้เป็น gateway ต่อ ADSL ของเราอย่างเดียวนั้น Srevice หลายๆตัวที่ run อยู่ ไม่จำเป็นต้องใช้มาปิด Service พวกนั้นกัน
ตรวจสอบ Service ทั้งหมดที่เปิดอยู่ก่อน
chkconfig –list | grep on
จะได้ประมาณนี้
atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
messagebus 0:off 1:off 2:off 3:on 4:on 5:on 6:off
smartd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
portmap 0:off 1:off 2:off 3:on 4:on 5:on 6:off
sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netfs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
cups 0:off 1:off 2:on 3:on 4:on 5:on 6:off
irqbalance 0:off 1:off 2:off 3:on 4:on 5:on 6:off
rpcgssd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
xfs 0:off 1:off 2:on 3:on 4:on 5:on 6:off
isdn 0:off 1:off 2:on 3:on 4:on 5:on 6:off
autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off
gpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off
apmd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
acpid 0:off 1:off 2:off 3:on 4:on 5:on 6:off
microcode_ctl 0:off 1:off 2:on 3:on 4:on 5:on 6:off
pcmcia 0:off 1:off 2:on 3:on 4:on 5:on 6:off
cpuspeed 0:off 1:on 2:on 3:on 4:on 5:on 6:off
xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
rpcidmapd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
readahead_early 0:off 1:off 2:off 3:off 4:off 5:on 6:off
readahead 0:off 1:off 2:off 3:off 4:off 5:on 6:off
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
anacron 0:off 1:off 2:on 3:on 4:on 5:on 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
kudzu 0:off 1:off 2:off 3:on 4:on 5:on 6:off
syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
nfslock 0:off 1:off 2:off 3:on 4:on 5:on 6:off
rawdevices 0:off 1:off 2:off 3:on 4:on 5:on 6:off
mdmonitor 0:off 1:off 2:on 3:on 4:on 5:on 6:off
haldaemon 0:off 1:off 2:off 3:on 4:on 5:on 6:off
ลอกเขามาเลยแล้วกัน

/sbin/chkconfig --level 0123456 portmap off
/sbin/chkconfig --level 0123456 nfslock off
/sbin/chkconfig --level 0123456 netfs off
/sbin/chkconfig --level 0123456 rpcgssd off
/sbin/chkconfig --level 0123456 rpcidmapd off
/sbin/chkconfig --level 0123456 autofs off
/sbin/chkconfig --level 0123456 sendmail off
/sbin/chkconfig --level 0123456 cups off
/sbin/chkconfig --level 0123456 xfs off
/sbin/chkconfig --level 0123456 isdn off
/sbin/chkconfig --level 0123456 pcmcia off

อ้างอิง
http://prefetch.net/blog/index.php/2006/12/27/securing-centos-installations-by-disabling-unneeded-services/
linux - cafedevel - News
1910 reads

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

เข้าหน้า login ต้องคลิ๊กหลายครั้งวิธีแก้ไข

แก้ปัญหา user ต้อง Login 2 ครั้งจึงจะเข้าสู่ระบบได้

พบคำตอบแล้วครับ ปัญหา user ต้อง Login 2 ครั้งจึงเข้าสู่ระบบได้ เป็นที่ไฟล์ radiusd.conf ศึกษาวิธีแก้ปัญหาจากบทความนี้

# nano /etc/raddb/radiusd.conf

กดปุ่ม Ctrl + w แล้วพิมพ์ cleanup_delay = 5 กดปุ่ม Enter

โปรแกรมจะวิ่งไปที่บรรทัด cleanup_deay = 5 ให้แก้ไขใหม่เป็น cleanup_deay = 0

บันทึกไฟล์ กดปุ่ม Ctrl + o ตามด้วยปุ่ม Enter ออกจากการแก้ไข กดปุ่ม Ctrl + x

สั่งให้ radiusd ทำงานใหม่ด้วยคำสั่ง

# /etc/init.d/radiusd restart
หรือ
# service radiusd restart

แหล่งข้อมูลจาก
http://www.kroonis.org/index.php?name=authen&file=readauthen&id=13

วันเสาร์ที่ 26 กุมภาพันธ์ พ.ศ. 2554

กรณี error เกี่ยวกับ auto tool ทุกตัว

In /usr/ports/www/apache22/Makefile, replace

Code:
USE_AUTOTOOLS= autoconf:267 libtool:22with

Code:
USE_AUTOTOOLS= autoconf libtool

ตัวโปรแกรมอื่น ๆ เช่นกันเช่น proftp หรือ php5

วันศุกร์ที่ 25 กุมภาพันธ์ พ.ศ. 2554

วิธีโม squid จากเวบ linuxthai

บทความจากเวบ linuxthai.org/forum คุณFAK-MUW
http_port 3128 transparent no-connection-auth
tcp_outgoing_address 0.0.0.0
udp_incoming_address 0.0.0.0
udp_outgoing_address 0.0.0.0
icp_port 0

# Time Out
request_timeout 5 minutes
forward_timeout 5 minutes
connect_timeout 5 minutes
peer_connect_timeout 1 minutes
pconn_timeout 120 seconds
read_timeout 15 minutes
request_timeout 5 minutes
persistent_request_timeout 2 minute
shutdown_lifetime 5 seconds
negative_ttl 2 minutes
negative_ttl 3 minutes
positive_dns_ttl 120 seconds
negative_dns_ttl 120 seconds

netdb_low 900
netdb_high 1000
client_db on
client_lifetime 1 day

# mark for no cache
hierarchy_stoplist cgi-bin ? localhost .asp .aspx .php .inf .dll .Xt .xtp .ini localhost php$ inf$ dll$ Xt$ xtp$ ini$ asp$ aspx$ patch_lv1
acl QUERY urlpath_regex cgi-bin \? localhost .asp .aspx .php .inf .dll .Xt .xtp .ini .exe localhost php$ inf$ dll$ Xt$ xtp$ ini$ asp$ aspx$ updatelist$ patch_lv1
cache deny QUERY

# OPTIONS WHICH AFFECT THE CACHE SIZE
# -----------------------------------
#---- ËÒÃ 3
cache_mem 1536 MB
cache_swap_low 90
cache_swap_high 95
memory_pools on
memory_pools_limit 512 MB

maximum_object_size 256 MB
maximum_object_size_in_memory 1024 KB

ipcache_size 4096
ipcache_low 90
ipcache_high 95
fqdncache_size 4096

cache_replacement_policy heap LFUDA
memory_replacement_policy heap GDSF

# LOGFILE
# -------------------------------------
#cache_dir aufs /data/squid 20480 24 256
cache_dir ufs /var/spool/squid 9000 16 256

cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log none
# mime_table /usr/share/squid/mime.conf
pid_filename /var/run/squid.pid

log_fqdn off
client_netmask 255.255.255.255
ftp_passive on
ftp_sanitycheck on
#DNS ¢Í§SERVER
dns_nameservers 127.0.0.1 203.146.237.237 203.146.237.222

# OPTIONS FOR TUNING THE CACHE
# --------------------------------------
# refresh_pattern ^ftp: 10080 95% 241920 reload-into-ims override-lastmod
# refresh_pattern . 180 95% 120960 reload-into-ims override-lastmod

refresh_pattern -i \.*$ 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload

refresh_pattern -i ^https://*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^https://*.in.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^https://www.*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^https://www.*.in.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.co.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*.*-*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*-*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*-*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*-*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*.*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*.*-*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*-*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*-*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*-*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*.*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.co.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.in.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.gg.in.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.org 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.co.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.in.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.org 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.*.*.*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.*.*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.com 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.*.*.*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.*.*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.net 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.co.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.in.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.org 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.*.co.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.*.in.th 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://www.*.*.org 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload

refresh_pattern -i ^http://*.*.*.*.*-* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*.*-* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*-* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*-* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*-* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*.*.* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.*.* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.*.* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://*.* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i ^http://* 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload

refresh_pattern -i .(gif|tif|tiff|jpeg|xbm|png|wrl|ico|pnm|pbm|pgm|ppm|rgb|xpm|xwd|pic|pict|bmp|jpg|jpe)$ 0 25000% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i .(arj|sit|zip|rar|rgz|cfg|rtf|psf|hqx|exe|lzh|lha|cab|tar|tgz|gz|Z|wp|wp5|ps|prn|srf|pdf|tex|latax|txt|doc|ppt|gpf|upd|iso|jar|bz2|uue|gzip|ace|cab|kf|a[0-9][0-9]|r[0-9][0-9])$ 0 100% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i .(midi|wav|aif|aiff|au|ram|ra|snd|mid|mp2|mp3|mp4|mov|mpg|mpeg|mpe|avi|qt|qtm|viv)$ 0 120% 1440 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern -i .(swf)$ 525960 18000% 525960 override-lastmod override-expire reload-into-ims ignore-reload
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern . 0 20% 4320 reload-into-ims
refresh_pattern -i \\.flv$ 10080 90% 999999 ignore-no-cache override-expire ignore-private

quick_abort_min 0 KB
quick_abort_max 0 KB
quick_abort_pct 100

half_closed_clients off

# ACL CONTROLS
# ---------------------------------------------------------------
acl virus_nimda urlpath_regex -i .*/system32/cmd\.exe.*
acl virus_nimda2 urlpath_regex -i .*/winnt/system32/cmd.exe.*
acl virus_nimda2 urlpath_regex -i .*/MSADC/root.exe..c.dir$
acl virus_nimda2 urlpath_regex -i .*/scripts/root.exe..c.dir$
acl virus_nimda2 urlpath_regex -i .*/appie.exe
acl virus_nimda2 urlpath_regex -i .*/app.exe

acl Manager proto cache_object
acl all src 0.0.0.0/0
acl localhost src 127.0.0.1/32
acl our_networks src 10.0.0.0/8 172.16.0.0/12 192.168.0.0/16
acl All_Port port 1-65535
acl CONNECT method CONNECT
acl blockweb dst 208.73.212.0/24

acl bitword urlpath_regex \.torrent\*?$
acl bittorrent_announce url_regex -i http://.+announce.+info_hash= #announce.php?passkey

##############################
# Limited file download < 128 MB ´ÒǹìâËÅ´äÁèà¡Ô¹ 128 M
# reply_body_max_size SizeInByte deny|allow acl
reply_body_max_size 134217728 deny our_networks
request_body_max_size 128 MB
##############################

http_access deny virus_nimda
http_access deny virus_nimda2
http_access deny bitword
http_access deny bittorrent_announce
http_access deny blockweb

http_access allow Manager all
http_access deny Manager
http_access allow All_Port
http_access allow CONNECT All_Port
http_access allow localhost
http_access allow our_networks
http_access deny all

http_reply_access allow all
icp_access allow all

# ADMINISTRATIVE PARAMETERS
# ------------------------------

cache_mgr squid@localhost
visible_hostname cache.hadyaiinternet.com

# MISCELLANEOUS
# -------------------------------
logfile_rotate 3
log_icp_queries off
query_icmp off
buffered_logs off
reload_into_ims on
nonhierarchical_direct off
prefer_direct on
strip_query_terms off
pipeline_prefetch on
ie_refresh on
forwarded_for on
vary_ignore_expire on
store_dir_select_algorithm round-robin
ignore_unknown_nameservers on

header_access Allow allow all
header_access Authorization allow all
header_access Cache-Control allow all
header_access Content-Encoding allow all
header_access Content-Length allow all
header_access Content-Type allow all
header_access Date allow all
header_access Expires allow all
header_access Host allow all
header_access If-Modified-Since allow all
header_access Last-Modified allow all
header_access Location allow all
header_access Pragma allow all
header_access Accept allow all
header_access Accept-Charset allow all
header_access Accept-Encoding allow all
header_access Accept-Language allow all
header_access Content-Language allow all
header_access Mime-Version allow all
header_access Retry-After allow all
header_access Title allow all
header_access Connection allow all
header_access Proxy-Connection allow all
header_access All allow all

อบรม advance network




23 - 24 กุมภาพันธ์ 2554 ไปอบรมเรื่องการวิเคราะห์เครือข่ายขั้นสูง ใช้ packet tracer cisco อบรมสนุกดี..แต่อบรมเวลาน้อยไปหน่อย..เสียดายวิทยากรเก่ง ๆ กำลังมัน...จบซะแล้ว..

วันศุกร์ที่ 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 ไวเร็วดุจนรก

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

คำสั่งติดตั้ง ntop

บทความ โดย itdekd แห่งเวบไซด์ freebsd
ntop คือ เครื่องมือที่ใช้ในการมอนิเตอร์และแก้ปัญหาระบบเครือข่าย สามารถวิเคราะห์ปัญหาของทราฟฟิกที่ช้าลงได้ ว่าเกิดจากสาเหตุใดโดยจะแสดงผลผ่านบราวเซอร์ ( ผมว่าคล้ายๆ MTRG แต่ผมว่าดีกว่าน่ะ ในความคิดเห็นของผมน่ะ )

วิธีการติดตั้ง ( ห้าม อัพเดท ports น่ะ ไม่งั้นมันจะ error ไม่รู้ว่าเป็นอ่ะไรเหมือนกัน แก้ไม่หายด้วยอ่ะ ถ้าใครรู้ว่าแก้ยังไงก็บอกด้วยล่ะกัน)

ขั้นแรกติดตั้ง GD ก่อน
# cd /usr/ports/graphics/gd
# make WITH_XPM=yes install clean

ขั้นที่สองติดตั้ง ntop
# cd /usr/ports/net/ntop && make install clean
รอประมาณ 1ชั่วโมง

คำสั้งรัน ntop
# chmod 555 /usr/local/etc/rc.d/ntop

ทำการเซตอัพ Admin password
# /usr/local/bin/ntop -u nobody -A

ทำการสั่งรัน ntop ผ่านเชล์สคริปต์
#/usr/local/etc/rc.d/ntop start

แก้ไขไฟล์ rc.conf
เพิ่มคำสั้ง ntop_enable="YES"

แล้ว reboot เครื่อง

การใช้งาน
http://xxx.xxx.xx.xx:3000(xxx.xxx.xx.xx คือไอพี หรือชื่อเว็บน่ะครับ ) ถ้าไม่ได้ยังไงถามได้น่ะครับ กว่าจะได้ 1 อาทิตย์ เต็มๆๆ

บน linux ก็ตามนี้ครับ
http://www.msit.mut.ac.th/newweb/phpfile/show.php?Qid=4936

วันศุกร์ที่ 18 กันยายน พ.ศ. 2552

แก้ยูเซอร์ค้างในระบบอย่างถาวร..จากเวบ linuxthai.org

เครดิตท่าน koko2330 แห่งเวบ www.linuxthai.org
vi /usr/local/etc/radiusd.conf
บรรทัดที่ ~2003


#
# Accounting. Log the accounting data.
#
accounting {
#
# Create a 'detail'ed log of the packets.
# Note that accounting requests which are proxied
# are also logged in the detail file.
detail
# daily

# Update the wtmp file
#
# If you don't use "radlast", you can delete this line.
# unix

#
# For Simultaneous-Use tracking.
#
# Due to packet losses in the network, the data here
# may be incorrect. There is little we can do about it.
# radutmp
# sradutmp
# Return an address to the IP Pool when we see a stop record.
# main_pool
# sqlippool

#
# Log traffic to an SQL database.
#
# See "Accounting queries" in sql.conf
sql
#
# Instead of sending the query to the SQL server,
# write it into a log file.
#
# sql_log

# Cisco VoIP specific bulk accounting
# pgsql-voip

}



แค่นี้ ข้อมูล User ก็จะไม่เก็บไว้ใน Text File แต่จะเก็บไว้ใน Mysql ที่ เวลา = 0000-00-00 00:00:00 หมายถึงเวลของคนที่ออนไลน์


แล้วสร้างไฟล์ xxx.php ให้มีเนื้อหาตามนี้

โค๊ด:
ob_start();
include("include/class.mysqldb.php");
include("include/config.inc.php");
$uday = date("Y-m-d");

$sql2 = "SELECT * from radacct where AcctStopTime = '0000-00-00 00:00:00'";
$result2 = mysql_query($sql2);
while($data = mysql_fetch_object($result2)) {
$user = $data->UserName;
passthru("/bin/echo 'User-Name = $user' | /usr/local/bin/radclient -x localhost:3799 disconnect testing123");


$sql = "UPDATE radacct SET AcctStopTime='$uday 00:00:00' where ((AcctStopTime = '0000-00-00 00:00:00') and (UserName='$usus'))";
$result = mysql_query($sql);

}

$sql3 = "DELETE from radacct where AcctStopTime = '0000-00-00 00:00:00'";
$result3 = mysql_query($sql3);
exit();

?>

ปรับแก้ม.บูรพาเพื่อคุม upload/download

Bandwidth ทะลุของม.บูรพาปรับให้สามารถคุมอัพโหลดดาว์นโหลดได้ จากเวบ linuxthai.org
ใน file manage_group.php มันมีบางที่ *1024*8 จริง ๆ แค่ *1024 ก็พอ (รึเปล่า ฮืม)
if($newdown != 0) {
$down = $newdown * 1024 * 8;
$sql = "insert into radgroupreply values ('', 'group".$_REQUEST['newgname']."', 'WISPr-Bandwidth-Max-Down', ':=', '$down')";

มันมี *8 มาด้วย
ทำให้เวลาบันทึกลง Database ค่ามันเลยสูงครับ
เช่น กำหนด Download 512 = 512*1024*8 = 4,194,304
512 = 512*1024 = 524,288 (ค่าที่ถูกต้อง)

ลองแล้ว Bandwidth Download ไม่ทะลุแล้วครับ
แต่ upload ทะลุอยู่ครั

วันจันทร์ที่ 10 สิงหาคม พ.ศ. 2552

squid block เป็นเวลา

ทิปจากท่าน yim และครูมานิสแห่ง thaibsd.com
แก้ไขไฟล์

# nano /usr/local/etc/squid/squid.conf ค้นหาบรรทัด bsex

แล้วแก้ไขคำสั่งการ Blockweb ใหม่ ดังนี้

#blockweb จันทร์-ศุกร์ ช่วงเวลา 08.00 - 17.00 น.
acl time_block time M T W H F 08:00-17:00
#blockweb เสาร์-อาทิตย์ ช่วงเวลา 08.00 - 14.00 น.
acl time_block time A S 08:00-14:00
#blockweb ต่ออีก วันเสาร์-อาทิตย์ ช่วงเวลา 18.10 - 21.10 น.
acl time_block time A S 18:10-21:10
acl bsex url_regex "/usr/local/etc/squid/bsex.txt"
http_access deny bsex time_block
deny_infohttp://www.google.co.thbsex time_block

คงเป็นประโยชน์ สำหรับร้านอินเตอร์เน็ต ที่มีจรรยาบรรณ ให้เล่นเกมส์ออนไลน์ เป็นช่วงเวลา จะได้ไม่มอมเมาเยาวชน ร่วมด้วยช่วยกันครับ

วันอังคารที่ 30 มิถุนายน พ.ศ. 2552

การทำ by pass authen สำหรับเจ้านายขี้หงุดหงิด

กรณีที่เราจัดทำ server เพื่อทำ authentification แล้วเกิดเจ้านาย..ไม่อยาก authen ก็สามารถ bypass ได้โดยแก้ไขไฟล์
chilli.conf

# MAC authentication
macauth

# TAG: macpasswd
macpasswd password

จากนั้น เพิ่ม User ในฐานข้อมูล โดย User Name : MacAddress ของเครื่องที่ต้องการ
โดยรูปแบบต้องเป็นแบบนี้นะครับ 00-1D-E0-9B-78-81
ส่วน PassWord ก็ใส่เป็น password

จากนั้นพอเครื่องที่กำหนดเปิดปุ๊บ ได้รับ IP ก็ใช้เน็ตได้เลยครับ
tip จากท่าน starcrafe แห่ง www.thaibsd.com

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

อบรม web conference ที่นนทบุรี


วันที่ 18-19 มิถุนายน 2552 ได้ไปอบรม web conference ที่โรงแรมโกล์เด้น ดราก้อน นนทบุรี..
ทดลองประชุมผ่าน web conference และผ่านอุปกรณ์ mcu และหลาย ๆ ช่องทางเพื่อเตรียมประชุมผ่านระบบ conference
ถึงแม้ที่ทำงานของเรา (ขาดอีก 67 เขตที่ยังไม่มีกล้อง conference ราคาเกือบสามแสน คงใช้ webcam หรือ กล้องวีดีโอไปก่อน)
ก็ผ่านการอบรมไม่ประสบผลสำเร็จมากนักเนื่องจาก แบนวิธอินเตอร์เน็ตของโรงแรมมีปัญหาเข้าระบบได้ช้ามาก ได้ไม่กี่ site เอง

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

popup มีรูปโชว์


กรณีไม่โชว์รูป..มีสองกรณีคือ..หากไม่ใช้ cert ต้องเอา setcookie ไฟล์
hotspotlogin.php กับ hotspotlogin_popup.php
ให้เหลือแค่ setcookie('username', $name, $expire);
กรณีต้องการโชว์รูปให้ตั้งชื่อรูปเป็นขื่อ login ของ ยูเซอร์ นามสกุล .jpg ครับ.
กรณี httpd.conf ของ server ตั้ง AddDefaultChaset utf-8,tis-620 จะขึ้น error ให้เอา tis-620 ออกก่อนจะสามารถใช้ได้ครับ..

วันศุกร์ที่ 29 พฤษภาคม พ.ศ. 2552

iftop เช็ค แบนวิธ

จอมยุทธ์น้อย


Sex :
Post : 444
สมาชิกลำดับที่ : 278

วันนี้ ผมมานำเสนอโปรแกรม traffic mornitor สำหรับ terminal ตามคำสัญญาที่ให้ไว้กับ อ.กิตติพงษ์ นะครับ
โปรแกรมนั้นมีชื่อว่า iftop
วิธีการติดตั้งนั้นก็แสนง่าย
#cd /usr/ports/net-mgmt/iftop
#make install clean
#rehash
เสร็แล้วสั่ง
#iftop -P -B <ย้ำว่าต้องเป็น root เท่านั้นจึงจะดูได้>
ส่วนการทำงานของมันนั้นมันจะรายงานว่า ขณะนี้ เครื่อง ip ใด ติดต่อกับ เครื่องเราอยู่
และport อะไรจะดีมาก ๆ สำหรับเครื่องที่เป็น gateway และสำนักงานใหญ่ ๆ ที่มีเครื่องติดไวรัสแต่
ไม่สามารถทำอะไรได้อย่างผม
จะไปฆ่าให้ก็ไม่เอา บอกให้ไป ลง windows ใหม่บอกไม่มีเงิน
- -" เอาน่า เราก็ จัดการ block ip นั้นเป็นการสั่งสอนไปพลาง ๆ ถ้าเค้าใช้ internet ไม่ได้นาน ๆ
ก็ จะยอมเองแหละ อิอิ
ประการสำคัญ
โปรแกรมเนี้ย มันดูได้ อีกว่า ใครทำอะไร กับ อะไรอยู่ นะ คงไม่ต้องอธิบายมาก

ส่วน option ต่าง ๆ ก็มีดังนี้
Host display: General:
n - toggle DNS host resolution P - pause display
s - toggle show source host h - toggle this help display
d - toggle show destination host b - toggle bar graph display
t - cycle line display mode B - cycle bar graph average
T - toggle cummulative line totals
Port display: j/k - scroll display
N - toggle service resolution f - edit filter code
S - toggle show source port l - set screen filter
D - toggle show destination port L - lin/log scales
p - toggle port display ! - shell command
q - quit
Sorting:
1/2/3 - sort by 1st/2nd/3rd column
< - sort by source name
> - sort by dest name
o - freeze current order

ถ้าเครื่องมี cardlan 2 ตัว
ในกรณีที่เราสั่ง #iftop -P -B มันจะแสดงค่าของ CardLan ตัวแรก
อย่างของผมคือ bge0
แล้วทีนี้ถามว่าถ้าอยากดูของ bge1 ล่ะ ?
เราก็ สั่งว่า
#iftop -P -B -i bge1

แค่นั้นแหละฮะ เอามาฝาก เผื่อใครปวดหัวกะ virus รึ การไล่ block web

วันอังคารที่ 5 พฤษภาคม พ.ศ. 2552

ดีดยูเซอร์ออกทันที

# echo User-Name=user1 | radclient -x 127.0.0.1:3779 disconnect wifi

อธิบาย user1 คือ user ที่ต้องการถีบออกให้หลุดเลย

wifi คือ radiussecret

chmod 777 ไฟล์ radclient ด้วย