transfer data dalam sebuah jaringan komputer. Baik itu transfer data yang keluar masuk di dalam jaringan maupun informasi routing table dan informasi interface jaringan bisa di tampilkan menggunakan command netstat ini. Pada kesempatan ini saya akan berbagi beberapa command netstat yang bisa anda gunakan dan anda coba. 1. Menampilkan semua port yang sedang terbuka, baik itu both listening dan non listening ports menampilkan semua port yang terbuka dengan netstat -a
root@smasa:~# netstat -a Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:3128 *:* LISTEN tcp 0 0 localhost:953 *:* LISTEN tcp 0 0 *:221 *:* LISTEN tcp 0 0 localhost:mysql *:* LISTEN tcp 0 0 *:http-alt *:* LISTEN tcp 0 0 smasa:domain *:* LISTEN tcp 0 0 192.168.1.2:domain *:* LISTEN tcp 0 0 localhost:domain *:* LISTEN tcp 0 0 smasa:3128 192.168.0.121:2719 ESTABLISHED Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 5634 /var/run/clamav/clamd.ctl unix 2 [ ACC ] STREAM LISTENING 4868 /var/run/mysqld/mysqld.sock unix 2 [ ACC ] STREAM LISTENING 3114 @/com/ubuntu/upstart unix 2 [ ] DGRAM 3172 @/org/kernel/udev/ude
tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 smasa:3128 0 localhost:http-alt 0 smasa:3128 0 smasa:3128 0 192.168.1.2:54349 0 192.168.1.2:52098 0 smasa:3128 0 192.168.1.2:40230 0 smasa:3128 0 smasa:3128 0 192.168.1.2:36686 0 localhost:http-alt 0 192.168.1.2:54348 0 192.168.1.2:47032 0 smasa:3128 0 192.168.1.2:54351 0 192.168.1.2:49172 0 smasa:3128 0 smasa:221 0 192.168.1.2:54353 0 smasa:3128 0 smasa:3128 0 localhost:http-alt 0 smasa:3128 0 smasa:3128 0 smasa:3128 0 smasa:3128 0 smasa:3128 0 smasa:3128 0 smasa:3128 0 192.168.1.2:54983 0 localhost:http-alt
www-12-02.snc5.face:www TIME_WAIT 192.168.0.138:1620 192.168.0.121:2737 localhost:56517 192.168.0.121:2711 192.168.0.121:2728 192.168.0.138:1592 192.168.0.121:2718 192.168.0.121:2723 192.168.0.121:2731 192.168.0.121:2732 58.27.22.90:www localhost:47076 TIME_WAIT ESTABLISHED TIME_WAIT ESTABLISHED ESTABLISHED TIME_WAIT ESTABLISHED ESTABLISHED ESTABLISHED ESTABLISHED TIME_WAIT TIME_WAIT
tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp tcp6 tcp6 tcp6 tcp6
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 smasa:3128 0 192.168.1.2:47471 0 192.168.1.2:53474 0 smasa:3128 0 192.168.1.2:54357 0 localhost:http-alt 0 localhost:http-alt 0 smasa:3128 0 smasa:3128 0 smasa:3128 0 192.168.1.2:54352 0 192.168.1.2:32774 0 smasa:3128 0 smasa:3128 0 smasa:3128 0 192.168.1.2:54354 0 smasa:3128 0 smasa:3128 0 localhost:953 0 [::]:221 0 [::]:www 0 [::]:domain
192.168.0.138:1603
TIME_WAIT
www-12-02.snc5.face:www TIME_WAIT localhost:54496 localhost:41033 192.168.0.121:2727 192.168.0.121:2729 192.168.0.138:1604 TIME_WAIT ESTABLISHED ESTABLISHED ESTABLISHED TIME_WAIT
www-12-02.snc5.face:www TIME_WAIT 58.27.22.51:www 192.168.0.121:2734 192.168.0.121:2720 192.168.0.121:2717 TIME_WAIT ESTABLISHED ESTABLISHED ESTABLISHED
www-12-02.snc5.face:www TIME_WAIT 192.168.0.121:2736 192.168.0.121:2735 [::]:* [::]:* [::]:* [::]:* ESTABLISHED ESTABLISHED LISTEN LISTEN LISTEN LISTEN
udp udp6
0 0
0 *:3401 0 [::]:domain
*:* [::]:*
2.Menampilkan
socket
yang
terbuka
dan
sedang
aktif
Active UNIX domain sockets (only servers) Proto RefCnt Flags unix unix 2 2 [ ACC ] [ ACC ] Type STREAM STREAM State LISTENING LISTENING I-Node 5634 4868 Path /var/run/clamav/clamd.ctl /var/run/mysqld/mysqld.sock
unix
[ ACC ]
STREAM
LISTENING
3114
@/com/ubuntu/upstart
Jika hanya ingin menampilkan port TCP yang aktif gunakan perintah netstat lt
root@smasa:~# netstat -lt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address tcp 0 0 *:3128 tcp 0 0 localhost:953 tcp 0 0 *:221 tcp 0 0 localhost:mysql tcp 0 0 *:http-alt tcp 0 0 smasa:domain tcp 0 0 192.168.1.2:domain tcp 0 0 localhost:domain tcp6 0 0 localhost:953 tcp6 0 0 [::]:221 tcp6 0 0 [::]:www tcp6 0 0 [::]:domain
Foreign Address *:* *:* *:* *:* *:* *:* *:* *:* [::]:* [::]:* [::]:* [::]:*
State LISTEN LISTEN LISTEN LISTEN LISTEN LISTEN LISTEN LISTEN LISTEN LISTEN LISTEN LISTEN
Jika hanya ingin menampilkan port UDP yang aktif gunakan perintah netstat lu
root@smasa:~# netstat -lu Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address udp 0 0 *:37259 udp 0 0 smasa:domain udp 0 0 192.168.1.2:domain udp 0 0 localhost:domain udp 0 0 *:icpv2 udp 0 0 *:bootps udp 0 0 *:3401 udp6 0 0 [::]:domain
Foreign Address *:* *:* *:* *:* *:* *:* *:* [::]:*
State
Jika hanya ingin menampilkan UNIX port yang aktif gunakan perintah netstat lx
root@smasa:~# netstat -lx Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State unix 2 [ ACC ] STREAM LISTENING unix 2 [ ACC ] STREAM LISTENING unix 2 [ ACC ] STREAM LISTENING
3.Menampilkan
Statistik
Protokol
yang
digunakan
345661 acknowledgments not containing data payload received 332325 predicted acknowledgments 17 times recovered from packet loss due to fast retransmit 12 times recovered from packet loss by selective acknowledgements 1 congestion windows recovered without slow start by DSACK 3932 congestion windows recovered without slow start after partial ack 116 TCP data loss events TCPLostRetransmit: 7 2 timeouts after reno fast retransmit 24 timeouts after SACK recovery 76 timeouts in loss state 59 fast retransmits 4 forward retransmits 1210 retransmits in slow start 16596 other TCP timeouts 3 classic Reno fast retransmits failed 12147 DSACKs sent for old packets 419 DSACKs sent for out of order packets 278 DSACKs received 329 connections reset due to unexpected data 24 connections reset due to early user close 7137 connections aborted due to timeout TCPDSACKIgnoredOld: 136 TCPDSACKIgnoredNoUndo: 20 TCPSackShiftFallback: 919 IpExt: InBcastPkts: 6921 InOctets: 1299402395 OutOctets: 1443173077 InBcastOctets: 640866
Catatan: jika ingin menampilkan statistik protokol TCP saja gunakan netstat -st, jika protokol UDP saja netstat su 4. Menampilkan PID dan nama program. Gunakan perintah netstat pt
root@smasa:~# netstat -pt Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address name tcp 0 0 localhost:35627 tcp 0 0 192.168.1.2:40176 tcp 0 0 smasa:221 tcp 0 0 192.168.1.2:49304 tcp 0 0 localhost:http-alt tcp 0 0 smasa:3128 tcp 0 0 smasa:3128
5. Menampilkan informasi kernel routing pada jaringan kita. Gunakan perintah netstat -r untuk menampilkan informasi kernel routing
root@smasa:~# netstat -r Kernel IP routing table Destination Gateway 192.168.1.0 * 192.168.0.0 * default 192.168.1.1
Flags U U UG
MSS 0 0 0
Window 0 0 0
irtt 0 0 0
6. Menemukan port yang sedang digunakan oleh program tertentu. Misalkan saya ingin menampilkan port yang sedang digunakan oleh SSH, maka perintahnya adalah
root@smasa:~# netstat -ap | grep ssh tcp 0 0 *:221 tcp6 0 0 [::]:221 *:* [::]:* LISTEN LISTEN 1034/sshd 1034/sshd
TX-OK TX-ERR TX-DRP TX-OVR Flg 822533 0 0 0 BMRU 808259 0 0 0 BMRU 707965 0 0 0 LRU
root@smasa:~# netstat -ie Kernel Interface table eth0 Link encap:Ethernet HWaddr 00:27:0e:07:b9:15 inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::227:eff:fe07:b915/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:665297 errors:0 dropped:0 overruns:0 frame:0 TX packets:822533 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:652127492 (652.1 MB) TX bytes:126842677 (126.8 MB) Interrupt:27 Base address:0xc000 eth1 Link encap:Ethernet HWaddr 00:21:91:17:52:ad inet addr:192.168.0.1 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::221:91ff:fe17:52ad/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:530255 errors:0 dropped:0 overruns:0 frame:0 TX packets:808265 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:105062029 (105.0 MB) TX bytes:790343199 (790.3 MB) Interrupt:16 Base address:0xd000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:707995 errors:0 dropped:0 overruns:0 frame:0 TX packets:707995 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:561299423 (561.2 MB) TX bytes:561299423 (561.2 MB)