iSCSI on Linux
This shows how to share a physical device via iSCSI.
Warning
While doing it quick&dirty like this is fine at home if you just want to mount a filesystem on another machine, be aware that using no authentication and restrictions is insecure.
For use in production environments, you certainly should consult the documentation (man tgtadm, man icsiadm) and use at least IP restrictions and CHAP authentication.
Server
tgtd
Create a target device:
tgtadm --lld iscsi --mode target --op new --tid=1 --targetname iqn.2017-10.com.example:target1
Create a LUN:
tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 -b /dev/sdX
Set permissions to allow all initiators:
tgtadm --lld iscsi --mode target --op bind --tid 1 -I ALL
Firewall
Allow tcp port 3260.
using iptables
iptables -I INPUT [rulenumber] -p tcp --dport 3260 -j ACCEPT
using firewalld
Check which zone is active:
firewall-cmd --get-active-zones
Allow the iscsi-target-service in that zone:
firewall-cmd --zone=PUTZONEHERE --add-service=iscsi-target
If you want to set this permanently, add --permanent
.
Reload firewalld:
firewall-cmd --reload
Client
Target discovery:
iscsiadm -m discovery -t sendtargets -p IP:3260
Login:
iscsiadm -m node -T iqn.2017-10.com.example:target1 -p IP:3260 --login
Now a new device should appear as /dev/sd* (check dmesg).
This device can be treated like a local device (with e.g., dd, mkfs, mount, …).
Logout:
iscsiadm -m node -T iqn.2017-10.com.example:target1 -p IP:3260 --logout