โปรแกรมบน Linux เพื่อใช้มอนิเตอร์และแก้ปัญหา VoIP

โปรแกรมบน CentOS ที่ควรติดตั้งใช้งานร่วมกับ VoIP Server

โปรแกรมบน Linux เพื่อใช้มอนิเตอร์และแก้ปัญหา VoIP

โพสต์โดย jubjang » 19 ธ.ค. 2009 11:49

ผมจะมาแนะนำโปรแกรมบน Linux ที่ผมชอบใช้เวลาจะมอนิเตอร์ และแก้ปัญหาการใช้งาน VoIP โดยเฉพาะแบบ SIP ครับ โปรแกรมที่ผมว่านี้อยู่ด้วยกัน 2 โปรแกรมครับ คือ

Note! จริงๆแล้วโปรแกรมเหล่านี้เขาทำขึ้นมาเพื่อใช้มอนิเตอร์ปัญหาของเน็ตเวอร์คครับ สามารถมอนิเตอร์ได้ทุกโปรโตคอลที่มีใช้บนเน็ตเวอร์คไม่เฉพาะแต่ VoIP นะครับ แต่ผมจะแนะนำการใช้โปรแกรมเหล่านี้กับ VoIP

1. Wireshark for Linux เป็นโปรแกรมตัวเดียวกันกับ Wireshark for Windows นั่นแหล่ะครับ แค่ตัวนี้ทำงานบน Linux และเวลาจะใช้งานก็ต้องสั่งผ่านคอมมานด์ไลน์แทน เราจะดูผลลัพท์จากหน้าจอเลยก็ได้ (แบบเรียลไทม์) หรือว่าจะเซฟเป็นไฟล์แล้วดาวน์โหลดออกมาแล้วส่งให้คนอื่นต่อหรือเปิดในโปรแกรม Wireshark for Windows ก็ได้ครับ

Note! ที่จริงโปรแกรม Wireshark นี้นะครับ มาจากโปรแกรมชื่อ Ethereal แต่ได้มีการพัฒนาและเปลี่ยนหน้าตาไป


2. Ngrep
เป็นโปรแกรมที่คล้ายๆกับโปรแกรมแรกครับ เป็นคอมมานด์ไลน์เหมือนกัน ตอนสั่งงานก็คล้ายๆกัน แต่ผลที่ได้มันละเอียดมากกว่า

1 ติดตั้งและใช้งานโปรแกรม Wireshark

1.1 ติดตั้งโดยใช้คำสั่ง Yum
yum -y install wireshark

รอจนติดตั้งเสร็จ

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

tethereal -help

TShark 1.0.8
Dump and analyze network traffic.
See http://www.wireshark.org for more information.

Copyright 1998-2009 Gerald Combs <gerald@wireshark.org> and contributors.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Usage: tshark [options] ...

Capture interface:
-i <interface> name or idx of interface (def: first non-loopback)
-f <capture filter> packet filter in libpcap filter syntax
-s <snaplen> packet snapshot length (def: 65535)
-p don't capture in promiscuous mode
-y <link type> link layer type (def: first appropriate)
-D print list of interfaces and exit
-L print list of link-layer types of iface and exit

Capture stop conditions:
-c <packet count> stop after n packets (def: infinite)
-a <autostop cond.> ...duration:NUM - stop after NUM seconds
filesize:NUM - stop this file after NUM KB
files:NUM - stop after NUM files
Capture output:
-b <ringbuffer opt.> ... duration:NUM - switch to next file after NUM secs
filesize:NUM - switch to next file after NUM KB
files:NUM - ringbuffer: replace after NUM files
Input file:
-r <infile> set the filename to read from (no pipes or stdin!)

Processing:
-R <read filter> packet filter in Wireshark display filter syntax
-n disable all name resolutions (def: all enabled)
-N <name resolve flags> enable specific name resolution(s): "mntC"
-d <layer_type>==<selector>,<decode_as_protocol> ...
"Decode As", see the man page for details
Example: tcp.port==8888,http
Output:
-w <outfile|-> set the output filename (or '-' for stdout)
-C <config profile> start with specified configuration profile
-F <output file type> set the output file type, default is libpcap
an empty "-F" option will list the file types
-V add output of packet tree (Packet Details)
-S display packets even when writing to a file
-x add output of hex and ASCII dump (Packet Bytes)
-T pdml|ps|psml|text|fields format of text output (def: text)
-e <field> field to print if -Tfields selected (e.g. tcp.port); this option can be repeated to print multiple fields
-E<fieldsoption>=<value> set options for output when -Tfields selected:
header=y|n switch headers on and off
separator=/t|/s|<char> select tab, space, printable character as separator
quote=d|s|n select double, single, no quotes for values
-t ad|a|r|d|dd|e output format of time stamps (def: r: rel. to first)
-l flush standard output after each packet
-q be more quiet on stdout (e.g. when using statistics)
-X <key>:<value> eXtension options, see the man page for details
-z <statistics> various statistics, see the man page for details

