Suport de HDD, SAMBA si sftp

Aveti un router cu OpenWrt si vreti sa-i adaugati suport de HDD, SAMBA si sftp pentru a accesa acest HDD si de la servici, sau pur si simplu sa faceti share securizat de fisiere peste internet.
Exemplul de mai jos este pentru un HDD extern FAT.
Intrati cu telnet pe router si schimbati parola.

root@OpenWrt:~# passwd
Changing password for root
New password:
Bad password: too weak
Retype password:
Password for root changed by root

Va reconectati cu SSH. Putty


root@OpenWrt:/# opkg update
Downloading http://downloads.openwrt.org/kamikaz...es/Packages.gz
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
Packages.gz 100% |*************************************************************************************************** ******| 130k --:--:-- ETA
Inflating http://downloads.openwrt.org/kamikaz...es/Packages.gz
Updated list of available packages in /var/opkg-lists/snapshots

Dezinstalati varianta minima de administrare pentru a face loc pe flash.

root@OpenWrt:/# opkg remove luci-admin-mini
Removing package luci-admin-mini from root...

Instalati SAMBA

root@OpenWrt:/# opkg install luci-app-samba
Installing luci-app-samba (0.8.8-1) to root...
Downloading http://downloads.openwrt.org/kamikaz...8-1_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
luci-app-samba_0.8.8 100% |*************************************************************************************************** ******| 2866 --:--:-- ETA
Installing samba3 (3.0.24-2) to root...
Downloading http://downloads.openwrt.org/kamikaz...4-2_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.8.39.5:8080)
samba3_3.0.24-2_mips 100% |*************************************************************************************************** ******| 456k 00:00:00 ETA
Installing libpthread (0.9.29-14.3) to root...
Downloading http://downloads.openwrt.org/kamikaz...4.3_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
libpthread_0.9.29-14 100% |*************************************************************************************************** ******| 19340 --:--:-- ETA
Configuring libpthread
Configuring luci-app-samba
Configuring samba3


Adaugati suportul de usb2 si firewall&port forwarding


root@OpenWrt:/# opkg install luci-app-firewall kmod-fs-vfat kmod-usb-storage kmod-usb-uhci-iv kmod-usb2
Installing luci-app-firewall (0.8.8-1) to root...
Downloading http://downloads.openwrt.org/kamikaz...8-1_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
luci-app-firewall_0. 100% |*************************************************************************************************** ******| 7679 --:--:-- ETA
Installing kmod-fs-vfat (2.4.35.4-brcm-2.4-1) to root...
Downloading http://downloads.openwrt.org/kamikaz...4-1_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
kmod-fs-vfat_2.4.35. 100% |*************************************************************************************************** ******| 32643 --:--:-- ETA
Installing kmod-usb-storage (2.4.35.4-brcm-2.4-1) to root...
Downloading http://downloads.openwrt.org/kamikaz...4-1_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
kmod-usb-storage_2.4 100% |*************************************************************************************************** ******| 41024 --:--:-- ETA
Installing kmod-usb-core (2.4.35.4-brcm-2.4-1) to root...
Downloading http://downloads.openwrt.org/kamikaz...4-1_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
kmod-usb-core_2.4.35 100% |*************************************************************************************************** ******| 46534 --:--:-- ETA
Installing kmod-scsi-core (2.4.35.4-brcm-2.4-1) to root...
Downloading http://downloads.openwrt.org/kamikaz...4-1_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
kmod-scsi-core_2.4.3 100% |*************************************************************************************************** ******| 54968 --:--:-- ETA
Installing kmod-usb-uhci-iv (2.4.35.4-brcm-2.4-1) to root...
Downloading http://downloads.openwrt.org/kamikaz...4-1_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
kmod-usb-uhci-iv_2.4 100% |*************************************************************************************************** ******| 19399 --:--:-- ETA
Installing kmod-usb2 (2.4.35.4-brcm-2.4-1) to root...
Downloading http://downloads.openwrt.org/kamikaz...4-1_mipsel.ipk
Connecting to 10.1.1.1:8080 (10.1.1.1:8080)
kmod-usb2_2.4.35.4-b 100% |*************************************************************************************************** ******| 15708 --:--:-- ETA
Configuring kmod-fs-vfat
Configuring kmod-scsi-core
Configuring kmod-usb-core
Configuring kmod-usb-storage
Configuring kmod-usb-uhci-iv
Configuring kmod-usb2
Configuring luci-app-firewall


In acest moment daca conectati un HDD usb la router acesta va fi detectat


root@OpenWrt:/# dmesg
............................................

Initializing USB Mass Storage driver...
usb.c: registered new driver usb-storage
USB Mass Storage support registered.
hub.c: new USB device 01:02.2-1, assigned address 2
scsi0 : SCSI emulation for USB Mass Storage devices
Vendor: Model: Flash Disk Rev: 5.00
Type: Direct-Access ANSI SCSI revision: 02
Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
SCSI device sda: 2068992 512-byte hdwr sectors (1059 MB)
sda: Write Protect is off
Partition check:
/dev/scsi/host0/bus0/target0/lun0: p1
WARNING: USB Mass Storage data integrity not assured
USB Mass Storage device found at 2


Creati un script shell pentru a monta HDD-ul in directorul ¨share¨ la fiecare restart la router-ului.


