Linux list all connection

Linux Show / Display Available Network Interfaces

  • ip command – It is used to show or manipulate routing, devices, policy routing and tunnels.
  • netstat command – It is used to display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
  • ifconfig command – It is used to display or configure a network interface.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements None
Est. reading time 4 minutes

List Network Interfaces Using ip Command on Linux

Type the following ip command, enter:
$ ip link show
Here is what we see:

  1. lo – Loopback interface.
  2. eth0 – My first Ethernet network interface on Linux.
  3. wlan0 – Wireless network interface in Linux.
  4. ppp0 – Point to Point Protocol network interface which can be used by dial up modem, PPTP vpn connection, or 3G wireless USB modem.
  5. vboxnet0, vmnet1, vmnet8 – Virtual machine interface working in bridge mode or NAT mode on Linux.

Linux show / display available network interfaces using nmcli

One can list available devices and their status on Linux, run:
$ nmcli device status
OR
$ nmcli connection show

Linux list all network interfaces using nmcli and ip command

Show a table of all network interfaces using netstat command in Linux

Type the following command:
$ netstat -i
Sample outputs:

Linux ip list interfaces using ifconfig command

Type the following ifconfig command:
$ /sbin/ifconfig -a
Sample outputs:

Источник

12 ss Command Examples to Monitor Network Connections

ss command is a tool that is used for displaying network socket related information on a Linux system. The tool displays more detailed information that the netstat command which is used for displaying active socket connections.

In this guide, we delve in and see how the ss command can be used to display varied socket connection information in Linux.

1. Listing all Connections

The basic ss command without any options simply lists all the connections regardless of the state they are in.

List All Connections in Linux

2. Listing Listening and Non-listening Ports

You can retrieve a list of both listening and non-listening ports using the -a option as shown below.

List All Ports in Linux

3. Listing Listening Sockets

To display listening sockets only, use the -l flag as shown.

List Listening Sockets in Linux

4. List all TCP Connections

To display all TCP connection, use the -t option as shown.

List TCP Connections in Linux

5. List all Listening TCP Connections

To have a view of all the listening TCP socket connection use the -lt combination as shown.

List Listening TCP Connections in Linux

6. List all UDP Connections

To view all the UDP socket connections use the -ua option as shown.

List UDP Socket Connections in Linux

7. List all Listening UDP Connections

To list listening UDP connections use the -lu option.

List Listening UDP Connections in Linux

8. Display PID (Process IDs) of Sockets

To display the Process IDs related to socket connections, use the -p flag as shown.

Find Process ID of Sockets in Linux

9. Display Summary Statistics

To list the summary statistics, use the -s option.

Find Summary Statistics

10. Display IPv4 and IPv6 Socket Connections

If you are curious about the IPv4 socket connections use the -4 option.

Find IPv4 Socket Connections in Linux

To display IPv6 connections, use the -6 option.

Find IPv6 Socket Connections in Linux

11. Filter Connections by Port Number

ss command also lets you filter socket port number or address number. For example, to display all socket connections with a destination or source port of ssh run the command.

Filter Connections by Port Number

Alternatively, you can run the command.

Filter Connections by Service

12. Check Man Pages for ss Command

To get more insights into the ss command usage, check the man pages using the command.

Find ss Command Usage and Options

Those are some of the commonly used options that are used with ss command. The command is considered more superior to netstat command and provide detailed information about network connections.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

We are thankful for your never ending support.

Источник

6 commands to check and list active SSH connections in Linux

Table of Contents

How to check active SSH connections in Linux. Show SSH connection history. How to show active ssh sessions in Linux. List all the active SSH connections in Unix. Find out all the currently active ssh connections on any Linux node. Which all tools can be used to list all the active ssh connections in Linux. Show active SSH sessions. Check ssh connection history using log files in Linux.

Some more more articles you may be interested on similar topics:

Check active SSH connections

There are various commands and tools available in Linux which can be used to check active SSH connections or sessions on your Linux node. In this article I will share a list of tools which can be used to get the list of active SSH connections. If you are aware of any more commands to show active ssh sessions then please let me know via comment section.

1. Using ss command

ss is used to dump socket statistics. It allows showing information similar to netstat . It can display more TCP and state information than other tools. We will use grep function to only get the list of active SSH sessions on our local host

From the above example we know that there are three hosts which are currently connected to our node3. We have active SSH connections from 10.0.2.31, 10.0.2.30 and 10.0.2.2

2. Using last command

last searches back through the file /var/log/wtmp (or the file designated by the -f flag) and displays a list of all users logged in (and out) since that file was created. Names of users and tty’s can be given, in which case last will show only those entries matching the arguments.

Using this command you can also get the information about the user using which the SSH connection was created between server and client. So below we know the connection from 10.0.2.31 is done using ‘deepak‘ user, while for other two hosts, ‘root‘ user was used for connecting to node3.

Here I am grepping for a string «still» to get all the patterns with » still logged in «. So now we know we have three active SSH connections from 10.0.2.31, 10.0.2.30 and 10.0.2.2

3. Using who command

who is used to show who is logged on on your Linux host. This tool can also give this information

Using this command we also get similar information as from last command. Now you get the user details used for connecting to node3 from source host, also we have terminal information on which the session is still active.

4. Using w command

w displays information about the users currently on the machine, and their processes. This gives more information than who and last command and also serves our purpose to get the list of active SSH connections. Additionally it also gives us the information of the running process on those sessions.

Using w command you will also get the idle time details, i.e. for how long the session is idle. If the SSH session is idle for long period then it is a security breach and it is recommended that such idle SSH session must be killed, you can configure your Linux host to automatically kill such idle SSH session.

