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

squid 3 บน centos 5.x

บทความจากเวบไซด์..
http://www.howtoforge.com/anonymous-proxy-using-squid-3-centos-5.x

1) Installation Of Squid 3:
CentOS 5 comes with Squid 2.6 but we need Squid 3, so we will download the source rpm of squid 3 and compile it for our OS.



1.1) Install Prerequisites
Install pre-requisite software, i.e. development tools to get all the compilers, libraries and other rpms for the compilation of SQUID 3.

yum -y groupinstall "Development Tools"
yum -y install rpm-build openjade linuxdoc-tools openldap-devel pam-devel openssl-devel httpd rpm-devel



1.2) Download Squid 3 Source RPM
Download source rpm of Squid 3 from the FEDORA website and install it.

cd /usr/src
wget http://download.fedora.redhat.com/pub/fedora/linux/releases/10/Fedora/source/SRPMS/squid-3.0.STABLE10-1.fc10.src.rpm
rpm -ivh squid-3.0.STABLE10-1.fc10.src.rpm



1.3) Compile Squid 3
Use the following commands to start the compilation, at the end it will generate an rpm file to install:

cd /usr/src/redhat/SPECS
rpmbuild -bb squid.spec



1.4) Install Squid 3
Install the newly built rpm, which will be found in /usr/src/redhat/RPMS/i386 for i686 and /usr/src/redhat/RPMS/x86_64 for x86_64.

rpm -Uvh /usr/src/redhat/RPMS/i386/squid-3.0.STABLE10-1.i386.rpm



2) Configuration
I will use the default squid.conf to edit.

vi /etc/squid/squid.conf

หรือ


wget -q -O- "http://devel.pramberger.at/getrepo?release=5" >> /etc/yum.repos.d/pramberger.repo

yum install squid3

วันพุธที่ 25 กันยายน พ.ศ. 2556

วันจันทร์ที่ 23 กันยายน พ.ศ. 2556

การ mount flash drive บน centos

สำหรับท่านที่ต้องการ mount flash drive ที่ฟอร์แมตแบบ ntfs ให้สามารถใช้งานกับ linux centos ได้ให้ทำดังนี้ครับ

1. สำหรับ centos 5.x
ทำการ Enable EPEL ก่อน
## RHEL/CentOS 5 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm

## RHEL/CentOS 5 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
# rpm -ivh epel-release-5-4.noarch.rpm

หลังจากนั้นทำการติดตั้ง ntfs-3g ได้เลย..ผ่าน epel
# yum --enablerepo=epel install ntfs-3g

2. สำหรับ centos 6.x
## RHEL/CentOS 6 32-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

## RHEL/CentOS 6 64-Bit ##
# wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm

หลังจากนั้นทำการติดตั้ง ntfs-3g ได้เลย..ผ่าน epel
# yum --enablerepo=epel install ntfs-3g

หลังจากที่ติดตั้ง ntfs-3g แล้วก็สามารถ mount flash drive ที่เป็น ntfs บน centos ได้เลยครับ
โดยการตรวจสอบ อุปกรณ์ flash drive ก่อนว่าชื่ออะไรด้วยคำสั่ง

#fdisk -l

หลังจากนั้น ก็สร้างห้องสำหรับ mount อุปกรณ์ผมสร้างไว้ที่ #mkdir /mnt/usb

#mount -t ntfs /dev/sdb1 /mnt/usb เรียบร้อย โดยค่า sdb1 จะเป็นอุปกรณ์ flash drive ที่เสียบไป บางครั้งอาจเป็น sdc1 ขึ้นอยู่กับคำสั่ง fdisk -l ว่าโชว์ชื่ออุปกรณ์ว่าอะไร
#cd /mnt/usb อันเป็นที่เรียบร้อย

วันอังคารที่ 17 กันยายน พ.ศ. 2556

dhcp on centos 6.4

yum -y install dhcp

#nano /etc/sysconfig/dhcpd

DHCPDARGS=eth1 ใส่การ์ดแลนที่ต้องการให้แจก dhcp

#cp /usr/share/doc/dhcp-*/dhcpd.conf.sample /etc/dhcp/dhcpd.conf

นำไฟล์คอนฟิกจากตัวอย่างมาแก้ไขเป็นไฟล์ dhcpd.conf ทำการแก้ไขให้เหมาะสม

# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
# see 'man 5 dhcpd.conf'
#
ddns-update-style none;
authoritative;
log-facility local7;
default-lease-time 600;
max-lease-time 7200;
option subnet-mask 255.255.255.0;
option broadcast-address 10.0.0.255;
option routers 10.0.0.1;
option domain-name-servers 192.168.6.1;
# option domain-name "centos.local";
subnet 10.0.0.0 netmask 255.255.255.0 {
range 10.0.0.10 10.0.0.100;
}

บันทึกแล้ว start dhcpd
#service dhcpd restart
To Check the DHCP Leases on CentOS Server:

cat /var/lib/dhcpd/dhcpd.leases

วันพฤหัสบดีที่ 5 กันยายน พ.ศ. 2556

การติดตั้ง squid เพื่อแชร์เน็ตใน linux