root@OpenWrt:/# cat>/etc/init.d/usbhdd
#!/bin/sh /etc/rc.common
START=99
STOP=40
start()
{
echo -n "Mounting USB drive: "
mount -t vfat -o uid=65534,gid=65534,dmask=0,fmask=0 /dev/scsi/host0/bus0/target0/lun0/part1 /share
echo "Done."
}
stop()
{
echo -n "Umounting USB drive: "
sync
sync
umount /dev/scsi/host0/bus0/target0/lun0/part1
echo "Done."
}
restart()
{
stop
start
}

Apasati Ctrl+D pentru a finaliza editarea si verificati

root@OpenWrt:/# cat /etc/init.d/usbhdd
#!/bin/sh /etc/rc.common
START=99
STOP=40
start()
{
echo -n "Mounting USB drive: "
mount -t vfat -o uid=65534,gid=65534,dmask=0,fmask=0 /dev/scsi/host0/bus0/target0/lun0/part1 /share
echo "Done."
}
stop()
{
echo -n "Umounting USB drive: "
sync
sync
umount /dev/scsi/host0/bus0/target0/lun0/part1
echo "Done."
}
restart()
{
stop
start
}


Modificati fisierul usbhdd in executabil


root@OpenWrt:/# chmod +x /etc/init.d/usbhdd

Activati autostart pentru usbhdd

root@OpenWrt:/# /etc/init.d/usbhdd enable

Creati directorul ¨share¨

root@OpenWrt:/# cd /
root@OpenWrt:/# mkdir share


Listati

root@OpenWrt:/# ls
bin dev etc home jffs lib mnt proc rom root sbin share sys tmp usr var www
root@OpenWrt:/# pwd
/


Rulati scriptul de initializare usbhdd

root@OpenWrt:/# /etc/init.d/usbhdd start
Mounting USB drive: Done.


Verificati daca HDD-ul a fost vazut si montat


root@OpenWrt:/# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 1.6M 1.6M 0 100% /
/dev/root 1.6M 1.6M 0 100% /rom
tmpfs 14.9M 384.0k 14.5M 3% /tmp
/dev/mtdblock/4 1.7M 1.2M 544.0k 69% /jffs
mini_fo:/jffs 1.6M 1.6M 0 100% /
/dev/scsi/host0/bus0/target0/lun0/part1 1008.2M 857.7M 150.6M 85% /share


Verificati si listati continutul directorului montat.


root@OpenWrt:/# ls /share
3cdaemon consola.ppk pcra023-confg tftpboot7970.sccp.7-0-2
IMG_1114.jpg consola_lucian.ppk tftpboot tftpboot7970.sccp.8-2-2sp1
Quasar cp005058.scexe tftpboot 7905 tftpboot7970.sip.8-3-1
SEP000E84E8E3D5.cnf.xml dialplan.xml tftpboot 7970 work
XMLDefault.cnf.xml firmware telefoane cisco 79xx tftpboot2-7940-7960 wrt firmware
asterisk firmware telefoane linksys SPA9xx tftpboot7970.SIP70.8-5-2S tftpboot7970.sccp.6-0-3
root@OpenWrt:/#


Activati autostart si porniti serviciul de SAMBA


root@OpenWrt:/etc/samba# /etc/init.d/samba enable
root@OpenWrt:/etc/samba# /etc/init.d/samba start


Editati fisierul template de configurare SAMBA dupa cum urmeaza.

Pe scurt, comenzile necesare pentru editorul VI sunt:
i - pentru insert si a incepe editarea
esc - pentru a iesi din editare
Shift+zz - pentru a salva
:q! - pentru a iesi din editare fara a salva

root@OpenWrt:vi /etc/samba/smb.conf.template
[global]
netbios name = openwrt
workgroup = openwrt
server string = openwrt
name resolve order = lmhosts hosts bcast
syslog = 10
encrypt passwords = true
passdb backend = smbpasswd
obey pam restrictions = yes
socket options = TCP_NODELAY
unix charset = ISO-8859-1
preferred master = yes
os level = 20
security = share
guest account = nobody
invalid users = root
smb passwd file = /etc/samba/smbpasswd
writeable = yes
public = yes
root@OpenWrt:~#


Restartati serviciul de SAMBA



root@OpenWrt:/etc/samba# /etc/init.d/samba restart

Ultimul pas este sa configurati router-ul din interfata grafica asa cum se vede in atasamente.


In acest moment din orice calculator conectat pe lan-ul router-ului se poate accesa fisierul share la \\192.168.1.1

In atasament aveti cum se configureaza interfata grafica pentru port forwarding si network file share.

Pentru a accesa fisierele cu sftp pe portul 443 trebuie sa instalati serviciul de sftpd, altfel merge cu un client de scp (winscp, pscp).

root@OpenWrt:/etc/samba# opkg install openssh-sftp-server

Asigurati-va ca accesul catre router-ul dvs este deschis pe portul 443 - verificati setarea Firewall a router-ului (Network -> Firewall).
Iar in acest moment puteti sa va accesati hdd-ul de acasa de oriunde aveti o conexiune la internet. Nu uitati sa configurati winscp cu sesiune catre IP wan router port 443. Portul 443 (ssl) este in general deschis pentru toate retelele corporate sau nu, deci nu veti avea probleme de firewall.

SURSA: http://www.elforum.ro/viewtopic.php?f=73&t=59878&start=0

0 comentarii:

Trimiteți un comentariu