Miscellaneous:
-h display this help and exit
-v display version info and exit
-o <name>:<value> ... override preference setting

1.3 ลองใช้คำสั่งจริง
มอนิเตอร์พอร์ต 5060 บนการ์ดแลน ethernet 0 บนเซอร์เวอร์

tetherneal -d eth0 port 5060

จะแสดงข้อมูลที่เกี่ยวข้องกับพอร์ต 5060 บนเครื่องที่เรากำลังมอนิเตอร์อยู่ (ไม่ระบุไอพีแสดงว่าเป็นเครื่องเซอร์เวอร์เอง) ว่ามีไอพีอะไรที่คอนเน็คกับพอร์ต 5060 บนเครื่องเซอร์เวอร์บ้าง เวลาจะยกเลิกมอนิเตอร์ ให้กดปุ่ม "Ctrl+C" ครับ

tethereal -i eth0 port 5060

Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
0.000000 202.170.255.19 -> 58.11.74.211 SIP Request: OPTIONS sip:88888@58.11.74.211:5060
0.000051 202.170.255.19 -> 58.8.117.188 SIP Request: OPTIONS sip:88888@58.8.117.188:5060
0.000110 202.170.255.19 -> 58.11.74.211 SIP Request: OPTIONS sip:88888@58.11.74.211:5060
0.195956 58.10.36.45 -> 202.170.255.19 SIP Request: REGISTER sip:202.170.255.19
0.196093 202.170.255.19 -> 58.10.36.45 SIP Status: 100 Trying (0 bindings)
0.196107 202.170.255.19 -> 58.10.36.45 SIP Status: 401 Unauthorized (0 bindings)
0.267137 58.10.36.45 -> 202.170.255.19 SIP Request: REGISTER sip:202.170.255.19
0.267212 202.170.255.19 -> 58.10.36.45 SIP Status: 100 Trying (0 bindings)
0.269358 202.170.255.19 -> 58.10.36.45 SIP Request: OPTIONS sip:063935683499@192.168.1.39:5061
0.269943 202.170.255.19 -> 58.10.36.45 SIP Status: 200 OK (1 bindings)
0.341545 58.10.36.45 -> 202.170.255.19 SIP Status: 200 OK
0.999900 202.170.255.19 -> 58.11.74.211 SIP Request: OPTIONS sip:88888@58.11.74.211:5060
0.999906 202.170.255.19 -> 58.8.117.188 SIP Request: OPTIONS sip:88888@58.8.117.188:5060
0.999912 202.170.255.19 -> 58.11.74.211 SIP Request: OPTIONS sip:88888@58.11.74.211:5060
1.387327 58.10.36.207 -> 202.170.255.19 SIP Request: REGISTER sip:202.170.255.19
1.387386 202.170.255.19 -> 58.10.36.207 SIP Status: 100 Trying (0 bindings)
1.387403 202.170.255.19 -> 58.10.36.207 SIP Status: 401 Unauthorized (0 bindings)
1.999900 202.170.255.19 -> 58.11.74.211 SIP Request: OPTIONS sip:88888@58.11.74.211:5060
1.999906 202.170.255.19 -> 58.8.117.188 SIP Request: OPTIONS sip:88888@58.8.117.188:5060
1.999911 202.170.255.19 -> 58.11.74.211 SIP Request: OPTIONS sip:88888@58.11.74.211:5060

