domingo, 16 de febrero de 2014

Raspberry Pi: Configurar ip fija, acceso ssh y montarle disco duro externo

Conectamos la Raspberry Pi a al router y vemos que ip tiene o le conectamos un teclado y una pantalla abrimos una consola y tecleamos ifconfig.

pi@raspberrypi ~ $ ifconfig
eth0      Link encap:Ethernet  HWaddr b8:27:eb:e7:76:6d  
          inet addr:192.168.1.31  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:463 errors:0 dropped:3 overruns:0 frame:0
          TX packets:334 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:48748 (47.6 KiB)  TX bytes:36262 (35.4 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr 80:1f:02:af:2c:ef  
          inet addr:192.168.1.32  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:507 errors:0 dropped:526 overruns:0 frame:0
          TX packets:5 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:103617 (101.1 KiB)  TX bytes:1195 (1.1 KiB)
Nos conectamos a traves de ssh. ssh -X pi@192.168.1.13 y he introducimos la clave. Por defecto "raspberry"

verdor@enlamina ~$ ssh pi@192.168.1.31
Linux raspberrypi 3.6.11+ #474 PREEMPT Thu Jun 13 17:14:42 BST 2013 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Feb 16 21:58:15 2014 from 192.168.1.33
pi@raspberrypi ~ $ 
Asignamos una ip fija a la Raspberry Pi. Se configura en /etc/network/interfaces

pi@raspberrypi ~ $ sudo vi /etc/network/interfaces

#/etc/network/interfaces
auto lo

iface lo inet loopback
#iface eth0 inet dhcp
iface eth0 inet static

address 192.168.1.31
gateway 192.168.1.1
netmask 255.255.255.0

allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
#iface default inet dhcp
iface default inet static
address 192.168.1.32
netmask 255.255.255.0
gateway 192.168.1.1
Reiniciamos la Raspberry Pi para ver que tome los cambios:

pi@raspberrypi ~ $ sudo reboot
Queremos autenticarnos a la Raspberry Pi a través de una llave ssh, ya tenemos una. Hacemos en el servidor, la Raspberry Pi:

pi@raspberrypi ~ $  pwd
/home/pi
pi@raspberrypi ~ $ mkdir .ssh; chmod 700 .ssh
pi@raspberrypi ~ $ cd .ssh
pi@raspberrypi ~ $ touch authorized_keys; chmod 600 authorized_keys
En el cliente:

verdor@enlamina ~$ cd ~/.ssh
verdor@enlamina ~$ cat id_dsa.pub| ssh pi@192.168.1.32 'cat - >> ~/.ssh/authorized_keys'
Ahora configuramos ssh para acceder mas fácilmente a la Raspberry Pi:

verdor@enlamina ~$ vi ~/.ssh/config

#/home/verdor/.ssh/config

Host raspberrypi
  User pi
  HostName 192.168.1.31
  IdentityFile /home/verdor/.ssh/id_rsa
Guardamos con wq y entramos en la Raspberry Pi

verdor@enlamina ~$ ssh raspberrypi 
Linux raspberrypi 3.6.11+ #474 PREEMPT Thu Jun 13 17:14:42 BST 2013 armv6l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Feb 16 22:49:09 2014 from 192.168.1.33
pi@raspberrypi ~ $ 
Montamos disco duro externo para datos. Buscamos dispositivos conectados:

pi@raspberrypi ~ $  lsusb
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. 
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. 
Bus 001 Device 004: ID 7392:7811 Edimax Technology Co., Ltd EW-7811Un 802.11n Wireless Adapter [Realtek RTL8188CUS]
Bus 001 Device 005: ID 152d:2329 JMicron Technology Corp. / JMicron USA Technology Corp. JM20329 SATA Bridge
Averiguamos como se llama el dispositivo:

pi@raspberrypi ~ $ blkid
/dev/mmcblk0p1: LABEL="RECOVERY" UUID="242D-1618" TYPE="vfat" 
/dev/mmcblk0p5: SEC_TYPE="msdos" LABEL="boot" UUID="676B-0317" TYPE="vfat" 
/dev/mmcblk0p6: UUID="0eb36e9e-40f5-47f4-a751-4e197c0dd7c8" TYPE="ext4" 
/dev/sda1: UUID="XXXX-XXXX" TYPE="vfat"
Para obtener información mas detallada de la lista de las unidades conectadas:

pi@raspberrypi ~ $ sudo fdisk -l

Disk /dev/mmcblk0: 7861 MB, 7861174272 bytes
4 heads, 16 sectors/track, 239904 cylinders, total 15353856 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 identifier: 0x000ba6a2

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            2048     2466796     1232374+   e  W95 FAT16 (LBA)
/dev/mmcblk0p2         2473984    15353855     6439936   85  Linux extended
/dev/mmcblk0p5         2482176     2596863       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p6         2605056    15353855     6374400   83  Linux

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 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 identifier: 0x000683e5

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63   234436544   117218241    c  W95 FAT32 (LBA)
Creamos carpeta para el disco duro:

pi@raspberrypi ~ $ sudo mkdir /media/descargas
Editamos /etc/fstab para que se monte automáticamente al arrancar, añadimos la ultima linea:

pi@raspberrypi ~ $ sudo vi /etc/fstab

# /etc/fstab
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p5  /boot           vfat    defaults          0       2
/dev/mmcblk0p6  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, so no using swapon|off from here on, use  dphys-swapfile swap[on|off]  for that
UUID="XXXX-XXXX" /media/descargas vfat  defaults
Damos permisos de lectura y escritura al directorio de montaje:

pi@raspberrypi ~ $ sudo chmod -Rf 777 /media/descargas
Y montamos o reiniciamos:

pi@raspberrypi ~ $ sudo mount -a
Lo próximo será montar clientes Torrent, aMule y servidor Owncloud

No hay comentarios:

Publicar un comentario