บทความจากอินเตอร์เน็ตจากเว็บไหน..จำไม่ได้..ขอความโชคดีให้ผู้เขียนบทความ...จงเจริญ

การทำ Transparent Proxy บน Squid
กรณีที่ Squid Server เป็น Gateway

1.ให้ทำการแก้ไขหรือเพิ่มเติมข้อมูลในไฟล์คอนฟิกของ squid (squid.conf) ให้มีบรรทัดต่อไปนี้ :

httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on

2. ตรวจสอบแพ็กเกตที่วิ่งผ่านเครื่อง Gateway ว่าเป็นการเรียกใช้งาน Port 80 (การเรียกใช้งานเว็บ) หรือไม่ ถ้าเป็นการเรียกใช้งานที่ Port 80 ก็ให้บังคับให้ใช้งานผ่าน squid โดยใช้คำสั่ง ipchains หรือ iptables

กรณี ipchains ให้ใช้คำสั่งดังนี้ :
#ipchians -F
#ipchains -A input -p tcp -s 192.168.1.0/24 -d 0/0 80 -j REDIRECT 8080
หรืออาจจะเป็น
#ipchains -F
#ipchains -A input -p tcp -s 0/0 -d 0/0 80 REJECT 8080

หมายเหตุ ในกรณีที่ squid ทำงานที่ port อื่น เช่น 3128 ก็ให้เปลี่ยน 8080 เป็น 3128


กรณี iptables

ใช้การ์ดแลน 1 การ์ด ให้ใช้คำสั่งดังนี้ :
#echo 1 > /proc/sys/net/ipv4/ip_forward
#iptables -F
#iptables -t nat -F
#iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

ใช้การ์ดแลน 2 การ์ด โดย eth0 เป็น public และ eth1 เป็น private ให้ใช้คำสั่งดังนี้ :
#echo 1 > /proc/sys/net/ipv4/ip_forward
#iptables -F
#iptables -t nat -F
#iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 8080

ใช้การ์ดแลน 2 การ์ดและทำ Masquerade ด้วย โดย eth0 เป็น public และ eth1 เป็น private การทำ Masquerade ด้วยจะเป็นผลดี กล่าวคือผมเคยเจอว่าการเรียกเว็บของบางที่ซึ่งมีระบบ Secure ด้วย จะใช้งานไม่ได้ เลยต้องทำ Masquerade ด้วย ซึ่งให้ใช้คำสั่งดังนี้ :
#echo 1 > /proc/sys/net/ipv4/ip_forward
#iptables -F
#iptables -t nat -F
#iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
#iptables -t nat -A PREROUTING -i eth1 -p tcp --dport 80 -j REDIRECT --to-port 8080

กรณีที่ใช้ Squid ร่วมกับ Cisco Router
ในกรณีที่ Gateway เป็น Cisco Router ก็สามารถทำ Transparent Proxy ร่วมกับ Squid เช่นเดียวกันครับ แต่การทำ ต้องทำทั้งบนเครื่องที่เป็น Squid และบน Cisco Router ซึ่งใช้ Web Cache Communication Protocol (wccp)

ในที่นี้ผมจะยกตัวอย่างแบบง่าย ๆ ที่ผมเคยทดลองใช้งานได้นะครับ (ออกตัวเสียก่อน เพราะจริง ๆ แล้วผมไม่เก่งเรื่อง router มากนัก) วิธีการทำการเป็นดังนี้ครับ

ขั้นที่ 1 ทำที่ Squid
ก็ทำเหมือนกับวิธีการทั่วไปครับ คือ ให้ทำการแก้ไขหรือเพิ่มเติมข้อมูลในไฟล์คอนฟิกของ squid (squid.conf) ให้มีบรรทัดต่อไปนี้ :

httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on

และในไฟล์ squid.conf จะมีคำว่า :

wccp_router 0.0.0.0

ซึ่งเป็นการกำหนด IP ของ home router โดยค่า default จะเป็น 0.0.0.0 หมายถึงเป็นการ disable wccp ดังนั้นก็ให้เปลี่ยน 0.0.0.0 เป็น IP ของ Router และถ้ามีเครื่องหมาย # นำหน้าก็ให้เอาออก

ขั้นที่ 2 การใช้คำสั่งบน Cisco
ให้ใช้คำสั่งสั้น ๆ 4 คำสั่ง ดังนี้ :
Router(conf)#ip wccp version 1 # ผมลองใช้ Version 2 (ซึ่งเป็นค่า default ของ router รุ่นที่ผมใช้) ปรากฎว่ามองไม่เห็น Proxy (Cache Engine)
Router(conf)#ip wccp web-cache
Router(conf)#int e0/0
Router(conf-if)#ip wccp web-cache redirect out

หมายเหตุ ตรง e0/0 อาจจะเป็น e0 หรือ f0 ได้นะครับ ขึ้นอยู่กับรุ่นของ router

คำสั่งที่เกี่ยวข้อง
sh ip wccp
sh ip wccp web-cache detail
sh ip wccp web-cache view
clear ip wccp
clear ip wccp web-cache

จบครับ