Skip to main content

Who is connecting to linux server

netstat -tn

-n: Display numeric only

-t: Display TCP connections only



Who is connected to my linux host - netstat -tn
Who is connecting to linux host: netstat -tn

netstat is not installed on CentOS/RHEL minimal installation by default.

[tuyendq@001 ~]$ which netstat
/usr/bin/which: no netstat in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/tuyendq/.local/bin:/home/tuyendq/bin)

Which package does netstat belong to?

[tuyendq@001 ~]$ yum search netstat
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: mirror.hostduplex.com
 * epel: mirrors.develooper.com
 * extras: repos.lax.quadranet.com
 * updates: mirror.hostduplex.com
zabbix-non-supported                                                                                                4/4
=================================================== Matched: netstat ===================================================
bwm-ng.x86_64 : Bandwidth Monitor NG
dstat.noarch : Versatile resource statistics tool
net-snmp.x86_64 : A collection of SNMP protocol tools and libraries
net-tools.x86_64 : Basic networking tools
python2-psutil.x86_64 : A process and system utilities module for Python
python34-psutil.x86_64 : A process and system utilities module for Python
python36-psutil.x86_64 : A process and system utilities module for Python
unhide.x86_64 : Tool to find hidden processes and TCP/UDP ports from rootkits

Install net-tools package in order to use netstat

[tuyendq@001 ~]$ sudo yum install -y net-tools
[sudo] password for tuyendq:
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.scalabledns.com
 * epel: mirrors.develooper.com
 * extras: mirror.scalabledns.com
 * updates: mirrors.usc.edu
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.24.20131004git.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================
 Package                   Arch                   Version                                    Repository            Size
========================================================================================================================
Installing:
 net-tools                 x86_64                 2.0-0.24.20131004git.el7                   base                 306 k

Transaction Summary
========================================================================================================================
Install  1 Package

Total download size: 306 k
Installed size: 918 k
Downloading packages:
net-tools-2.0-0.24.20131004git.el7.x86_64.rpm                                                    | 306 kB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : net-tools-2.0-0.24.20131004git.el7.x86_64                                                            1/1
  Verifying  : net-tools-2.0-0.24.20131004git.el7.x86_64                                                            1/1

Installed:
  net-tools.x86_64 0:2.0-0.24.20131004git.el7

Complete!

Check netstat version

[tuyendq@001 ~]$ netstat --version
net-tools 2.10-alpha
Fred Baumgarten, Alan Cox, Bernd Eckenfels, Phil Blundell, Tuan Hoang, Brian Micek and others
+NEW_ADDRT +RTF_IRTT +RTF_REJECT +FW_MASQUERADE +I18N +SELINUX
AF: (inet) +UNIX +INET +INET6 +IPX +AX25 +NETROM +X25 +ATALK +ECONET +ROSE -BLUETOOTH
HW:  +ETHER +ARC +SLIP +PPP +TUNNEL -TR +AX25 +NETROM +X25 +FR +ROSE +ASH +SIT +FDDI +HIPPI +HDLC/LAPB +EUI64
[tuyendq@001 ~]$

Check open ports with netstat, ss, lsof

netstat -tupln | grep LISTEN
sudo ss -tupln | grep LISTEN
sudo lsof -i -P -n | grep LISTEN

Popular posts from this blog

Linux command: top

NAME        top - display Linux processes SYNOPSIS        top -hv|-bcHiOSs -d secs -n max -u|U user -p pid -o fld -w [cols]        The traditional switches `-' and whitespace are optional. DESCRIPTION        The  top program provides a dynamic real-time view of a running system.  It can display        system summary information as well as a list of processes or  threads  currently  being        managed  by  the  Linux  kernel.  The types of system summary information shown and the        types, order and size of information displayed for processes are all user  configurable        and that configuration can be made persistent across restarts.        The  program  provides a limited interactive interface for process manipulation ...

Linux command: tail

tail - output the last part of files

Linux command: printenv

printenv - print all or part of environment NAME        printenv - print all or part of environment SYNOPSIS        printenv [OPTION]... [VARIABLE]... DESCRIPTION        Print  the  values  of the specified environment VARIABLE(s).  If no VARIABLE is speci‐        fied, print name and value pairs for them all.        -0, --null               end each output line with NUL, not newline        --help display this help and exit        --version               output version information and exit        NOTE: your shell may have its own version of printenv,  which  usually  supersedes  the        version  described  here.  Please refer to your shell's documentation for d...