Learn how to configure an iSCSI Target in Linux with our step-by-step guide. Set up a network storage solution to enhance your server’s storage capabilities efficiently. #centlinux #linux #iscsi
Table of Contents
What is iSCSI Target?
iSCSI (Internet Small Computer System Interface) is a protocol used to link data storage devices over an IP network infrastructure. An iSCSI target is often a dedicated network-connected hard disk storage device, but may also be a general-purpose computer. Nearly all modern mainstream server operating systems (such as BSD, Linux, Solaris or Windows Server) can provide iSCSI target functionality, either as a built-in feature or with supplemental software. The computer providing the iSCSI targets is called iSCSI Server.

What is iSCSI Initiator?
An iSCSI initiator is an iSCSI client. An iSCSI initiator typically serves the same purpose to a computer as a SCSI bus adapter would, except that, instead of physically cabling SCSI devices (like hard drives and tape changers), an iSCSI initiator sends SCSI commands over an IP network.
In this post, we will configure iSCSI Target in Linux, and then persistently mount that iSCSI Target on a iSCSI Initiator.
If you’re serious about leveling up your Linux skills, I highly recommend the Linux Mastery: Master the Linux Command Line in 11.5 Hours by Ziyad Yehia course. It’s a practical, beginner-friendly program that takes you from the basics to advanced command line usage with clear explanations and hands-on exercises. Whether you’re a student, sysadmin, or developer, this course will help you build the confidence to navigate Linux like a pro.
👉 Enroll now through my affiliate link and start mastering the Linux command line today!
Disclaimer: This post contains affiliate links. If you purchase through these links, I may earn a small commission at no extra cost to you, which helps support this blog.
Read Also: How to Configure an iScsi Target in Openfiler
Linux Server Specification
We have provisioned two CentOS 7 virtual machines with following specifications.
| iSCSI Server | iSCSI Initiator | |
| Operating System: | CentOS 7 | CentOS 7 |
| Hostname: | server1.example.com | desktop1.example.com |
| IP Address: | 192.168.116.11/24 | 192.168.116.12/24 |
Configure iSCSI Target
We have an spare hard disk (20 GB) is available. we have created a partition (20GB) in it using fdisk to make it usable by iSCSI Server.
fdisk -l /dev/sdbOutput:
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x94c52e45
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 83 Linux
we need targetcli package to configure an iSCSI Target.
yum install -y targetcliNow obtain a targetcli shell.
targetcliOutput:
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/>
Check the status of current iSCSI Target configurations.
lsOutput:
o- / ..................................................................... [...]
o- backstores .......................................................... [...]
| o- block .............................................. [Storage Objects: 0]
| o- fileio ............................................. [Storage Objects: 0]
| o- pscsi .............................................. [Storage Objects: 0]
| o- ramdisk ............................................ [Storage Objects: 0]
o- iscsi ........................................................ [Targets: 0]
o- loopback ..................................................... [Targets: 0]
/>
At the targetcli shell, create a Storage Block using following commands.
cd backstores/block/
create block1 /dev/sdb1
lsOutput:
Created block storage object block1 using /dev/sdb1.
o- block .................................................. [Storage Objects: 1]
o- block1 ....................... [/dev/sdb1 (20.0GiB) write-thru deactivated]
Create a TPG (Target Portal Group).
cd /iscsi
create iqn.2018-07.com.example.server1:remotedisk1
lsOutput:
Created target iqn.2018-07.com.example.server1:remotedisk1.
Created TPG 1.
o- iscsi .......................................................... [Targets: 1]
o- iqn.2018-07.com.example.server1:remotedisk1 ..................... [TPGs: 1]
o- tpg1 ............................................. [no-gen-acls, no-auth]
o- acls ........................................................ [ACLs: 0]
o- luns ........................................................ [LUNs: 0]
o- portals .................................................. [Portals: 0]
/iscsi>
Obtain the client iqn (iSCSI Qualified Name) from the client machine and use it to create an ACL, to limit the access to our iSCSI Target by desktop1.example.com machine.
cd /iscsi/iqn.2018-07.com.example.server1:remotedisk1/tpg1/acls
create iqn.1994-05.com.redhat:31532b60ee10
lsOutput:
Created Node ACL for iqn.1994-05.com.redhat:31532b60ee10
o- acls .............................................................. [ACLs: 1]
o- iqn.1994-05.com.redhat:31532b60ee10 ...................... [Mapped LUNs: 1]
o- mapped_lun0 .................................... [lun0 block/block1 (rw)]
/iscsi/iqn.20...sk1/tpg1/acls>
Create a LUN (Logical Unit Number).
cd /iscsi/iqn.2018-07.com.example.server1:remotedisk1/tpg1/luns
create /backstores/block/block1
lsOutput:
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.1994-05.com.redhat:31532b60ee10
o- luns .............................................................. [LUNs: 1]
o- lun0 ........................................... [block/block1 (/dev/sdb1)]
/iscsi/iqn.20...sk1/tpg1/luns>
Create a Portal now.
cd /iscsi/iqn.2018-07.com.example.server1:remotedisk1/tpg1/portals
create 192.168.116.11
exitOutput:
Using default IP port 3260
Created network portal 192.168.116.11:3260.
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
Allow the port 3260/tcp through firewall.
firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reloadStart and enable the target service.
systemctl enable target
systemctl start targetiSCSI Target has been configured successfully.
Configure iSCSI Initiator
Install iscsi-initiator-utils package. It is required to configure a iSCSI Initiator.
yum install -y iscsi-initiator-utilsWe can confirm the iSCSI Initiator’s iqn that, we have used during iSCSI Target configuration to create an ACL.
cat /etc/iscsi/initiatorname.iscsiOutput:
InitiatorName=iqn.1994-05.com.redhat:31532b60ee10
Start and enable iscsi service.
systemctl enable iscsi
systemctl start iscsiDiscover the available iSCSI Targets at 192.168.116.11.
iscsiadm -m discovery -t sendtargets -p 192.168.116.11Output:
192.168.116.11:3260,1 iqn.2018-07.com.example.server1:remotedisk1
Restart iscsi service and list block devices.
systemctl restart iscsi
lsblkOutput:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
ââsda1 8:1 0 300M 0 part /boot
ââsda2 8:2 0 1.5G 0 part [SWAP]
ââsda3 8:3 0 18.2G 0 part /
sdb 8:16 0 20G 0 disk
sr0 11:0 1 3.5G 0 rom /mnt/iso
Our iSCSI Target Disk has been successfully discovered as /dev/sdb. Let’s create a partition and the filesystem.
fdisk /dev/sdbOutput:
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x08f4940d.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (8192-41940991, default 8192):
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-41940991, default 41940991):
Using default value 41940991
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
# fdisk -l /dev/sdb
Disk /dev/sdb: 21.5 GB, 21473787904 bytes, 41940992 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk label type: dos
Disk identifier: 0x08f4940d
Device Boot Start End Blocks Id System
/dev/sdb1 8192 41940991 20966400 83 Linux
# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=256 agcount=16, agsize=327600 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=5241600, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
Now, persistently mount the partition at /mnt/remotedisk1.
echo "/dev/sdb1 /mnt/remotedisk1 xfs _netdev 0 0" >> /etc/fstab
mount -a
mount | grep /mnt/remotedisk1Output:
/dev/sdb1 on /mnt/remotedisk1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota,_netdev)
We have successfully configure iSCSI Target and then persistently mount it at our iSCSI Initiator.
Final Thoughts
Configuring an iSCSI Target in Linux can significantly enhance your server’s storage capabilities by providing a robust and scalable network storage solution. By following this guide, you can set up and manage your iSCSI Target efficiently.
From setting up scalable AWS solutions to managing complex Linux environments, I’ve got you covered. Visit my Freelancer profile to get started.

Leave a Reply
Please log in to post a comment.