5. Using netstat command

Similar to ss we have netstat command to show active ssh sessions. Actually we can also say that ss is the new version of netstat. Here we can see all the ESTABLISHED SSH sessions from remote hosts to our localhost node3. it is also possible that one or some of these active ssh connections are in hung state so you can configure your host to automatically disconnect or kill these hung or unresponsive ssh sessions in Linux.

Источник

List all connected SSH sessions?

I just SSH’d into root, and then SSH’d again into root on the same machine. So I have two windows open both SSH’d into root on my remote machine.

From the shell, how can I see a list of these two sessions?

7 Answers 7

who or w ; who -a for additional information.

These commands just show all login sessions on a terminal device. An SSH session will be on a pseudo-terminal slave ( pts ) as shown in the TTY column, but not all pts connections are SSH sessions. For instance, programs that create a pseudo-terminal device such as xterm or screen will show as pts . See Difference between pts and tty for a better description of the different values found in the TTY column. Furthermore, this approach won’t show anybody who’s logged in to an SFTP session, since SFTP sessions aren’t shell login sessions.

I don’t know of any way to explicitly show all SSH sessions. You can infer this information by reading login information from utmp / wtmp via a tool like last , w , or who like I’ve just described, or by using networking tools like @sebelk described in their answer to find open tcp connections on port 22 (or wherever your SSH daemon(s) is/are listening).

A third approach you could take is to parse the log output from the SSH daemon. Depending on your OS distribution, SSH distribution, configuration, and so on, your log output may be in a number of different places. On an RHEL 6 box, I found the logs in /var/log/sshd.log . On an RHEL 7 box, and also on an Arch Linux box, I needed to use journalctl -u sshd to view the logs. Some systems might output SSH logs to syslog. Your logs may be in these places or elsewhere. Here’s a sample of what you might see:

The logs show when sessions open and close, who the session belongs to, where the user is connecting from, and more. However, you’re going to have to do a lot of parsing if you want to get this from a simple, human-readable log of events to a list of currently active sessions, and it still probably won’t be an accurate list when you’re done parsing, since the logs don’t actually contain enough information to determine which sessions are still active — you’re essentially just guessing. The only advantage you gain by using these logs is that the information comes directly from SSHD instead of via a secondhand source like the other methods.

I recommend just using w . Most of the time, this will get you the information you want.

Источник

Linux ss Command Tutorial With Examples

Linux processes communicates with the socket between each other. There are tools to list, resolve, provide information about sockets. Ss is one of them. Netstat command can list and resolve the sockets too but it is slow because there is a lot of sockets. Ss gets information about socket from directly Linux kernel.

List All Connections

First of all existing connections, listening Unix and Network sockets can be listed with -l .

List All Connections

  • Netid column specifies the type of the socket like nl, u_dgr,tcp,udp
  • State column specifies current status of socket like listening, established etc.
  • Recv-Q column shows received packets
  • Send-Q column shows send packets
  • Local Address:Port column shows local address and port or equivalent values
  • Remote Address:Port column shows remote address and port or equivalent values

Filter TCP Connections

Listing all connections will create a lot of output on the terminal especially in busy servers. Or we may need only TCP connections to list and inspect. There is two way to list only TCP connections. One way is using TCP option -t directly. This will filter and list all ready established TCP connections.

Filter TCP Connections

Filter TCP Connections

As we can see both command have printed the same output because they do same operation just their syntax is different. -A option is used for simple and complex queries where we will look it below. We specify TCP protocol as query filter to only list TCP connections.

Filter UDP Sockets

Like filtering TCP connections UDP connections can be filtered like below. In the first example, we will provide a direct option -u to filter UDP sockets.

Filter UDP Connections

Filter UDP Connections

As we can see previous examples we have provided extra option -a because UDP is a connectionless protocol and we want to list sockets that can be listed with this option.

List All Statuses of Sockets, Connections

ss command by default list only established and connected sockets/connections. Listening sockets will be eliminated. The -a option will make to list all of them without eliminating.

List All Sockets, Connections

Filter Unix Sockets

Unix sockets are used for communication and exchange data between processes that resides in same Linux system. This socket mechanism is inherited from old Unix systems. All sockets in a Unix Linux system can be listed with the -x or —unix options.

Filter Unix Sockets

Filter IPv4 Connections

Linux network stack supports different protocols but as we know IPv4 is the most popular one which is mainly used for the internet. While printing network protocols all of them are listed like IPv4, IPv6, Apple Talk, etc. IPv4 protocols connections and sockets can be filtered with -4 or —ipv4 option like below.

Filter IPv4 Connections

Filter IPv6 Connections

As previously done IPv4 filtering for current connections and sockets. The same filtering can be done for IPv6 connections and sockets with -6 or —ipv6 options.

Filter IPv6 Connections

Filter Connections According to Port Number

Connects and sockets can be filtered according to their port numbers. Filtering this type of information requires special syntax and great flexibility to use. We will provide port number syntax by specifying ssh port.

Filter Connections According to Port Number

Using Port Numbers

In this example, we have filtered according to both source and destination ports. While expressing ports we have used the protocol name but numbers are OK for port specification like below.

Using Port Numbers

Filter Connections According to IP Address

We will filter connections according to IP address. Both destination and source hosts have an IP address. These are called

  • dst for a destination or remote IP address
  • src for source or local IP address

Filter Connections According to IP Address

Filter TCP Connections According States

As we know TCP protocol is a stateful protocol. What is stateful? Stateful simply means the source host create sessions for the network connection. TCP has the following states that are popular

Источник

Читайте также:  Odbc драйвер oracle для windows
Оцените статью