how to check list of opened and closed port in linux ?

There are different commands on both Linux and UNIX server to see what TCP/UDP ports are listening or open on your server. You can use netstat command, which prints network connections, routing tables, interface statistics, masquerade connections, and multicast memberships, etc.

Method 1:

netstat command to find open ports

ravi@linuxforfreshers.com>>sudo netstat –listen

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 *:1234 *:* LISTEN

tcp 0 0 *:8084 *:* LISTEN

tcp 0 0 192.168.122.1:domain *:* LISTEN

tcp 0 0 *:ssh *:* LISTEN

tcp 0 0 *:ipp *:* LISTEN

tcp 0 0 *:microsoft-ds *:* LISTEN

tcp 0 0 *:7070 *:* LISTEN

tcp 0 0 localhost:mysql *:* LISTEN

tcp 0 0 *:netbios-ssn *:* LISTEN

tcp6 0 0 [::]:ssh [::]:* LISTEN

tcp6 0 0 [::]:ipp [::]:* LISTEN

tcp6 0 0 [::]:microsoft-ds [::]:* LISTEN

tcp6 0 0 [::]:netbios-ssn [::]:* LISTEN

udp 0 0 *:39505 *:*

udp 0 0 *:ipp *:*

udp 0 0 *:mdns *:*

udp 0 0 *:mdns *:*

Active UNIX domain sockets (only servers)

Proto RefCnt Flags Type State I-Node Path

unix 2 [ ACC ] STREAM LISTENING 12950 /var/run/acpid.socket

unix 2 [ ACC ] STREAM LISTENING 18259042 @atpl-com.canonical.Unity.Scope.rhythmbox.T516689809663571

unix 2 [ ACC ] STREAM LISTENING 19096 /run/user/1000/keyring-n7CcyZ/control

unix 2 [ ACC ] STREAM LISTENING 22589 @/tmp/.ICE-unix/3779

unix 2 [ ACC ] STREAM LISTENING 21540 @/tmp/dbus-u6IauIGH5I

To display open ports and established TCP connections, enter:

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

tcp 0 0 0.0.0.0:1234 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:8084 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:631 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:7070 0.0.0.0:* LISTEN

To display only open UDP ports try the following command:

ravi@linuxforfreshers.com>>sudo netstat -vaun

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address Foreign Address State

udp 0 0 0.0.0.0:39505 0.0.0.0:*

udp 0 0 0.0.0.0:631 0.0.0.0:*

● -l = only services which are listening on some port

● -n = show port number, don’t try to resolve the service name

● -p = name of the program

To display the list of open ports, enter:

To display all open files, use:

To display all open IPv4 network files in use by the process whose PID is 10050, use:

# lsof -iTCP -sTCP:LISTEN

Quickest way to test if a TCP port is open (including any hardware firewalls you may have), is to type, from a remote computer (e.g. your desktop):

telnet hostip port_number

ravi@linuxforfreshers.com>>telnet 192.168.101.156 22

Trying 192.168.101.156…

Connected to 192.168.101.156

Escape character is ‘^]’.

ravi@linuxforfreshers.com>>telnet localhost 22

ravi@linuxforfreshers.com>>ss -lntu

Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port

tcp UNCONN 0 0 *:39505 *:*

tcp UNCONN 0 0 *:631 *:*

tcp UNCONN 0 0 *:5353 *:*

 

Source

Leave a Reply

Your email address will not be published. Required fields are marked *

WP2Social Auto Publish Powered By : XYZScripts.com