Monday, June 16, 2014

tcpdump_advanced_filters

tcpdump advanced filters
========================
Source: http://www.wains.be/pub/networking/tcpdump_advanced_filters.txt

Notes :

I usually always specify the interface from which to listen.. that's the -i option you will always see in the examples.
Indeed, I have tested each rule on my laptop over the wireless adapter which is eth1.

Feel free to contact me for comments, suggestions or for reporting mistakes.
I know I'm usually terrible at explaining stuff, so let me know if something is not clear.

I'll try to keep this document updated with new useful rules.


Before I begin with advanced filters, let's review the basic syntax of tcpdump

Basic syntax :
==============

Filtering hosts :
-----------------

- Match any traffic involving 192.168.1.1 as destination or source
# tcpdump -i eth1 host 192.168.1.1

- As soure only
# tcpdump -i eth1 src host 192.168.1.1

- As destination only
# tcpdump -i eth1 dst host 192.168.1.1


Filtering ports :
-----------------

- Match any traffic involving port 25 as source or destination
# tcpdump -i eth1 port 25

- Source
# tcpdump -i eth1 src port 25

- Destination
# tcpdump -i eth1 dst port 25


Network filtering :
-------------------

# tcpdump -i eth1 net 192.168
# tcpdump -i eth1 src net 192.168
# tcpdump -i eth1 dst net 192.168


Protocol filtering :
--------------------

# tcpdump -i eth1 arp
# tcpdump -i eth1 ip

# tcpdump -i eth1 tcp
# tcpdump -i eth1 udp
# tcpdump -i eth1 icmp


Let's combine expressions :
---------------------------

Negation    : ! or "not" (without the quotes)
Concatanate : && or "and"
Alternate   : || or "or" 

- This rule will match any TCP traffic on port 80 (web) with 192.168.1.254 or 192.168.1.200 as destination host
# tcpdump -i eth1 '((tcp) and (port 80) and ((dst host 192.168.1.254) or (dst host 192.168.1.200)))'

- Will match any ICMP traffic involving the destination with physical/MAC address 00:01:02:03:04:05
# tcpdump -i eth1 '((icmp) and ((ether dst host 00:01:02:03:04:05)))'

- Will match any traffic for the destination network 192.168 except destination host 192.168.1.200
# tcpdump -i eth1 '((tcp) and ((dst net 192.168) and (not dst host 192.168.1.200)))'


Advanced header filtering :
===========================

Before we continue, we need to know how to filter out info from headers

proto[x:y]   : will start filtering from byte x for y bytes. ip[2:2] would filter bytes 3 and 4 (first byte begins by 0)
proto[x:y] & z = 0  : will match bits set to 0 when applying mask z to proto[x:y]
proto[x:y] & z !=0  : some bits are set when applying mask z to proto[x:y]
proto[x:y] & z = z  : every bits are set to z when applying mask z to proto[x:y]
proto[x:y] = z   : p[x:y] has exactly the bits set to z


Operators : >, <, >=, <=, =, !=


This may not be clear in the first place but you'll find examples below involving these.


Of course, it is important to know what the protocol headers look like before diving into more advanced filters.


IP header
---------

 0                   1                   2                   3   
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |Version|  IHL  |Type of Service|          Total Length         |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |         Identification        |Flags|      Fragment Offset    |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |  Time to Live |    Protocol   |         Header Checksum       |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |                       Source Address                          |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |                    Destination Address                        |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |                    Options                    |    Padding    | <-- --------------------="" -="" -i="" ...="" 01000101.="" 01000101="" 01000110="" 0100="4" 0101="5" 0="" 1.="" 1="69" 20="" 21st="" 2="" 32="" 4="" 5="" 64="" 69.="" 70.="" :="" a="" also="" an="" any="" anyhow="" are="" at="" be="" because="" bigger="" binary.="" bits="" blocks="" but="" byte.="" byte="" bytes.="" bytes="" calculate="" can="" case="" consider="" course.="" data="" dealing="" decimal.="" decimal="" divide="" do="" eader="" either="" equals="" ersion="" eth1="" every="" examples.="" field="" filter="" filters.="" first="" fit="" for="" had="" half...="" half="" has="" have="" header="6)," headers.="" here="" how="" i="" ideal="" if="" ihl="" in="" inside="" ip="" ipv4="" ipv6="" is="" job="" just="" kind="" know="" length="" let="" ll="" long.="" longer="" match="" matches="" need="" no="" normal="" not="" number="" of="" one="" only="" optional="" options="" or="" out="" probably="" protocol="" recap="" rule="" s="" say="" second="" set.="" set="" should="" start="" suite="" t="" tcpdump="" than="" that.="" that="" the="" these="" this="" to="" traffic="" trigger="" try="" two="" usually="" v4="4" value="" version.="" version="" want="" ways="" we="" which="" will="" with="" working="" world="" would="" x=""> 69'

Somehow, the proper way is to mask the first half/field of the first byte, because as mentionned earlier, 
this filter would match any IPv6 traffic.

2. The proper/right way : "masking" the first half of the byte

0100 0101 : 1st byte originally
0000 1111 : mask (0xf in hex or 15 in decimal). 0 will mask the values while 1 will keep the values intact.
=========
0000 0101 : final result

You should see the mask as a power switch. 1 means on/enabled, 0 means off/disabled.

The correct filter :

In binary
# tcpdump -i eth1 'ip[0] & 15 > 5'

or 

In hexadecimal
# tcpdump -i eth1 'ip[0] & 0xf > 5'

I use hex masks.

Recap.. That's rather simple, if you want to :
- keep the last 4 bits intact, use 0xf (binary 00001111)
- keep the first 4 bits intact, use 0xf0 (binary 11110000)


