Showing posts with label netstat. Show all posts
Showing posts with label netstat. Show all posts

Tuesday, September 3, 2019

How to check if port is in use on Linux or Unix

How to check if port is in use on Linux or Unix


sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo lsof -i:22 ## see a specific port such as 22 ##
sudo nmap -sTU -O IP-address-Here

Option #1: lsof command
$ sudo lsof -i -P -n
$ sudo lsof -i -P -n | grep LISTEN
$ doas lsof -i -P -n | grep LISTEN ### [OpenBSD] ###

Linux netstat syntax
netstat -tulpn | grep LISTEN
watch netstat -tulpn
sudo ss -tulw
sudo ss -tulwn


netstat -tulpn |grep tcp |grep -v 127.0.0.1 |grep -v 192.168.101.36
-v is invert matching (every thing except 127.0.0.1 and 192.168.101.36)


Where ss command options are as follows:
  • -t : Show only TCP sockets on Linux
  • -u : Display only UDP sockets on Linux
  • -l : Show listening sockets. For example, TCP port 22 is opened by SSHD server.
  • -p : List process name that opened sockets
  • -n : Don’t resolve service names i.e. don’t use DNS

FreeBSD/MacOS X netstat syntax

$ netstat -anp tcp | grep LISTEN
$ netstat -anp udp | grep LISTEN

OpenBSD netstat syntax

$ netstat -na -f inet | grep LISTEN
$ netstat -nat | grep LISTEN

Option #3: nmap command

The syntax is:
$ sudo nmap -sT -O localhost
$ sudo nmap -sU -O 192.168.2.13 ##[ list open UDP ports ]##
$ sudo nmap -sT -O 192.168.2.13 ##[ list open TCP ports ]##
You can combine TCP/UDP scan in a single command:
$ sudo nmap -sTU -O 192.168.2.13

A note about Windows users

You can check port usage from Windows operating system using following command:
netstat -bano | more
netstat -bano | grep LISTENING
netstat -bano | findstr /R /C:"[LISTEING]"

Ref:
unix-linux-check-if-port-is-in-use-command






Wednesday, April 26, 2017

ss / netstata command

ss -s
ss -lp
ss -pl | grep port no.

time netstat -at
time ss -atr


linux-investigate-sockets-network-connections

Tuesday, March 17, 2015

การเพิ่ม Route แบบถาวรในวินโดว์

บทความด้านล่างคัดลอกมาจากเว็บไซต์ Komkit.net


ระบบที่ทดสอบ Microsoft Windows 7 Professional
กำหนดให้ Destination route คือ 172.17.15.0/24
กำหนดให้ Gateway คือ 172.17.12.1

- เพิ่ม route ชั่วคราว โดย route นี้จะหายไปเมื่อระบบ reboot
C:\>route add 172.17.15.0 mask 255.255.255.0 172.17.12.1
OK!

- เพิ่ม Perpersistent Static Route โดย route นี้จะไม่หายไปเมื่อระบบ reboot
C:\>route add -p 172.17.15.0 mask 255.255.255.0 172.17.12.1
OK!

- ลบ route
C:\>route delete 172.17.15.0 mask 255.255.255.0 172.17.12.1
OK!

- ตรวจสอบ Routing table
C:\> route print

หรือ

C:\> netstat -rn