คอลัมน์แรกเป็นเวลาที่ผ่านไป นับตั้งแต่เริ่มใช้คำสั่งนี้ คอลัมน์ที่ 2 เป็นไอพีแอดเดรสต้นทางที่ส่งข้อความ (อาจเป็นไอพีของเซอร์เวอร์ หรือเป็นไอพีของอุปกรณ์ VoIP) คอลัมน์ที่ 2 เป็นไอพีแอดเดรสปลายทาง (อาจเป็นไอพีของเซอร์เวอร์หรือไอพีของอุปกรณ์ VoIP) คอลัมน์ที่ 4 สุดท้ายเป็น SIP message ที่กำลังติดต่อกัน ซึ่งมีอยู่หลายแบบครับ ไว้ผมจะเขียนกระทู้เกี่ยวกับ SIP message นี้อีกครั้งหนึ่ง

ตัวอย่างที่ 2 มอนิเตอร์ SIP message ที่โฮสต์ 58.11.74.211 กำลังคุยกับเซอร์เวอร์ทางพอร์ต 5060

tethereal -i eth0 host 58.10.36.45 and port 5060

Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
0.000000 58.10.36.45 -> 202.170.255.19 SIP Request: REGISTER sip:202.170.255.19
0.000096 202.170.255.19 -> 58.10.36.45 SIP Status: 100 Trying (0 bindings)
0.000115 202.170.255.19 -> 58.10.36.45 SIP Status: 401 Unauthorized (0 bindings)
0.071210 58.10.36.45 -> 202.170.255.19 SIP Request: REGISTER sip:202.170.124.18
0.071253 202.170.255.19 -> 58.10.36.45 SIP Status: 100 Trying (0 bindings)
0.072403 202.170.255.19 -> 58.10.36.45 SIP Request: OPTIONS sip:063935683499@192.168.1.39:5060
0.072886 202.170.255.19 -> 58.10.36.45 SIP Status: 200 OK (1 bindings)
0.148143 58.10.36.45 -> 202.170.255.19 SIP Status: 200 OK

ตัวอย่างที่ 3 มอนิเตอร์ SIP message ที่โฮสต์ 58.11.74.211 กำลังคุยกับอุปกรณ์ VoIP ที่มีไอพีเป็น 58.10.36.45 แต่เก็บไว้เป็นไฟล์ .cap

tethereal -i eth0 host 58.10.36.45 and port 5060 -w "monihost_58.10.36.4.cap"

Running as user "root" and group "root". This could be dangerous.
Capturing on eth0
152

แค๊ปเจอร์ได้ 152 แพ็กเก็ตครับ จากนั้นก็ดาวน์โหลดมาไว้ที่เครื่องคอมแล้วเปิดดูด้วยโปรแกรม WireShark บนเครื่อง Windows

คงพอจะมองออกแล้วนะครับว่าเราจะใช้ WireShark ทำอะไรให้เราได้บ้าง

2 ติดตั้งและใช้งาน Ngrep

2.1 ดาวน์โหลดโปรแกรม
เป็นไฟล์ .rpm ติดตั้งได้เลยบน CentOS/RHEL/Fedora ดาวน์โหลดจากเว็บไซต์นี้ครับ http://dag.wieers.com/rpm/packages/ngrep/ เลือกไฟล์ตาม CentOS/RHEL/Fecora ที่ติดตั้งอยู่ในเครื่องของเรานะครับ เช่น ngrep-1.45-1.el5.rf.i386.rpm (สำหรับ Enterprise Linux 5/CentOS 5 แบบ 32 บิต), ngrep-1.45-1.el5.rf.x86_64.rpm (สำหรับ Enterprise Linux 5/CentOS 5 แบบ 64 บิต) เครื่องที่ผมใช้เป็น CentOS 5 เวอร์ชั่น 32 บิต ผมจึงเลือกไฟล์ ngrep-1.45-1.el5.rf.i386.rpm ครับ คลิ๊กขวาที่ชื่อไฟล์นี้แล้วเลือก "Copy Shortcut" เพื่อก๊อบปี้ลิ้งค์ไว้ครับ

เข้าสู่พร้อมท์ Linux
cd /tmp
wget แล้วคลิ๊กขวาเลือก Paste จะได้คำสั่งต่อไปนี้
wget http://dag.wieers.com/rpm/packages/ngre ... f.i386.rpm
รอจนดาวน์โหลดเสร็จ

2.2 ติดตั้ง
พิมพ์คำสั่ง rpm -ivh ngrep-1.45-1.el5.rf.i386.rpm
รอจนติดตั้งเสร็จ

2.3 การใช้งาน
ใช้เหมือนโปรแกรม Wireshark ครับ แต่คำสั่งต่างกันนิดหน่อย

