basic linux
DESCRIPTION
Basic linuxTRANSCRIPT
Training Basic Linux
Mr.Kriangsak [email protected]
[email protected]://www.jodoi.comhttp://www.doi.in.th
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
การติ�ดติ��ง Linux
Linux Kernel• Kernel เป็�นส่�วนที่�ที่� หน� ที่�ควบค�ม
ก รที่� ง นในระดั�บล่� งค�อส่�วนที่�เป็�น Hardware ที่��งหมดั รวมถึ งก รจั�ดัส่รรที่ร�พย กรดั�วย
KernelHardware
Kernel
Linux Shell• เป็�นตั�วเชื่��อมระหว� งผู้'�ใชื่�ง นก�บส่�วน
ของ kernel เม��อเที่ยบก�บ dos แล่�วก*ค�อ command.com โดัย shell จัะที่� หน� ที่�ร �บค� ส่��งจั กผู้'�ใชื่�ม ตัคว มหม ย
KernelHardware
หลั�กการทำ�างานของ Linux•อ�ป็กรณ์-ที่�กอย� ง Linux จัะมองเป็�น
ไฟล่-•Config ของระบบแล่ะของโป็รแกรม
ตั� งๆ ก*จัะมองเป็�นไฟล่-•ข�อม'ล่ที่�กอย� งมล่�กษณ์ะ Case
Sensitive
โครงสร�าง File ใน Linux
• / Root Partition/bin เก*บ Binary File ในก ร Run ค� ส่��งตั� งๆ/boot เก*บไฟล่-ส่� ค�ญในก ร Boot ระบบ/dev เก*บข�อม'ล่อ�ป็กรณ์-ตั� งๆ/mnt เก*บข�อม'ล่อ�ป็กรณ์-ที่� Mount ไว�/etc เก*บ Config ของ Application ตั� งๆ/home เก*บข�อม'ล่ของ User แตั�ล่ะคน/lib เก*บ Libraries Files ตั� งๆ ของระบบ/root เก*บข�อม'ล่ของ Root/var เก*บ System Log, Application log, เก*บ Mail ฯล่ฯ
การร��จั�ก Hardware ของ Linux
• /dev/fd0 ฟล่อป็ป็4ไดัรฟ5ตั�วแรก (ไดัรฟ5 A:)• 1/dev/fd ฟล่อป็ป็4ไดัรฟ5ตั�วที่�ส่อง (ไดัรฟ5 B:)• //1/ พ ร-ตั6ชื่�นที่� 1 ของฮ ร-ดั6ส่ก-ตั�วแรกชื่น6ดั IDE• /dev/hda2/ พ ร-ตั6ชื่�นที่� 2 ของฮ ร-ดั6ส่ก-ตั�วแรกชื่น6ดั IDE• /dev/hda3/ พ ร-ตั6ชื่�นที่� 2 ของฮ ร-ดั6ส่ก-ตั�วแรกชื่น6ดั IDE• /dev/hda4/ พ ร-ตั6ชื่�นที่� 2 ของฮ ร-ดั6ส่ก-ตั�วแรกชื่น6ดั IDE• /dev/hda5 / logical พ ร-ตั6ชื่�นที่�1ของฮ ร-ดั6ส่ก-ตั�วแรก
ชื่น6ดั IDE
การร��จั�ก Hardware ของ Linux (ติ�อ)
• 1/dev/hdb / พ ร-ตั6ชื่�นที่� 1 ของฮ ร-ดั6ส่ก-ตั�วที่�ส่องชื่น6ดั IDE
• /dev/hdb2/ พ ร-ตั6ชื่�นที่� 2 ของฮ ร-ดั6ส่ก-ตั�วที่�ส่องชื่น6ดั IDE
• /dev/hdb3/ พ ร-ตั6ชื่�นที่� 2 ของฮ ร-ดั6ส่ก-ตั�วที่�ส่องชื่น6ดั IDE
• /dev/hdb4/ พ ร-ตั6ชื่�นที่� 2 ของฮ ร-ดั6ส่ก-ตั�วที่�ส่องชื่น6ดั IDE
• /dev/hdb5 / logical พ ร-ตั6ชื่�นที่�1ของฮ ร-ดั6ส่ก-ตั�วที่�ส่องชื่น6ดั IDE
การร��จั�ก Hardware ของ Linux (ติ�อ)
• /dev/cdrom CD-ROM Driveหร�อ /dev/hdc, /dev/hdd แล่�วแตั� Disk Partition
• /dev/sda/ SCSI Primary Master• /dev/sdb/ SCSI Primary Slave• /dev/sdc/ SCSI Secondary master• /dev/sdd/ SCSI Secondary Slave
Linux basic command• ก รเข� ใชื่�ง นระบบ (login) ตั�องใส่� Username แล่ะ
Password ซึ่ �งขณ์ะที่�เร พ6มพ- password จัะไม�เห*นข�อคว ม
• Shell $ ส่� หร�บบ�คคล่ที่��วไป็ที่� Login เข� ม • Shell # ส่� หร�บผู้'� Login เป็�น Root ซึ่ �งเป็�นผู้'�ดั'แล่
ระบบ• ค� ส่��ง “pwd” ใชื่�เพ��อแส่ดัง directory ป็9จัจั�บ�น
**ไม�ควรป็:ดัเคร��องโดัยไม�ที่� ก ร Shutdown
การปิ�ดเคร��องอย่�างถู�กวิ�ธี#•ก ร shutdown
#shutdown –h now
•ก ร restart#shutdown –r now #shutdown –r +5 (เคร��องจัะ restart ในอก 5 น ที่)#reboot
**ไม�ควรป็:ดัเคร��องโดัยไม�ที่� ก ร Shutdown **
การเปิลั#�ย่น Directory
• ก รเป็ล่�ยน Directory# cd <Directory>Directory. หม ยถึ ง Current Directory.. หม ยถึ ง Parent Directory/ หม ยถึ ง Directory ร ก (Root Directory)~ หม ยถึ ง Home Directory (/home/)
การด�ไฟลั&ข�อมู�ลั• ดั'ไฟล่-ข�อม'ล่ # ls (ใชื่� * เป็�น
Wildcard ไดั�)• ดั'ไฟล่-ข�อม'ล่พร�อมร ยล่ะเอยดั # ls -al
- - 1rwxr xr x jodoi 37 45 19user Apr21:12 wut.txt– Permission ของไฟล่- - - -rwxr xr x– จั� นวน link 1– Owner jodoi– Group user– ขน ดั 37 bytes– ว�นที่�ๆ แก�ไขล่� ส่�ดั 45 Apr 19 21:12 – ชื่��อไฟล่- wut.txt
การด�ไฟลั&ข�อมู�ลั (ติ�อ)
• ดั'ป็ระเภที่ไฟล่-ข�อม'ล่ # file <ชื่��อไฟล่- >
• ดั'เน��อห ของไฟล่- # cat <ชื่��อไฟล่->• ดั'เน��อห ของไฟล่-เป็�นหน� # more <ชื่��อไฟล่->• ดั'ก รเป็ล่�ยนแป็ล่งของไฟล่- # tail –f <ชื่��อ
ไฟล่->
การก�าหนดส�ทำธี�ของไฟลั&ข�อมู�ลั
• chmod ใชื่�ในก รก� หนดั Permission ของไฟล่-• -rwx -r x -r x หม ยถึ ง
– rwx ส่� หร�บ Owner (อ� นไดั� , เขยนไดั� , Execute ไดั� ) - > 11 1
– r-x ส่� หร�บ Group (อ� นไดั�, เขยนไม�ไดั�, Execute ไดั�) - >1 01
– r-x ส่� หร�บ Other (อ� นไดั�, เขยนไม�ไดั�, Execute ไดั�) - >1 01
• แป็ล่งเป็�นเล่ขฐ นส่6บ rwxr-xr-x -> 111 101 101 -> 755
• ในก รส่��งให�ไฟล่-ม Permission เป็�น rwxr-xr-x ส่ ม รถึที่� ไดั�โดัยใชื่�ค� ส่� �ง chmod 755 <ชื่��อไฟล่->
การก�าหนดควิามูเปิ(นเจั�าของไฟลั&ข�อมู�ลั
• เป็ล่�ยน Owner ของไฟล่- ดั�วยค� ส่��ง chown ตั�วอย� งเชื่�น – chown samart file1.txt
• เป็ล่�ยน Group ของไฟล่- ดั�วยค� ส่��ง chgrp ตั�วอย� งเชื่�น– chgrp samart file1.txt
• เป็ล่�ยนที่��ง Owner แล่ะ Group ในคร วเดัยว ดั�วยค� ส่��ง chown – chown root.root file1.txt
การทำ�าส�าเนาไฟลั&ข�อมู�ลั• cp [option] <source file1> [source
file2] […] <destination file/dir>• Options
– -p Preserve permission, owner– -r Recursive– -v แส่ดังชื่��อไฟล่-ขณ์ะที่� copy ดั�วย– -f force overwriting
• ตั�วอย� ง cp xxx.txt yyy.txt
การทำ�า Link ถู)งไฟลั&ข�อมู�ลั• คล่� ยก รส่ร� ง shortcut ของ Microsoft Windows• มส่องป็ระเภที่ค�อ Hard link แล่ะ Soft link
– Hard link: ln file1 file2 ไฟล่- 2 จัะอ� งไป็ย�ง physical address ของไฟล่- 1 เล่ย
– Softlink: ln -s file1 file2 ไฟล่- 2 จัะอ� งไป็ย�งชื่��อของไฟล่- 1 ถึ� เป็ล่�ยนชื่��อของไฟล่- 1 ไฟล่- 2 ก*จัะกล่ ยเป็�น link ที่�ผู้6ดัพล่ ดัไป็
• ล่อง ln -s /usr/bin/X11/xpaint /bin/xpaint• จั กน��นล่อง ls -l /bin/xpaint จัะพบ xpaint อย'�ใน
bin
การย่�าย่ไฟลั&ข�อมู�ลั
• mv [option] <source1> [source2] […] <destination>
• ตั�วอย� ง mv file1.txt file2.txt• ล่องใชื่�ค� ส่��ง mv เพ��อย� ยไดัเรกที่อร /tmp
ม ย�ง Home directory ของที่� น แล่ะล่องใชื่�ค� ส่��ง mv เพ��อย� ยกล่�บ
การลับไฟลั&ข�อมู�ลั• rm [options] <files>… เชื่�น rm file1.txt• Options:
– - f ล่บเล่ยโดัยไม�ตั�องถึ มย�นย�น– -i ให�ถึ มย�นย�นอกคร��งว� y หร�อ n– -r ล่บที่��งไฟล่-แล่ะไดัเรอที่อร�ย�อยที่�อย'�ภ ยใน
• ค� ถึ ม ค� ส่��ง rm -rf / หม ยคว มว� อย� งไร• ล่บ Directory # rmdir <ชื่��อ Directory>• ล่บ Directory รวมที่��งไฟล่-แล่ะ Directory ย�อยที่��งหมดั
rm –rf <ชื่��อ Directory>
การส�งติ�อค�าส��ง
• Linux ส่ ม รถึให�เร ส่�งตั�อผู้ล่ของค� ส่��งไดั� โดัยใชื่� ไป็ป็5 (|)
• เชื่�นให�ที่ดัล่องใชื่�ค� ส่��ง # ls –al |more
• ส่�วนใหญ�จัะใชื่�ก�บค� ส่��ง grep ซึ่ �งชื่�วยในก รค�นห ข�อคว ม
• เชื่�นให�ที่ดัล่องใชื่�ค� ส่��ง # ls –al |grep in จั ก root dir (/)
การค�นหาข�อควิามู• ห กตั�องก รห บรรที่�ดัที่�มค� ว� telnet ในไฟล่-
/etc/inetd.conf– cat /etc/inetd.conf |grep telnet หร�อ grep
telnet /etc/inetd.conf• ตั�องก รให�แส่ดังที่�กบรรที่�ดั ยกเว�นบรรที่�ดัที่�มค� ว� telnet
– - cat /etc/inetd.conf |grep v telnet หร�อ grep -v telnet /etc/inetd.conf
• ตั�องก รให�แส่ดังบรรที่�ดัที่�ข �นตั�นดั�วย root ในไฟล่- /etc/passwd– cat /etc/passwd |grep “^root” หร�อ
grep “^root” /etc/passwd
การค�นหาไฟลั&ข�อมู�ลั
• ค� ส่��ง locate (Package ชื่��อ slocate)
• ก�อนจัะใชื่�ค� ส่��ง locate ตั�องมก ร Update Files Database โดัยใชื่�ค� ส่��ง# updatedb
• เส่ร*จัแล่�วล่องใชื่�ค� ส่��ง #locate httpd
การใช้�ค�าส��ง tar รวิบรวิมูข�อมู�ลั
• ร'ป็แบบ # tar [options] files• ค� ส่��งที่�มก รใชื่�ง นก�นบ�อยค�อ
– tar xvfz <ไฟล่- .tar.gz> [destination] ใชื่�แตักไฟล่- .tar.gz
– tar xvf <ไฟล่- .tar> [destination] ใชื่�แตักไฟล่- .tar
– tar cvfz <ชื่��อไฟล่-ที่�จัะเก*บ> [destination] • เชื่�น tar cvfz backup.tar.gz /var/log/
การ Add/Delete User , สลั�บใช้�งาน• Add User (ข�อม'ล่จัะอย'�ใน /etc/passwd)
#useradd <ชื่��อ User> เชื่�น #useradd samartหม ยเหตั� ใน Debian Linux ควรใชื่� adduser เชื่�น # adduser
test1
• Delete User#userdel <ชื่��อ User> เชื่�น #userdel samart
หม ยเหตั� ใน Debian Linux ควรใชื่� deluser เชื่�น # deluser test1
• ส่ล่�บก รใชื่�ง นระหว� ง User#su - <ชื่��อ User>
• ส่ล่�บก รใชื่�ง นระหว� งหน� จัอกดั ALT+F2…F12 เพ��อเรยกใชื่� Virtual Console
การเปิลั#�ย่นรห�สผ่�าน แลัะการติ��งรห�สผ่�าน
• เป็ล่�ยน Root Password (ข�อม'ล่จัะอย'�ใน /etc/shadow)# passwd enter old password :
enter new password : reenter new password หม ยเหตั� จัะไม�แส่ดัง
ผู้ล่เม��อที่� ก รพ6มพ-• เป็ล่�ยน User Password
# passwd <ชื่��อ User>
การติ��งค�าวิ�น,เวิลัา•ดั'ค� ว�น,เวล่ ของระบบ
# date• ร'ป็แบบค� ส่��ง # date MMDDhhmmYYYY
เชื่�น ว�นน�ว�นที่� 16022004/ /เวล่ 15:43ใชื่�ค� ส่��ง # date 021615432004 เป็�นตั�น
- ใชื่� ntpdate ชื่�วยในก ร set time
#ntpdate -b clock.nectec.or.th
การ Monitor ระบบ• ดั' Process # ps –ef• Kill Process # kill -9 <ps
no.>• Restart Process # kill -1
<PID>• ดั' User ที่� Login อย'�ในระบบ # w• ดั'ก รใชื่�ง น Resources ตั� งๆ # top• ดั'ขน ดั Partion ที่�ก Partition # df –kh• ดั'ขน ดั Folder # du –kh• ดั'เวอร-ชื่��นของ Kernel # uname -a
ขอควิามูช้�วิย่เหลั�อด�วิย่ค�าส��ง man
• ล่องใชื่�ค� ส่��ง man ls จัะแส่ดังร ยล่ะเอยดัว6ธีก รใชื่�ค� ส่��ง ls
• ห กที่ร บแค� keyword ย�งไม�ที่ร บกระที่��งชื่��อค� ส่��ง เชื่�น อย กร' �ค� ส่��งที่�ใชื่�ในก รที่� ก ร copy ให�พ6มพ-ว� man -k copy จัะแส่ดังร ยชื่��อของค� ส่��งที่�เก�ยวข�องก�บก ร copy
• update ฐ นข�อม'ล่ของ man -k โดัยก รใชื่�ค� ส่��ง makewhatis (ตั�องเป็�น root)
• หร�อห กที่ร บค� ส่��ง แตั�ไม�ที่ร บ syntax ให�ล่องพ6มพ- ค� ส่��ง แล่�วตั มดั�วย -- help ก*จัะมตั�วชื่�วยอย� งย�อข �นม ให� เชื่�น # ls --help
Basic text mode editor (vi)
• ใชื่� Editor vi เป็�นพ��นฐ นของก รใชื่�ง น ส่� ค�ญม ก
• ใชื่� vi ตั มดั�วยชื่��อไฟล่- ที่�ตั�องก รแก�ไข หร�อตั�องก รส่ร� ง
• เชื่�น vi helloworld.c• จัะมเคร��องหม ย ~ ในแตั�ล่ะบรรที่�ดั
การใช้� vi จั�ดการไฟลั& (ติ�อ)
• ก รเพ6�มข�อคว ม Esc
a
A iO
o
“a” แที่รกข�อคว มหล่�งเคอร-เซึ่อร-
“A” ใส่�ข�อคว มใหม� ที่� ยของ บรรที่�ดั
“i” ใส่�ข�อคว มใหม�หน� เคอร-เซึ่อร-
“O” แที่รกบรรที่�ดั 1บรรที่�ดับนตั� แหน�งเคอร-เซึ่อร-
“o” แที่รกบรรที่�ดั 1บรรที่�ดัใตั�ตั� แหน�งเคอร-เซึ่อร-
การใช้� vi จั�ดการไฟลั& (ติ�อ)
• ก รล่บ dw ล่บข�อคว ม 1 ค� dd ล่บข�อคว มที่��งบรรที่�ดั
x ล่บตั�วอ�กษรที่�เคอร-เซึ่อร-D ล่บตั�วอ�กษรตั��งแตั�เคอร-เซึ่อร-อย'�จันส่�ดับรรที่�ดั
• ก รค�นห ค� พ6มพ- / แล่�วตั มดั�วยค� ที่�ตั�องก รค�นห เชื่�น /systemให�ค�นห ตั�อไป็ กดั n ไป็เร��อยๆ
การใช้� vi จั�ดการไฟลั& (ติ�อ)
• ก รควบค�มเคอร-เซึ่อร- ที่� Mode ค� ส่��ง h เล่�อนไป็ที่ งซึ่� ย (หร�อป็�?มล่'กศรชื่�ซึ่� ย)
J เล่�อนล่งล่� ง (หร�อป็�?มล่'กศรชื่�ล่งล่� ง)K เล่�อนข �นบน (หร�อป็�?มล่'กศรชื่�ข �นบน)l เล่�อนไป็ที่ งขว (หร�อป็�?มล่'กศรชื่�ขว )
การใช้� vi จั�ดการไฟลั& (ติ�อ)
• ก รเก*บข�อม'ล่แล่ะออกจั ก vi :w ก รเขยนไฟล่-
:w new_files ก ร Save เป็�นชื่��อใหม�:wq ก ร Save ไฟล่-แล่�วออกจั ก vi:wq! ก ร Save ไฟล่-แล่�วออกจั ก vi โดัยไม�ม
เง��อนไข:q! ออกจั ก vi โดัยไม�มก ร save ไฟล่-
Well-Known PortECHO Server ---> TCP/7DISCARD Server ---> TCP/9DAYTIME Server ---> TCP/13CHARGET Server ---> TCP/19FTP Server ---> TCP/21SSH Server ---> TCP/22Telnet Server ---> TCP/23SMTP Server ---> TCP/25DNS Server ---> TCP/53 and UDP/53DHCP Server ---> UDP/68 Web Server ---> TCP/80 (HTTP)Secure Web Server ---> TCP/443 (HTTPS)POP3 Server ---> TCP/110IMAP Server ---> TCP/143SNMP Server ---> UDP/161LDAP Server ---> TCP/389Web Proxy Server ---> TCP/3128 or TCP/8080
iptables Firewall# iptables -L –n
Chain INPUT (policy ACCEPT)target prot opt source destination
Chain FORWARD (policy ACCEPT)target prot opt source destination
Chain OUTPUT (policy ACCEPT)target prot opt source destination
TABLES in IPTABLES
[1] filter[2] nat
# iptables -t filter -L -n# iptables -t nat -L –n
ERASE existing ruleset
# iptables -F INPUT# iptables -F OUTPUT
set defaut policy
# iptables -P INPUT DROP# iptables -P OUTPUT ACCEPT
set stateful connection tracking (allow REPLY to come back)
# iptables -P INPUT DROP# iptables -P OUTPUT ACCEPT# ping 192.168.100.254# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# ping 192.168.100.254
iptables Firewall
Ex SELECTIVELY PERMIT some connectione.g. TCP/22 from 192.168.1.0/24
LIST the following information [0] FROM WHAT INTERFACE?
[1] FROM WHAT IP? [2] TO WHICH PROTOCOL? [3] TO WHICH PORT?
LIST the following information [0] FROM WHAT INTERFACE? eth0
[1] FROM WHAT IP? 192.168.1.0/24 [2] TO WHICH PROTOCOL? TCP [3] TO WHICH PORT? 22
# iptables -A INPUT -i eth0 -s 192.168.1.0/24 -p tcp --dport 22 -j ACCEPT
iptables Firewall
Ex SELECTIVELY PERMIT some connectione.g. TCP/80 from 192.168.1.0/24
LIST the following information [0] FROM WHAT INTERFACE?
[1] FROM WHAT IP? [2] TO WHICH PROTOCOL? [3] TO WHICH PORT?
LIST the following information [0] FROM WHAT INTERFACE? eth0
[1] FROM WHAT IP? any [2] TO WHICH PROTOCOL? TCP [3] TO WHICH PORT? 80,443
# iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT# iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
iptables Firewall
RESET iptables ruleset# iptables -F INPUT# iptables -F OUTPUT# iptables -P INPUT ACCEPT# iptables -P OUTPUT ACCEPT# iptables -t nat -F POSTROUTING
Reading iptables rules# iptables -L –n# iptables-save
iptables Firewall
Transparent Proxy
Squid = TCP/3128 or TCP/8080# vi /etc/squid/squid.conf...httpd_accel_host virtualhttpd_accel_port 80httpd_accel_with_proxy onhttpd_accel_uses_host_header on ...# /etc/init.d/squid restart
# iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
iptables Firewall
Internet Gateway Server
1.เป็:ดั IP Forward[root@doiserver root]# vi /etc/sysctl.conf ~# Controls IP packet forwardingnet.ipv4.ip_forward = 0 ( แก�จั ก 0 เป็�น 1 )~:wq!
[root@doiserver root]# service network restart[root@doiserver root]# cat /proc/sys/net/ipv4/ip_forward 1 ( ผู้ล่ที่�ไดั�ตั�องเที่� ก�บ 1 )
2.ป็:ดั Firewall ของระบบ [root@doiserver root]# setup
Internet Gateway Server
3. Set กล่��ม IP ที่�ให� Forward Packet ไดั�[root@doiserver root]# iptables -A FORWARD -s 192.168.200.240/28 -j ACCEPT
[root@doiserver root]# iptables -A FORWARD -d 192.168.200.240/28 -j ACCEPT
[root@doiserver root]# iptables -A FORWARD -j DROP
[root@doiserver root]# service iptables save
[root@doiserver root]# service iptables restart
[root@doiserver root]# iptables -L
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- 192.168.200.240/28 anywhere
ACCEPT all -- anywhere 192.168.200.240/28
DROP all -- anywhere anywhere
Internet Gateway Server
Squid Proxy
[root@doiserver root]# vi /etc/squid/squid.conf
~# http_port 3128 ( ก� หนดั port ให� proxy )
http_port 8080
# cache_mem 8 MB ( ก� หนดัให� squid ใชื่� mem ส่'งส่�ดัตั มตั�องก ร )cache_mem 100 MB
# cache_dir ufs /var/spool/squid 100 16 256 ( ให� squid เก*บข�อม'ล่แบบ ufs โดัยเก*บไว�ที่� /var/spool/squid ใชื่�พ��นที่� 100 MB แบ�งเป็�น 16 Dir หล่�ก แล่ะ 256 Dir ย�อย )
cache_dir ufs /var/spool/squid 1000 128 256
# cache_access_log /var/log/squid/access.log ( เก*บ log ไว�ที่�ใดั )cache_access_log /var/log/squid/access.log
#acl our_networks src 192.168.1.0/24 192.168.2.0/24 (ก� หนดั IPให� our_networks )acl our_networks src 192.168.200.240/28
#http_access allow our_networks ( อน�ญ ตัให� ip ใน our_networks ใชื่�ง น squid ไดั� )
http_access allow our_networks
# TAG: visible_hostname ( ก� หนดัชื่��อ proxy )visible_hostname doiserver~
[root@doiserver root]# squid -z2007/05/21 14:52:19| Creating Swap Directories
Squid Proxy
[root@doiserver root]# service squid start
[root@doiserver root]# netstat -tanp |grep 8080tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 15382/
[root@doiserver root]# tail -f /var/log/squid/access.log
1179734358.606 2334 192.168.200.246 TCP_MISS/200 15520 GEThttp://www.jodoi.com/ - DIRECT/72.29.87.198 text/html
1179734359.100 842 192.168.200.246 TCP_MISS/200 1770 GET http://www.jodoi.com/pic/new.gif - DIRECT/72.29.87.198 image/gif
1179734359.407 793 192.168.200.246 TCP_MISS/200 14528 GET http://www.jodoi.com/pic/puket57_1.jpg - DIRECT/72.29.87.198 image/jpeg
1179734359.742 1124 192.168.200.246 TCP_MISS/200 3100 GET http://www.jodoi.com/pic/more.bmp - DIRECT/72.29.87.198 image/bmp
Squid Proxy
Web Server
[root@doiserver root]# vi /etc/httpd/conf/httpd.conf
~
Listen 80
DocumentRoot "/var/www/html“
~
[root@doiserver root]# service httpd start
[root@doiserver root]# netstat -tanp |grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15599/httpd
http://192.168.200.249/
Web Server