DF bit (don't fragment) set ?
-----------------------------

Let's now trying to know if we have fragmentation occuring, which is not desirable. Fragmentation occurs 
when a the MTU of the sender is bigger than the path MTU on the path to destination.

Fragmentation info can be found in the 7th and 8th byte of the IP header.

 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |Flags|      Fragment Offset    |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Bit 0:  reserved, must be zero
Bit 1:  (DF) 0 = May Fragment, 1 = Don't Fragment.
Bit 2:  (MF) 0 = Last Fragment, 1 = More Fragments.

The fragment offset field is only used when fragmentation occurs.

If we want to match the DF bit (don't fragment bit, to avoid IP fragmentation) :

The 7th byte would have a value of :
01000000 or 64 in decimal

# tcpdump -i eth1 'ip[6] = 64'


Matching fragmentation ?
------------------------

- Matching MF (more fragment set) ? This would match the fragmented datagrams but wouldn't match the last 
  fragment (which has the 2nd bit set to 0).
# tcpdump -i eth1 'ip[6] = 32'

The last fragment have the first 3 bits set to 0... but has data in the fragment offset field.

- Matching the fragments and the last fragments
# tcpdump -i eth1 '((ip[6:2] > 0) and (not ip[6] = 64))'

A bit of explanations :
"ip[6:2] > 0" would return anything with a value of at least 1
We don't want datagrams with the DF bit set though.. the reason of the "not ip[6] = 64"

If you want to test fragmentation use something like :
ping -M want -s 3000 192.168.1.1


Matching datagrams with low TTL
-------------------------------

The TTL field is located in the 9th byte and fits perfectly into 1 byte.
The maximum decimal value of the TTL field is thus 255 (11111111 in binary).

This can be verified :
$ ping -M want -s 3000 -t 256 192.168.1.200
ping: ttl 256 out of range

 +-+-+-+-+-+-+-+-+
 |  Time to Live |
 +-+-+-+-+-+-+-+-+

We can try to find if someone on our network is using traceroute by using something like this on the gateway :
# tcpdump -i eth1 'ip[8] < 5'


Matching packets longer than X bytes
------------------------------------

Where X is 600 bytes

# tcpdump -i eth1 'ip[2:2] > 600'


More IP filtering
-----------------

We could imagine filtering source and destination addresses directly in decimal addressing.
We could also match the protocol by filtering the 10th byte.

It would be pointless anyhow, because tcpdump makes it already easy to filter out that kind of info.


TCP header
----------

 0                   1                   2                   3   
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |          Source Port          |       Destination Port        |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |                        Sequence Number                        |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |                    Acknowledgment Number                      |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |  Data |       |C|E|U|A|P|R|S|F|                               |
 | Offset|  Res. |W|C|R|C|S|S|Y|I|            Window             | 
 |       |       |R|E|G|K|H|T|N|N|                               |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |           Checksum            |         Urgent Pointer        |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |                    Options                    |    Padding    |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |                             data                              |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

- Matching any TCP traffic with a source port > 1024
# tcpdump -i eth1 'tcp[0:2] > 1024'

- Matching TCP traffic with particular flag combinations

The flags are defined in the 14th byte of the TCP header.

 +-+-+-+-+-+-+-+-+
 |C|E|U|A|P|R|S|F|
 |W|C|R|C|S|S|Y|I|
 |R|E|G|K|H|T|N|N|
 +-+-+-+-+-+-+-+-+

In the TCP 3-way handshakes, the exchange between hosts goes like this :

1. Source sends SYN 
2. Destination answers with SYN, ACK 
3. Source sends ACK

- If we want to match packets with only the SYN flag set, the 14th byte would have a binary 
  value of 00000010 which equals 2 in decimal.
# tcpdump -i eth1 'tcp[13] = 2'

- Matching SYN, ACK (00010010 or 18 in decimal)
# tcpdump -i eth1 'tcp[13] = 18'

- Matching either SYN only or SYN-ACK datagrams
# tcpdump -i eth1 'tcp[13] & 2 = 2'

We used a mask here. It will returns anything with the ACK bit set (thus the SYN-ACK combination as well)

Let's assume the following examples (SYN-ACK)

00010010 : SYN-ACK packet
00000010 : mask (2 in decimal)
--------
00000010 : result (2 in decimal)

Every bits of the mask match !

- Matching PSH-ACK packets
# tcpdump -i eth1 'tcp[13] = 24'

- Matching any combination containing FIN (FIN usually always comes with an ACK so we either 
  need to use a mask or match the combination ACK-FIN)
# tcpdump -i eth1 'tcp[13] & 1 = 1'

- Matching RST flag
# tcpdump -i eth1 'tcp[13] & 4 = 4'

Actually, there's an easier way to filter flags :
# tcpdump -i eth1 'tcp[tcpflags] == tcp-ack'

- Matching all packages with TCP-SYN or TCP-FIN set : 
# tcpdump 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0


By looking at the TCP state machine diagram (http://www.wains.be/pub/networking/tcp_state_machine.jpg)
we can find the different flag combinations we may want to analyze.

Ideally, a socket in ACK_WAIT mode should not have to send a RST. It means the 3 way handshake has not completed.
We may want to analyze that kind of traffic.


Matching SMTP data :
--------------------

I will make a filter that will match any packet containing the "MAIL" command from SMTP exchanges.

I use something like http://www.easycalculation.com/ascii-hex.php to convert values from ASCII to hexadecimal.

"MAIL" in hex is 0x4d41494c

The rule would be :

# tcpdump -i eth1 '((port 25) and (tcp[20:4] = 0x4d41494c))'

It will check the bytes 21 to 24. "MAIL" is 4 bytes/32 bits long.. 

This rule would not match packets with IP options set.

This is an example of packet (a spam, of course) :

# tshark -V -i eth0 '((port 25) and (tcp[20:4] = 0x4d41494c))'
Capturing on eth0
Frame 1 (92 bytes on wire, 92 bytes captured)
    Arrival Time: Sep 25, 2007 00:06:10.875424000
    [Time delta from previous packet: 0.000000000 seconds]
    [Time since reference or first frame: 0.000000000 seconds]
    Frame Number: 1
    Packet Length: 92 bytes
    Capture Length: 92 bytes
    [Frame is marked: False]
    [Protocols in frame: eth:ip:tcp:smtp]
Ethernet II, Src: Cisco_X (00:11:5c:X), Dst: 3Com_X (00:04:75:X)
    Destination: 3Com_X (00:04:75:X)
        Address: 3Com_X (00:04:75:X)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
    Source: Cisco_X (00:11:5c:X)
        Address: Cisco_X (00:11:5c:X)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
    Type: IP (0x0800)
Internet Protocol, Src: 62.163.X (62.163.X), Dst: 192.168.X (192.168.X)
    Version: 4
    Header length: 20 bytes
    Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00)
        0000 00.. = Differentiated Services Codepoint: Default (0x00)
        .... ..0. = ECN-Capable Transport (ECT): 0
        .... ...0 = ECN-CE: 0
    Total Length: 78
    Identification: 0x4078 (16504)
    Flags: 0x04 (Don't Fragment)
        0... = Reserved bit: Not set
        .1.. = Don't fragment: Set
        ..0. = More fragments: Not set
    Fragment offset: 0
    Time to live: 118
    Protocol: TCP (0x06)
    Header checksum: 0x08cb [correct]
        [Good: True]
        [Bad : False]
    Source: 62.163.X (62.163.X)
    Destination: 192.168.X (192.168.XX)
Transmission Control Protocol, Src Port: 4760 (4760), Dst Port: smtp (25), Seq: 0, Ack: 0, Len: 38
    Source port: 4760 (4760)
    Destination port: smtp (25)
    Sequence number: 0    (relative sequence number)
    [Next sequence number: 38    (relative sequence number)]
    Acknowledgement number: 0    (relative ack number)
    Header length: 20 bytes
    Flags: 0x18 (PSH, ACK)
        0... .... = Congestion Window Reduced (CWR): Not set
        .0.. .... = ECN-Echo: Not set
        ..0. .... = Urgent: Not set
        ...1 .... = Acknowledgment: Set
        .... 1... = Push: Set
        .... .0.. = Reset: Not set
        .... ..0. = Syn: Not set
        .... ...0 = Fin: Not set
    Window size: 17375
    Checksum: 0x6320 [correct]
        [Good Checksum: True]
        [Bad Checksum: False]
Simple Mail Transfer Protocol
    Command: MAIL FROM:\r\n
        Command: MAIL
        Request parameter: FROM:


Matching HTTP data :
--------------------

Let's make a filter that will find any packets containing GET requests
The HTTP request will begin by :

GET / HTTP/1.1\r\n (16 bytes counting the carriage return but not the backslashes !)

If no IP options are set.. the GET command will use the byte 20, 21 and 22
Usually, options will take 12 bytes (12nd byte indicates the header length, which should report 32 bytes). 
So we should match bytes 32, 33 and 34 (1st byte = byte 0).

Tcpdump is only able to match data size of either 1, 2 or 4 bytes, we will take the following ASCII 
character following the GET command (a space)

"GET " in hex : 47455420
 
# tcpdump -i eth1 'tcp[32:4] = 0x47455420'


Matching HTTP data (exemple taken from tcpdump man page) : 

# tcpdump -i eth1 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2 -="" amp="" tcp="" xf0="">>2)) != 0)'

          +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
ip[2:2] = |          Total Length         |
   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

 +-+-+-+-+-+-+-+-+
ip[0] = |Version|  IHL  |
 +-+-+-+-+-+-+-+-+

      +-+-+-+-+-+-+-+-+
ip[0]&0xf =  |# # # #|  IHL  | <-- ---------------------------------------="" -="" -i="" 00001111="" 0="" 0x5353482d.="" 0xf="" 4="" :="" an="" any="" are="" be="" binary="" bits="" by="" bytes="" connection="" contains="" data.="" data="" doing="" eth1="" first="" for="" given="" have="" header="" here="" hex="" ihl="" in="" interesting="" ip="" is="" lenght="" length="" like="" looking="" masked="" matching="" of="" offset="" on="" openssh="" or="" other="" packet="" penssh_3.6.1p2="" port="" replies="" reply="" right="" s="" server.="" so="" something="" ssh="" taking="" tcp="" tcpdump="" that="" the="" things="" total="" usually="" value="" version="" we="" what="" will="" with="">>2):4] = 0x5353482D'

If we want to find any connection made to older version of OpenSSH (version 1, which are insecure and subject to MITM attacks) : 
The reply from the server would be something like "SSH-1.99.."

# tcpdump -i eth1 '(tcp[(tcp[12]>>2):4] = 0x5353482D) and (tcp[((tcp[12]>>2)+4):2] = 0x312E)'

Explanation of >>2 can be found below in the reference section.


UDP header
----------

  0      7 8     15 16    23 24    31  
 +--------+--------+--------+--------+ 
 |     Source      |   Destination   | 
 |      Port       |      Port       | 
 +--------+--------+--------+--------+ 
 |                 |                 | 
 |     Length      |    Checksum     | 
 +--------+--------+--------+--------+ 
 |                                   | 
 |              DATA ...             |
 +-----------------------------------+                 

Nothing really interesting here.

If we want to filter ports we would use something like :
# tcpdump -i eth1 udp dst port 53


ICMP header
-----------

See different ICMP messages :
http://img292.imageshack.us/my.php?image=icmpmm6.gif

We will usually filter the type (1 byte) and code (1 byte) of the ICMP messages.

Here are common ICMP types :

  0 Echo Reply     [RFC792]
  3 Destination Unreachable    [RFC792]
  4 Source Quench      [RFC792]
  5 Redirect     [RFC792]
  8 Echo      [RFC792]
 11 Time Exceeded     [RFC792]

We may want to filter ICMP messages type 4, these kind of messages are sent in case of congestion of the network.
# tcpdump -i eth1 'icmp[0] = 4'


If we want to find the ICMP echo replies only, having an ID of 500. By looking at the image with all the ICMP packet description
we see the ICMP echo reply have the ID spread across the 5th and 6th byte. For some reason, we have to filter out with the value in hex.

# tcpdump -i eth0 '(icmp[0] = 0) and (icmp[4:2] = 0x1f4)'


References
----------

tcpdump man page : http://www.tcpdump.org/tcpdump_man.html
Conversions : http://easycalculation.com/hex-converter.php
Filtering HTTP requests : http://www.wireshark.org/tools/string-cf.html
Filtering data regardless of TCP options : http://www.wireshark.org/lists/wireshark-users/201003/msg00024.html

Just in case the post disappears, here's a copy of the last URL :

From: Sake Blok 
Date: Wed, 3 Mar 2010 22:42:29 +0100
Or if your capturing device is capable of interpreting tcpdump style filters (or more accurately, BPF style filters), you could use:

tcp[(((tcp[12:1] & 0xf0) >> 2) + 8):2] = 0x2030

Which in English would be: 
- take the upper 4 bits of the 12th octet in the tcp header ( tcp[12:1] & 0xf0 )
- multiply it by four ( (tcp[12:1] & 0xf0)>>2 ) which should give the tcp header length
- add 8 ( ((tcp[12:1] & 0xf0) >> 2) + 8 ) gives the offset into the tcp header of the space before the first octet of the response code
- now take two octets from the tcp stream, starting at that offset ( tcp[(((tcp[12:1] & 0xf0) >> 2) + 8):2]  )
- and verify that they are " 0" ( = 0x2030 )

Of course this can give you false positives, so you might want to add a test for "HTTP" and the start of the tcp payload with:

tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x48545450

resulting in the filter:

tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x48545450 and tcp[(((tcp[12:1] & 0xf0) >> 2) + 8):2] = 0x2030

A bit cryptic, but it works, even when TCP options are present (which would mess up a fixed offset into the tcp data).

Enjoy!
Pond

Thursday, November 25, 2010

How To Install And Configure Advanced Policy Firewall (APF)

พอดีเจอมาจาก thaihosttalk คับ

#wget http://www.rfxnetworks.com/downloads/apf-current.tar.gz tar -xvzf
#apf-current.tar.gz cd apf-* ./install.sh
#perl -pi -e 's/IG_TCP_CPORTS="22"/ \
IG_TCP_CPORTS="21,22,25,53,80,443,110,143,587,993,995,2222"/' /etc/apf/conf.apf 
#perl -pi -e 's/IG_UDP_CPORTS=""/IG_UDP_CPORTS="20,21,53,123"/' /etc/apf/conf.apf 
#perl -pi -e 's/DEVEL_MODE="1"/DEVEL_MODE="0"/' /etc/apf/conf.apf 
#/etc/init.d/apf restart

Tuesday, June 8, 2010

ตัวอย่างการทำ rsync

การทำ rsync กันระหว่างเครื่องที่เป็น FreeBSD และ Debian
นะครับ สามารถไปประยุกต์ใช้ ระหว่าง OS Unix ตัวอื่นได้เหมือนกัน .. เริ่มกันเลยครับ
ฝั่ง Server
Step 1: Install rsync
freebsd-1# cd /usr/ports/net/rsync
freebsd-1# make install clean
Step 2: Config rsyncd.conf
freebsd-1# vi /usr/local/etc/rsyncd.conf
ใส่ข้อมูลไปดังนี้ครับ
[www]
comment = web server backup
path = /home/ton # ตรงนี้เป็น path ของ server ที่เราต้องการ backup
auth users = ton # user ที่ใช้ในการ Authen
uid = ton
gid = ton
secrets file = /usr/local/etc/rsyncd.secrets # ที่เก็บ file สำหรับเก็บ user-passwd
read only = no
Step 3: Create rsyncd.secrets
freebsd-1# vi /usr/local/etc/rsyncd.secrets
ใส่
ton:123456
freebsd-1# chmod 600 /usr/local/etc/rsyncd.secrets
Step 4: Edit rc.conf
freebsd-1# vi /etc/rc.conf
ใส่
rsyncd_enable=”YES”
Step 5: Start Rsync daemon
freebsd-1# /usr/local/etc/rc.d/rsyncd start
Step 6: Rsync daemon ลองดูว่ามี daemon ประมาณนี้หรือยัง
freebsd-1# sockstat | grep rsync
root rsync 60398 3 dgram -> /var/run/logpriv
root rsync 60398 4 tcp6 *:873 *:*
root rsync 60398 5 tcp4 *:873 *:*
ถ้ามีก็เป็นอันเรียบร้อยแล้วครับสำหรับฝั่ง Server ของเรา
ฝั่ง Client
Step 1: Install rsync
debian-client# apt-get install rsync
Step 2: Test rsync
debian-client# rsync -avz -e ssh ton@server1.example.com:/home/ton/ /home/ton/
Step 3: Create The Keys On mirror.example.com
debian-client# mkdir /root/rsync
debian-client# ssh-keygen -t dsa -b 1024 -f /root/rsync/mirror-rsync-key
Generating public/private dsa key pair.
Enter passphrase (empty for no passphrase):
<– Enter
Enter same passphrase again:
Your identification has been saved in /root/rsync/mirror-rsync-key.
Your public key has been saved in /root/rsync/mirror-rsync-key.pub.
The key fingerprint is:
6c:34:c9:29:cf:16:a3:c8:72:c0:28:b3:c6:61:75:a2 root@www
<– Enter
Step 4: Copy our public key to server1.example.com:
debian-client# scp /root/rsync/mirror-rsync-key.pub ton@server1.example.com:/home/ton/
กลับมาดูที่ฝั่ง Server อีกครั้งครับ
Step 7: Create authorized_keys
(Login as ton!)
freebsd-1# mkdir ~/.ssh
freebsd-1# chmod 700 ~/.ssh
freebsd-1# mv ~/mirror-rsync-key.pub ~/.ssh/
freebsd-1# cd ~/.ssh
freebsd-1# touch authorized_keys
freebsd-1# chmod 600 authorized_keys
freebsd-1# cat mirror-rsync-key.pub >> authorized_keys
Step 8: Connect from mirror.example.com only
(Still as ton!)
freebsd-1# vi /home/someuser/.ssh/authorized_keys
ใส่ เข้าไปก่อนข้อความใน file เดิม
command=”/home/ton/rsync/checkrsync”,from=”mirror.example.com”,no-port-forwardin
g,no-X11-forwarding,no-pty
ตอนนี้ก็เป็นอันเสร็จแล้วครับสำหรับฝั่ง Server เราจะสามารถใช้ rsync ผ่าน sshd ได้
โดยไม่ต้องใส่ user - password ทำให้สะดวกขึ้นเวลาทำ auto backup
มาดูที่ฝั่ง Client กันอีกครั้งครับ
Step 5: Test rsync
debian-client# rsync -avz –delete -e “ssh -i /root/rsync/mirror-rsync-key”
ton@server1.example.com:/home/ton/ /home/ton/
Step 6: Create crond job
debian-client# crontab -e
ใส่
*/5 * * * * /usr/bin/rsync -azq –delete -e “ssh -i /root/rsync/mirror-rsync-key”
ton@server1.example.com:/home/ton/ /home/ton/
ก็เสร็จแล้วครับสำหรับการทำ rsync ระหว่าง FreeBSD กับ debian

Monday, June 7, 2010

Screen command

คำสั่ง screen

คำสั่ง screen คือคำสั่งที่เก็บ session ของงานไว้โดนที่เราสามารถเรียกมาดูใหม่ได้ถึงแม้จะปิด terminal นั้นทิ้งไปแล้ว

วิธีใช้

ขั้นแรกต้องสร้าง ~/.screenrc ก่อนดังนี้
# use visual bell
vbell on
# replace ctrl-A by ctrl-O
escape ^Oo
# set a big scrolling buffer
defscrollback 5000
# Set the caption on the bottom line
caption always "%{= kw}%-w%{= BW}%n %t%{-}%+w %-= @%H - %LD %d %LM - %c"
  • เวลาเรียกใช้งานเรียก
screen
  • พอเรียกเสร็จจะมีหน้าจอโปรแกรม screen ให้เรากด space หรือ enter จากนั้นเราจะได้ prompt ใหม่ซึ่งเป็น prompt จากคำสั่ง screen
  • เรียกใช้โปแกรมภายใต้คำสั่ง screen ต่อได้เลยเช่น
irssi
  • ถ้าใช้เสร็จแล้วอยามf
กจะปิด connectin ก็กด ปิด terminal นั้นไปเลย หรือกด shot key
ctrl+o d
  • ถ้าต้องการกลับมาแสดงหน้าจอของโปรแกรมที่เรียกค้างไว้ให้สั่ง
screen -r -d

การใช้งานขั้นสูง

  • เราสามารถเปิด session ของscreen ได้หลายๆอันเช่นหน้าแรกเปิด irssi หน้าสองเปิด top แต่อยู่ใน terminal เดียวกันทำได้ดังนี้
screen
irssi
    • หลังจากสั่ง2คำสั่งแล้ว ให้กดshotcut ตามนี้ เพื่อสร้าง session ใหม่
ctrl+o c 
    • จากนั้นสั่งคำสั่งต่อไปเลย
top
    • จะเห็นได้ว่าตรงบรรทัดล่างสุดจะมีบอกว่า มีหน้า 1,2 โผล่ขึ้นมา
    • การสลับหน้าจอระหว่าง 1 และ 2 ทำดังนี้
ctrl+o n
ctrl+o p

การใช้งาน Rsync

การใช้งาน Rsync


Rsync เป็นทูลที่ใช้ในการแบ็คอัพหรือก็อปปี้ ( mirror ) สามารถทำการดาวน์โหลดหรืออัพโหลดได้ ลักษณะ การทำงานจะคล้ายๆ 
กับ FTP+tar Utility แต่จะมีความคล่องสูงมาก เหมาะสำหรับงาน Backup,Mirror โดยมีความสามารถต่างๆ คร่าวๆดังนี้
*สนับสนุนการแบ็คอัพทั้งแบบ Incremental และ แบบ Full *มีระบบการป้องกันความปลอดภัยสนับสนุนภายในตัว *สามารถุกำหนดผู้ใช้และรหัสผ่านเพื่อใช้งานโดยที่ไม่จำเป็นที่จะต้องเป็น user จริงๆ ในระบบ *สามารถกำหนดรูปแบบการทำงานให้เป็นในลักษณะอ่านอย่างเดียว หรือ เขียนอย่างเดียว หรือ ทั้งอ่านทั้งเขียน ได้เพื่อความคล่องตัว *กำหนดระดับผู้ใช้ให้สามารถที่ทำงานได้ *เพื่อความยืดหยุ่นในการทำงานสามารถกำหนดพอร์ทการทำงานได้ *etc.. :)
เมื่อกำหนดค่าต่างๆ เรียบร้อยแล้ว ก็สามารถเรียกให้ทำงานได้ทันทีโดยเรียกคำสั่งผ่านทางคอมมาน์ไลน์ได้โดยตรง
หรือกำหนดให้ทำงานผ่าน inetd หรือ xinetd ได้ โดยใน FedoraCORE นั้นสามารถเรียกการทำงานผ่านระบบ xinetd
โดยเข้าไปแก้ที่ file ใน /xinetd.d/rsync
ขั้นตอนการทำงาน
1. สร้างคอนฟิกไฟล์ขึ้นมาเพื่อใช้กำหนดการทำงานของ  server และ secret 
ไฟล์ที่จะใช้เพื่อเก็บผู้ใช้ที่จะทำการตรวจสอบสิทธิการใช้งานในกรณีนี้ ผมสร้างไดเรกทอรี่ rsync.d ขึ้นมาเพื่อใช้เก็บคอนฟิกไฟล์ดังกล่าว root# mkdir /etc/rsync.d root# cd /etc/rsync.d root# touch rsyncd.conf root# ln -s /etc/rsyncd.d/rsyncd.conf /etc/rsyncd.conf
2.กำหนดค่าต่างๆ เข้าไปในไฟล์ rsyncd.conf เพื่อกำหนดสภาวะแวดล้อมการทำงานของ rsync server 
รูปแบบของการกำหนดหนดไฟล์จะแบ่งเป็น ส่วนๆ คล้ายๆ การกำหนดค่าของ samba ข้างล่างยกตัวอย่าง การคอนฟิกค่าเพื่อจะใช้ Backup Mail Spool Directory
log file = /var/log/rsync.log port = 8002

[ MailSPool ]
comment = Directory Mail Spool Mail  
use chroot = true
uid = root
gid = root
path = /var/spool/mail/
use chroot = true
max verbosity = 2
read only = true
auth users = rsyncuser
secrets file = /etc/rsync.d/rsyncd.secrets
hosts allow = 192.168.0.1/24
exclude = somefile >> บางไฟล์ที่ไม่ต้องการ Backup
[ testbackup ]
commment = test backup rsync
........
comment  = ใช้กำหนดคำอธิบายเพื่อสามารถที่จะอธิบายได้ว่าไดเรกทอรี่นี้มีเพื่ออะไรเพื่อที่จะบอกรายละเอียดเพิ่มเติม
 use chroot = เมื่อกำหนดออปชั่นนี้แล้วลักษณะการเชื่อมต่อเข้าไปจะใช้รูปแบบ chroot ช่วยเพิ่มความปลอดภัยยิ่งขึ้น
 uid = user id ที่เราต้องการให้ทำการทำงาน 
 gid = group id คือ id ที่เราต้องการให้ผู้ใช้ภายใต้กลุ่มนั้นๆ มาใช้งาน
 path = directory ที่เราต้องการทำงานด้วย
 max verbosity = กำหนดรายละเอียดการ debug ลงไปใน log file มีประโยชน์เมื่อเราต้องการติดตามดูความผิดพลาดต่างๆ
ก็สามารถจะช่วยได้ดีทีเดียว
read only = กำหนดให้เป็นสถานะอ่านอย่างเดียวหรือไม่ โดยปกติแล้ว ค่าโดยปกติจะเป็นอนุญาติให้อ่านได้อย่างเดียว
auth users = กำหนดผู้ใช้ที่จะทำการตรวจสอบซึ่งเก็บไว้ใน rsyncd.secret
secrets file = ไฟล์ที่ใช้เก็บข้อมูลของผู้ที่เราจะใช้ในการตรวจสอบสิทธิ โดยลักษณะเป็น เท็กซ์ไฟล์ธรรมดา
host allow = กำหนดสิทธิได้ในระดับเครือข่ายหรือ host ที่เราจะอนุญาติให้ทำการ คอนเนกต์เข้ามาได้
exclude = ยกเว้น ไฟล์ใดๆ ที่เราไม่ต้องการให้มีการ backup 
log file = กำหนดไฟล์ที่ใช้เก็บล็อก
port = กำหนด พอร์ทการทำงานจากปกติ 833
หากต้องการกำหนดไดเรกทอรี่ใดๆ ขึ้นอีก ก็สามารถเพิ่มเข้าไปได้ โดยจะกำหนดเป็น section ๆ ไป
3. สั่งให้ทำงานได้ทันที
โดยหากเป็นการกำหนดให้ทำงานผ่านทาง commandline ก็สั่งได้โดยตรงโดยใช้คำสั่ง
root# rsync --daemon
หรือหากเป็น Fedora ก็เข้าไปที่ไดเรกทอรี่ /etc/xinetd.d เข้าไปแก้ไขไฟล์ที่ชื่อว่า rsync
               root# cd /etc/xinetd.d
root# vi rsync
  1. default: off
  2. description: The rsync server is a good addition to an ftp server, as it \
  3. allows crc checksumming etc.
service rsync { disable = yes << เปลี่ยนตรงนี้ให้เป็น no socket_type = stream wait = no user = root server = /usr/bin/rsync server_args = --daemon log_on_failure += USERID }
3. สั่งให้มันทำงาน root# service xinetd restart 4. พร้อมทำงานได้เลยทันที :)
ทีนี้มายังฝั่ง ไคลเอ็นต์กันบ้าง
โดยปกติแล้วเราสามารถกำหนดได้ว่าจะทำการ backup เมื่อไหร่และอย่างไร ในกรณีนี้ผมทำเป็น bash script 
เพื่อสะดวกในการเรียกใช้งาน (เพราะคำสั่งยาวพอสมควาร :p ) นอกจากจะสามารถกำหนดว่าให้ทำงานได้ทันที หรือ กำหนดระยะเวลาการทำงาน ( cron job ) โดยมีรูปแบบตัวอย่างดังนี้
ส่วนรายละเอียดเพิ่มเติม จะขอมาเพิ่มเติมภายหลังนะครับเรื่องการกำหนดฝั่งการทำงานของ ไคล์เอนต์ 
พอดีไม่ค่อยว่างหรือสะดวกที่จะเขียน สักเท่าไหร่ อย่างไรก็ดี ก็อยากให้พี่ๆ น้อง ๆ ที่ใช้งาน linux สามารถมาเพิ่มเติมหรือว่า ลบทิ้งก็ได้นะครับ ( กรณีที่ผิดพลาด หรือ ลบหมดเพื่อแก้ไข :p ) และหากผิดพลาดขาดตกบกพร่องประการใดขออภัยด้วยครับ ซึ่งหากจบเรื่องนี้แล้ว ก็กะจะพูดต่อเรื่องการ import ระบบ mail ที่เป็น mbox format และระบบเมล์เก่าๆ มาใช้กับ dovecot (maildir ) ครับ
ขอบคุณครับ
    • หากรูปแบบ layout ดูประหลาดๆ ขออภัยด้วยครับ พอดีเพิ่งเคยน่ะครับ ขออภัยด้วยครับ

Sunday, April 25, 2010

Day2.1 - How to setup mail server via Postfix

Email Server คือ เครื่องบริการรับ-ส่งจดหมายสำหรับสมาชิก บริการที่มีให้ใช้เช่น ส่งจดหมาย รับจดหมาย ส่ง attach file
ในการส่ง E-mail นั้นจะต้องอาศัย Protocol ที่ชื่อ SMTP (Simple Mail Transfer Protocol) เป็นตัวกลางในการรับและส่ง E-mail แต่ละฉบับ โปรแกรมที่ทำหน้าที่คอยรับการสื่อสารทาง SMTP นั้นมีหลายตัวด้วยกัน เช่น Sendmail, Postfix, qmail, smail, Microsoft Exchange, Lotus Note เป็นต้น โดยปรกติ SMTP จะรอรับการติดต่ออยู่ที่ Port 25 อยู่แล้ว

SMTP
เป็นโปรโตคอลที่ใช้ในการส่งอีเมล์ไปยังเมล์ เซิร์ฟเวอร์ เช่น เมื่อเราส่งอีเมล์หา Billgates@microsoft.com ขั้นแรกเราต้องส่งอีเมล์เข้าเมล์เซิร์ฟเวอร์ของหน่วยงานเรา ซึ่งเมล์เซิร์ฟเวอร์จะเปิดบริการ SMTP รอรับไว้บน TCP port 25 จากนั้นเมล์เซิร์ฟเวอร์ของหน่วยงานเราจะส่งไปให้เมล์เซิร์ฟเวอร์ของ ไมโครซอฟท์ อาจจะต้องส่งเข้าเครื่อง mail.microsoft.com หรือ mail2.microsoft.com ก็ได้ แล้วแต่ค่าที่มีอยู่ใน MX Record ซึ่งรายละเอียดเกี่ยวกับโปรโตคอล SMTP จะได้ศึกษากันในบทที่เกี่ยวกับเมล์เซิร์ฟเวอร์


POP
ถูกออกแบบสำหรับการเข้าถึงแบบ offline คือ จดหมายอยู่ใน server และผู้ใช้สามารถใช้โปรแกรมที่สนับสนุน POP ในการเข้าถึงจดหมายจากระยะไกล การจัดการใดๆ กับจดหมายจะเป็นการจัดการในเครื่องของผู้ใช้เท่านั้น ถึงแม้ว่าข้อจำกัดของการเข้าถึงแบบ offline จะทำให้เกิดความคิดที่จะทำให้ POP สามารถใช้งานในแบบ online หรือ แบบ disconnected ได้ แต่ POP ขาดคุณสมบัติที่จำเป็นบางอย่าง ส่วนการเข้าถึงแบบเสมือน online (pseudo-online) จดหมายจะไม่ถูกลบออกจาก server แต่ก็ไม่ใช่การเข้าถึงแบบ online ที่แท้จริง เพราะขาดโปรโตคอลในการเข้าถึงระบบไฟล์ในเครื่อง server ในการที่จะเข้าถึงหรือเปลี่ยนแปลง folder หรือ สถานะต่างๆ ของจดหมาย ตัวอย่างเช่น การตั้งค่าสถานะของจดหมาย เช่นได้ถูกอ่านแล้ว จะถูกตั้งค่าเพียงแค่ในเครื่องไคลเอนท์ที่ใช้เท่านั้น แต่สถานะของจดหมายที่แท้จริงบนเซิร์ฟเวอร์ยังคงไม่เปลี่ยนแปลง หรือการจัดเก็บจดหมายลง folder จะถูกจัดเก็บลงในเครื่องไคลเอนท์เท่านั้น ซึ่งที่จริงควรจะจัดเก็บไว้บนเซิร์ฟเวอร์ เพราะหากว่ามีการใช้ไคลเอนท์เครื่องอื่น ก็ยังสามารถเห็น folder นั้นๆได้


IMAP
 มีความสามารถในการเข้าถึงทั้งแบบ offline และแบบ online โดยในแบบ online จดหมายจะไม่ถูกดึงมา แต่จะเป็นแบบโต้-ตอบกับ server นั่นคือผู้ใช้สามารถดึงเฉพาะหัวข้อจดหมาย , บางส่วนของจดหมาย หรือค้นหาจดหมายที่ตรงความต้องการ โดยจดหมายที่ถูกเก็บไว้บน server และสามารถตั้งค่าสถานะของจดหมายต่างๆ เช่น ถูกลบไปแล้ว , ตอบไปแล้ว และจะยังอยู่ใน server จนกว่าผู้ใช้จะสั่งลบ อธิบายง่ายๆ คือ IMAP ถูกออกแบบให้การเข้าจดหมายจากระยะไกลเหมือนกับการเข้าถึงจดหมายจากภายใน เครื่องของผู้ใช้เอง ซึ่งขึ้นอยู่กับโปรแกรมที่ใช้ว่าจะเก็บจดหมายไว้ในเครื่องของผู้ใช้เอง หรือเก็บไว้ใน server หรือให้ผู้ใช้เลือกเองอย่างใดอย่างหนึ่ง 
note:
webmail ส่วนมากนั้นจะเป็น imap


สรุปความแตกต่างระหว่าง offline และ online
1. ความแตกต่างในแง่การใช้งาน
offline
: เหมาะกับการเข้าถึงโดยใช้คอมพิวเตอร์เครื่องเดียว และไม่ต้องการความสามารถพิเศษอื่นๆ
online
: เหมาะกับการเข้าถึงแบบตอบโต้กับ server และมีความสามารถในการเข้าถึง mailbox หลายๆอัน
2. ข้อดีของแบบ offline
        ใช้ เวลาในการติดต่อน้อย ใช้ทรัพยากรของระบบน้อย
3. ข้อดีของแบบ online
        สามารถ เข้าถึงจดหมาย จากคอมพิวเตอร์เครื่องใดก็ได้ ในเวลาใดๆ เหมาะสำหรับเครื่องที่มีเนื้อที่ดิสค์น้อย เช่น เครื่องคอมพิวเตอร์ในห้องปฏิบัติการ
ไม่ขึ้นกับ platform ในการเข้าถึง mailbox หลายๆ อัน ผู้ใช้หลายคนสามารถทำการใช้ mailbox เดียวกันได้ในเวลาเดียวกัน
จุดสำคัญก็คือ ในแบบ online สามารถเข้าถึงได้จากคอมพิวเตอร์หลายๆเครื่องในเวลาใดๆ โดยไม่ขึ้นกับโปรโตคอลในการเข้าถึงระบบไฟล์ในเครื่อง server (ซึ่งอาจไม่มีในทุก platform และอาจมีปัญหาเกี่ยวกับประสิทธิภาพ และ file locking) ถึงแม้ว่าความสามารถนี้ไม่มีความจำเป็นสำหรับผู้ใช้ที่ใช้เครื่อง คอมพิวเตอร์เพียงเครื่องเดียว ในการเข้าถึงจดหมาย แต่จะจำเป็นมากสำหรับผู้ใช้ที่ใช้คอมพิวเตอร์หลายๆ เครื่อง

ความสามารถในส่วนที่มีทั้งใน POP และ IMAP  สนับสนุนการเข้าถึงแบบ offline จดหมายใหม่จะถูกส่งไปเก็บไว้ยังเครื่อง server รอผู้ใช้ติดต่อเข้าไปตรวจเช็ค สามารถเข้าถึงจดหมายได้จาก platfrom หลากหลายรูปแบบ สามารถเข้าถึงได้จากทุกๆ ที่ในเครือข่าย เป็นโปรโตคอลแบบเปิด ซึ่งเป็นไปตาม Internet RFCs มีเครื่องมือ (Implementations) ต่างๆ (รวมทั้งซอร์สโค้ด) แจกฟรี มีโปรแกรมสำหรับการเข้าถึงจดหมายทั้งใน PC,Mac และ UNIX มีเครื่องมือ (Implementations) ต่างๆ ขาย ไม่ต้องการ SMTP mail gateways ถูกใช้ในการเข้าถึงจดหมายเท่านั้น ส่วนการส่งจะใช้ protocol SMTP สนับสนุน persistent message IDs (สำหรับการเข้าถึงแบบ disconnected) ข้อดีของโปรโตคอล POP ไม่ซับซ้อน จึงง่ายในการ Implement มีโปรแกรมสนับสนุนจำนวนมาก
ข้อดีของโปรโตคอล IMAP สามารถจัดการกับสถานะของจดหมาย (status flags) เช่น อ่านแล้ว,ลบแล้ว,ตอบแล้ว หรือ สถานะใดๆที่ผู้ใช้กำหนดเอง
สามารถเพิ่มจดหมายลงใน folder ที่ต้องการ สามารถเข้าถึง และจัดการกับ mailbox ได้หลายอัน รวมทั้งสามารถเปลี่ยนชื่อ,สร้าง,ลบ,แสดงรายชื่อ และเข้าถึง folder ต่างๆ นอกเหนือจาก folder จดหมายปกติ (Inbox) ซึ่ง folder เหล่านี้อาจจะไม่ได้อยู่บน server เดียวกันก็ได้ โดยเราสามารถเรียกดูได้พร้อมๆกัน หรือทำการเคลื่อนย้ายจาก folder หนึ่งไปยังอีก folder หนึ่ง ผู้ใช้หลายคนสามารถทำการเข้าถึง mailbox เดียวกันพร้อมกัน โดยเมื่อผู้ใช้คนใดทำการแก้ไขอะไรไป ผู้ใช้คนอื่นๆ ก็จะเห็นการแก้ไขนั้นๆ ในทันที สามารถเข้าถึงข้อมูลที่ไม่จำกัดแค่ e-mail แต่สามารถเข้าถึงข้อมูลชนิดอื่นด้วย เช่น NetNews,Documents สนับสนุนการเข้าถึงแบบ offline ในกรณีที่เชื่อมต่อผ่านทาง dialup ที่มีราคาต่อนาทีสูง โดยไม่ต้องการความสามารถพิเศษอื่นๆ หรือในกรณีที่เครื่อง server มีความสามารถต่ำ แต่ไม่ใช่ทุกโปรแกรมที่สนับสนุน IMAP สามารถทำได้ แต่โดยโปรโตคอล IMAP แล้วสามารถทำได้ 


มีโปรโตคอลในการจัดเก็บข้อมูลส่วนตัวของผู้ใช้แต่ละคนลงในเซิร์ฟเวอร์ เช่น Internet Message Support Protocol (IMSP) ซึ่งทำให้ผู้ใช้จาก platform ใดๆ สามารถเข้าถึงข้อมูลส่วนบุคคลของตนเอง เช่น สมุดรายชื่อที่อยู่ (address book) ทางเลือกใหม่ที่ทรงประสิทธิภาพก็คือ Application Configuration Access Protocol (ACAP) โปรโตคอลที่ไม่เพียงแต่ช่วยให้สร้าง หรือเก็บออบชัน และ address-book information ที่เลือกไว้แล้วเท่านั้น แต่ยังสร้างโพรซีเจอร์เพื่อจัดการกับผู้ใช้อื่นที่เกี่ยวข้อง ที่ถูกแชร์ร่วมกัน เช่น spelling check เป็นต้น
ปรับปรุงประสิทธิภาพในการเข้าถึงโดยเมื่อทำการติดต่อผ่านทางสายสื่อสารความ เร็วต่ำ โดย IMAP มีความสามารถในการเลือกดึงบางส่วน หรือ ทั้งหมดของจดหมายที่ต้องการ หรือให้ server ค้นหาจดหมายที่ต้องการให้ โดยมันจะเป็นประโยชน์อย่างมาก หากการติดต่อผ่านสื่อสารที่ช้ามาก ในการเลือกที่จะดึงเฉพาะบางส่วนของจดหมาย เช่น หัวข้อจดหมาย (header) โดยเฉพาะหากจดหมายนั้นเป็นจดหมายชนิด MIME (Multipurpose Internet Mail Externsions ซึ่งเป็นมาตรฐานในการส่งแฟ้มข้อมูลติดไปกับจดหมายตาม RFC-822 โดยโปรโตคอล SMTP) ซึ่งหากมีการส่งแฟ้มขนาดใหญ่ติดมากับจดหมายด้วย โดยมีส่วนของจดหมายเพียงไม่กี่บรรทัดจะทำให้เสียเวลาในการดึงข้อมูลที่ยัง ไม่ต้องการ เป็นอย่างมาก โดยเฉพาะเมื่อทำการติดต่อผ่านทางสายสื่อสารความเร็วต่ำ หรือค่าใช้จ่ายในการติดต่อมีราคาแพง และนี่เป็นข้อดีที่แสดงให้เห็นว่า IMAP เหนือกว่า POP 


Install Postfix mail server to enable IMAP and POP 

สิ่งที่ต้องการ
- Linux Server with Centos 4/5 (VPS or Dedicated)
- Apache 2 with PHP4 or later
- Postfix (SMTP server or MTA)
- Dovecot ( IMAP/POP3 server)
- Squirrelmail (A free Webmail)
เราจะเซ็ตอัฟอีเมล์เซิฟเวอร์เพื่อให้ไคล์เอ็นต์ใช้งานติดต่อเมล์บ๊อกของพวกเขาผ่านทางเว็ปเมล์ หรือ outlook express หรือ thunderbird. เราจะเซ็ตอัฟให้พวกเขาแบบง่ายๆ




Sunday, February 7, 2010

IT Hardware asset project.

I'd like to tell you about a project that my team finished last month. The IT Hardware asset of project to produce website to help accounting employees can track computer asset information.




To be continued...