ดูออปชั่นของคำสั่งทั้งหมดก่อน
ngrep -h
usage:
ngrep <-hNXViwqpevxlDtTRM> <-IO pcap_dump> <-n num> <-d dev> <-A num> <-s snaplen> <-S limitlen> <-W normal|byline|single|none> <-c cols><-P char> <-F file> <match expression> <bpf filter>
-h is help/usage
-V is version information
-q is be quiet (don't print packet reception hash marks)
-e is show empty packets
-i is ignore case
-v is invert match
-R is don't do privilege revocation logic
-x is print in alternate hexdump format
-X is interpret match expression as hexadecimal
-w is word-regex (expression must match as a word)
-p is don't go into promiscuous mode
-l is make stdout line buffered
-D is replay pcap_dumps with their recorded time intervals
-t is print timestamp every time a packet is matched
-T is print delta timestamp every time a packet is matched
-M is don't do multi-line match (do single-line match instead)
-I is read packet stream from pcap format file pcap_dump
-O is dump matched packets in pcap format to pcap_dump
-n is look at only num packets
-A is dump num packets after a match
-s is set the bpf caplen
-S is set the limitlen on matched packets
-W is set the dump format (normal, byline, single, none)
-c is force the column width to the specified size
-P is set the non-printable display char to what is specified
-F is read the bpf filter from the specified file
-N is show sub protocol number
-d is use specified device instead of the pcap default

2.4 ตัวอย่างการใช้คำสั่ง

2.4.1 มอนิเตอร์พอร์ต 5060 บนการ์ด eth0
ngrep -d eth0 port 5060

interface: eth0 (202.170.5.0/255.255.255.224)
filter: (ip) and ( port 5060 )
#
U 58.9.187.120:23396 -> 202.170.255.19:5060
NOTIFY sip:202.170.255.19 SIP/2.0..Via: SIP/2.0/UDP 192.168.2.36:5060;branch=z9hG4bK-c0a946db..From: <sip:050041546430@202.170.255.19>;tag=91110dfc21491faco0..To: <sip:202.170.255.19>..Call-ID: 13fbd3fc-22ed11ac@192.168.2.36..CSeq: 20623 NOTIFY..Max-Forw
ards: 70..Event: keep-alive..User-Agent: Sipura/SPA841-3.1.4(a)..Content-Length: 0....
#
U 202.170.255.19:5060 -> 58.9.187.120:23396
SIP/2.0 489 Bad event..Via: SIP/2.0/UDP 192.168.2.36:5060;branch=z9hG4bK-c0a946db;received=58.9.187.120..From: <sip:05004154643
0@202.170.255.19>;tag=91110dfc21491faco0..To: <sip:202.170.124.18>;tag=as4c0752e7..Call-ID: 13fbd3fc-22ed11ac@192.168.2.36..CSe
q: 20623 NOTIFY..User-Agent: Gw-Biz..Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO..Supported: repla
ces..Content-Length: 0....

2.4.2 มอนิเตอร์แพ็กเก็ตที่ไอพี 192.168.2.100 คุยกับเซอร์เวอร์ทางพอร์ต 5060
ngrep -d eth0 host 192.168.2.100 and port 5060

Note! ไอพีของเซอร์เวอร์ไม่ต้องใส่ครับเพราะว่าเรามอนิเตอร์บนเครื่องเซอร์เวอร์

เทคนิคการติดตั้ง Asterisk 16.x + DAHDI 2.11.1 บน CentOS 7
เทคนิคการติดตั้ง Asterisk 15.x + DAHDI 2.11.1 บน CentOS 7
jubjang
Gold Member
 
โพสต์: 55
ลงทะเบียนเมื่อ: 18 พ.ย. 2009 15:41

Re: โปรแกรมบน Linux เพื่อใช้มอนิเตอร์และแก้ปัญหา VoIP

โพสต์โดย dueraso » 11 ธ.ค. 2018 15:59

สุดยอดเลยครับ กำลังหาอยู่พอดี ขอบคุณครับ
dueraso
Bronz Member
 
โพสต์: 7
ลงทะเบียนเมื่อ: 28 ก.ย. 2018 11:04


ย้อนกลับไปยัง CentOS - The Community Enterprise Operating System

ผู้ใช้งานขณะนี้

่กำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และ บุคคลทั่วไป 1 ท่าน