How to List and Verify Currently Connected iSCSI Targets in Linux Using iscsiadm


2 views

When working with iSCSI storage in Linux, you'll often need to verify which targets are currently connected to your system. While iscsiadm -m discovery shows available targets, it doesn't indicate active connections. Here's how to properly check established sessions.

The most direct way to view connected targets is using the session mode:

iscsiadm -m session

This will output information in this format:

tcp: [1] 192.168.0.4:3260,1 iqn.2004-04.com.qnap:ts-509:iscsi.linux02.ba4731
tcp: [2] 192.168.0.4:3260,1 iqn.2004-04.com.qnap:ts-509:iscsi.linux03.ba4731

For more verbose output including connection state and statistics:

iscsiadm -m session -P 3

This provides detailed information like:

Target: iqn.2004-04.com.qnap:ts-509:iscsi.linux02.ba4731
    Current Portal: 192.168.0.4:3260,1
    Persistent Portal: 192.168.0.4:3260,1
    **********
    Interface:
    **********
    Iface Name: default
    Iface Transport: tcp
    Iface Initiatorname: iqn.1994-05.com.redhat:0123456789ab
    ...
    [Connection: 0]
    CID: 0
    State: LOGGED_IN

You can also check through the sysfs interface:

ls -l /sys/class/iscsi_session/

Or examine the kernel connection table:

cat /proc/net/iet/volume

To correlate connected targets with actual block devices:

ls -l /dev/disk/by-path/ | grep iscsi

Example output:

ip-192.168.0.4:3260-iscsi-iqn.2004-04.com.qnap:ts-509:iscsi.linux02.ba4731-lun-0 -> ../../sdb
ip-192.168.0.4:3260-iscsi-iqn.2004-04.com.qnap:ts-509:iscsi.linux03.ba4731-lun-0 -> ../../sdc

For monitoring scripts, this one-liner shows all connected target IQNs:

iscsiadm -m session | awk '{print $3}'

To check if a specific target is connected:

iscsiadm -m session | grep -q "iqn.2004-04.com.qnap:ts-509:iscsi.linux02.ba4731" && echo "Connected"

After discovering available iSCSI targets using iscsiadm -m discovery, you'll want to verify which targets are actually connected to your system. Here's the definitive command:

# iscsiadm -m session -P 3

This provides detailed session information including:

  • Active target IQNs
  • Connection state
  • Session IDs
  • Network interface details

For a cleaner view of just the connected targets:

# iscsiadm -m session

Example output:

tcp: [1] 192.168.0.4:3260,1 iqn.2004-04.com.qnap:ts-509:iscsi.linux02.ba4731
tcp: [2] 192.168.0.4:3260,1 iqn.2004-04.com.qnap:ts-509:iscsi.linux01.ba4731

While the /dev/disk/by-path/ method works, these alternatives provide more direct information:

# cat /proc/scsi/scsi
# lsscsi
# dmesg | grep -i scsi

To see what targets are configured for automatic connection:

# cat /etc/iscsi/nodes/*

This shows all discovered targets that could potentially connect at boot.

If targets aren't connecting as expected:

# iscsiadm -m node --loginall=automatic
# systemctl restart iscsid
# journalctl -u iscsid -f

These commands help diagnose and resolve common iSCSI connection problems.