Raspberry Zero: Asignar IP estática en ClusterHat
Hoy voy a enseñaros como asignar una IP estática en una Raspberry Pi Zero 2W, en mi caso, las tengo instaladas en mi ClusterHat, del que alguna vez os he hablado, que consta de una Raspberry Pi 4 y 4 RaspBerry Pi Zero 2W. Lo que vamos a modificar es la red tanto del nodo principal como de las Zero que forman el cluster.
Primero comprobamos que el nodo al que necesitamos cambiar la IP está levantado. El valor en ese caso es 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
pi@p0:~ $ clusterctrl status clusterhat:1 clusterctrl:False maxpi:4 throttled:0x0 hat_version:2.5 hat_version_major:2 hat_version_minor:5 hat_size:4 hat_uuid:16aeb902-9d28-11ea-bb37-0242ac130002 hat_vendor:8086 Consultancy hat_product_id:0x0004 hat_alert:0 hat_hub:1 hat_wp:1 hat_led:1 hat_wplink:0 hat_xra1200p:True p1:1 p2:0 p3:0 p4:0 |
Si no lo está, lo levantamos manualmente (podemos ir repitiendo la operación uno a uno):
1 |
pi@p0:~ $ clusterctrl on p1 |
Vemos que IP tiene actualmente, que ha sido asignada por DHCP:
1 2 3 4 5 6 7 8 9 |
pi@p0:~ $ ping p1 PING p1.negu.local (192.168.2.231) 56(84) bytes of data. 64 bytes from 192.168.2.231 (192.168.2.231): icmp_seq=1 ttl=64 time=75.9 ms 64 bytes from 192.168.2.231 (192.168.2.231): icmp_seq=2 ttl=64 time=5.30 ms 64 bytes from 192.168.2.231 (192.168.2.231): icmp_seq=3 ttl=64 time=5.35 ms ^C --- p1.negu.local ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 5.303/28.843/75.882/33.261 ms |
Nos conectamos vía SSH, elevando los permisos:
1 2 3 |
pi@p0:~ $ sudo su - root@p0:~# ssh pi@p1 pi@p1's password: |
Como ya sabréis, cada nodo, dispone de 2 interfaces, una WLAN que corresponde a la tarjeta de red Wifi, y una USB0 que correspondería a la Ethernet, que se genera por estar montada sobre un ClusterHat:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
root@p1:~# ifconfig lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 11 bytes 1598 (1.5 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 11 bytes 1598 (1.5 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 usb0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 ether 00:22:82:ff:ff:01 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.2.231 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::5176:3ca5:22e1:126c prefixlen 64 scopeid 0x20<link> ether e4:5f:01:5b:69:a4 txqueuelen 1000 (Ethernet) RX packets 241 bytes 36278 (35.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 103 bytes 20633 (20.1 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
El fichero que modificaremos para poder poner una IP estática a nuestras RaspBerry Pi Zero 2W es:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
root@p1:~# cat /etc/dhcpcd.conf # A sample configuration for dhcpcd. # See dhcpcd.conf(5) for details. # Allow users of this group to interact with dhcpcd via the control socket. #controlgroup wheel # Inform the DHCP server of our hostname for DDNS. hostname # Use the hardware address of the interface for the Client ID. clientid # or # Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361. # Some non-RFC compliant DHCP servers do not reply with this set. # In this case, comment out duid and enable clientid above. #duid # Persist interface configuration when dhcpcd exits. persistent # Rapid commit support. # Safe to enable by default because it requires the equivalent option set # on the server to actually work. option rapid_commit # A list of options to request from the DHCP server. option domain_name_servers, domain_name, domain_search, host_name option classless_static_routes # Respect the network MTU. This is applied to DHCP routes. option interface_mtu # Most distributions have NTP support. #option ntp_servers # A ServerID is required by RFC2131. require dhcp_server_identifier # Generate SLAAC address using the Hardware Address of the interface #slaac hwaddr # OR generate Stable Private IPv6 Addresses based from the DUID slaac private # Example static IP configuration: #interface eth0 #static ip_address=192.168.0.10/24 #static ip6_address=fd51:42f8:caae:d92e::ff/64 #static routers=192.168.0.1 #static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1 # It is possible to fall back to a static IP if DHCP fails: # define static profile #profile static_eth0 #static ip_address=192.168.1.23/24 #static routers=192.168.1.1 #static domain_name_servers=192.168.1.1 # fallback to static profile on eth0 #interface eth0 #fallback static_eth0 # ClusterCTRL reboot 15 denyinterfaces ethpi* ethupi* ethupi*.10 brint usb0.10 profile clusterctrl_fallback_usb0 static ip_address=172.19.181.1/24 #ClusterCTRL static routers=172.19.181.254 static domain_name_servers=8.8.8.8 208.67.222.222 profile clusterctrl_fallback_br0 static ip_address=172.19.181.254/24 interface usb0 fallback clusterctrl_fallback_usb0 interface br0 fallback clusterctrl_fallback_br0 |
Al tratarse de un ClusterHat, necesitaremos modificar la IP del nodo principal “p0” y de sus nodos, que en este caso es una Raspberry Pi 4 y los nodos Pi Zero. Revisamos la interface bridge “br0”. Salimos de la consola del nodo y vamos al principal:
1 2 3 4 5 6 7 8 9 |
root@p0:~# ifconfig br0 br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.2.197 netmask 255.255.255.0 broadcast 192.168.2.255 inet6 fe80::8c41:aeba:51a9:de31 prefixlen 64 scopeid 0x20<link> ether e4:5f:01:63:84:8b txqueuelen 1000 (Ethernet) RX packets 7254 bytes 991380 (968.1 KiB) RX errors 0 dropped 2 overruns 0 frame 0 TX packets 1211 bytes 153374 (149.7 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
Con esta referencia…Lo primero que haremos es hacer una copia de seguridad del fichero, tanto en el principal como en los nodos a modificar:
1 |
root@p1:~# cp /etc/dhcpcd.conf /etc/dhcpcd.conf.old |
Una vez realizado el backup correspondiente, editamos el fichero en la siguiente línea para el nodo principal con “vi”:
1 2 3 4 |
#fallback clusterctrl_fallback_br0 static ip_address=192.168.1.90 static routers=192.168.1.1 static domain_name_servers=8.8.8.8 |
Y para cada nodo, conectándonos nuevamente por SSH modificamos /etc/dhcpcd.conf:
1 2 3 4 |
#fallback clusterctrl_fallback_usb0 static ip_address=192.168.1.91/24 static routers=192.168.0.254 static domain_name_servers=192.168.0.254 8.8.8.8 |
Y repetimos los pasos para cada nodo. Comprobando que resuelve correctamente (yo he cambiado mi servidor DNS, pero podéis hacerlo vía fichero hosts):
1 2 3 4 5 6 7 8 |
root@p0:~# ping p1.negu.local PING p1.negu.local (192.168.1.91) 56(84) bytes of data. 64 bytes from 192.168.1.91 (192.168.1.91): icmp_seq=1 ttl=64 time=127 ms 64 bytes from 192.168.1.91 (192.168.1.91): icmp_seq=2 ttl=64 time=5.26 ms 64 bytes from 192.168.1.91 (192.168.1.91): icmp_seq=3 ttl=64 time=2.05 ms ^C --- p1.negu.local ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms |
En este momento podéis deshabilitar el DHCP, si es lo que os interesa.
Te ha gustado la entrada SGUENOS EN TWITTER O INVITANOS A UN CAFE?