¿Cómo obtener información básica de red con nmcli?

¿Cómo obtener información básica de red con nmcli en GNU/Linux?

El post pretende ser un recordatorio para mi mismo y un acicate para profundizar en nmcli, un desconocido para mi, que me ha parecido más amigable que el nuevo ip.

A modo de ejemplo, listo las conexiones activas con el comando en negrita:


user@machine:~$ nmcli connection show
NAME UUID TYPE DEVICE
MIWIFI_2G_nnGQ 43ce5cc0-6ecc-4fca-997b-ccdcb12ca2ff wifi
wlx74da38e4733c

virbr0 a756e70d-7f44-4bc6-8ce7-a3d1265cee1f bridge virbr0
Conexión cableada 1 3df083b6-e2d3-35b6-a55d-d1c540443eca ethernet

¿Cómo sé a qué velocidad se conecta la WiFi? nmcli ofrece un parámetro para saber los campos (-f para fields en inglés) de las conexiones a las que el sistema puede acceder.

user@machine:~$ nmcli -f WIFI-PROPERTIES dev show wlx74da38e4733c
WIFI-PROPERTIES.WEP: sí
WIFI-PROPERTIES.WPA: sí
WIFI-PROPERTIES.WPA2: sí
WIFI-PROPERTIES.TKIP: sí
WIFI-PROPERTIES.CCMP: sí
WIFI-PROPERTIES.AP: sí
WIFI-PROPERTIES.ADHOC: sí
WIFI-PROPERTIES.2GHZ: sí
WIFI-PROPERTIES.5GHZ: no
WIFI-PROPERTIES.MESH: sí
WIFI-PROPERTIES.IBSS-RSN: sí

Para quedarnos con ganas de explorar más las opciones de nmcli podemos listar la conexión concreta que nuestro equipo utilizaba y filtrar información sobre IPv4. Nos permite ver la ip de la conexión, la del router, los DNS que utiliza, etc.

user@machine:~$ nmcli connection show "MIWIFI_2G_nnGQ" | grep ^IP4
IP4.ADDRESS[1]: 192.168.1.142/24
IP4.GATEWAY: 192.168.1.1
IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.1.1, mt = 600
IP4.ROUTE[2]: dst = 169.254.0.0/16, nh = 0.0.0.0, mt = 1000
IP4.ROUTE[3]: dst = 192.168.1.0/24, nh = 0.0.0.0, mt = 600
IP4.DNS[1]: 212.230.135.2
IP4.DNS[2]: 212.230.135.1
IP4.DOMAIN[1]: home

Minimum securization for sshd

I run an RaspberryPi inside my home network with ssh access allowed. One of the first things I’d done was to install fail2ban package.

I know this is not enough by far. A really secure configuration requires more intel in it but I let it that way just to check how much penetration attemps I’ll see.

After a fast review in the /var/log/fail2ban.log file I notice that almost everything were ssh tries to log in the system. Which is perfectly normal because the system only exposes a web server and the sshd daemon.

An easy and fast securization for your home systems with ssh is to edit the /etc/hosts.allow and the /etc/host deny files to concrete what IP’s are allow to log in via ssh and deny all the rest. You may do the same secure configuration via /etc/ssh/sshd_config what it requieres more ssh knowledge and I prefer dedicate another post to it.

To allow you home network edit your /etc/host.allow and add:
sshd: 192.168.0.0/24 # this allow your local lan
sshd: 127.0.0.1 # this allow your localhost

To deny any other IP edit your /etc/hosts.deny and add:
sshd: ALL

How to install a concrete binary in a rpm distro

How to install a concrete binary in a rpm based distribution? Let’s asume you have a rpm based distro. I will wrote this little howto using a CentOS 7.8.

For instance you need to install iwlist but you don’t know what package provides you that binary. You have to type:


# yum provides iwlist

Your local database will return you something like this:

[pbenavent@localhost ~]$ yum provides iwlist
Complementos cargados:fastestmirror
Determining fastest mirrors
* base: mirror.gadix.com
* epel: fr2.rpmfind.net
* extras: mirror.airenetworks.es
* updates: mirror.gadix.com
1:wireless-tools-29-13.el7.x86_64 : Wireless ethernet configuration tools
Repositorio : @epel
Resultado obtenido desde:
Nombre del archivo : /usr/sbin/iwlist

Now you know the package name that you need to install, so the only thing you need to do is installed:

# yum install wireless-tools

As you may notice by reading the above lines, it’s assumed that your repository have indexed in its information the binary and package you’re querying for. In this particular exemple, the binary was iwlist and in the answer you read the full path indexed (/usr/bin/iwlist) wich is provided by EPEL repos. Remember the EPEL repo it’s not installed by defaul.

VMs CentOS con IP fija en Hyper-V

El escenario es un hipervisor Hyper-V de Microsoft que alberga dos máquinas virtuales CentOS, que por ejemplo es el laboratorio en el que estudias o ensayas antes de hacer cambios en las máquinas productivas.

He hecho dos cambios; configurar en el hipervisor que la máquina virtual (el servidor CentOS) no admita DCHP de otros servidores y fijar una dirección IP en cada una de los servidores virtuales CentOS.

Configurar el hipervisor

Abrimos la configuración del hipervisor, pulsamos sobre “Configuración” de la máquina virtual y en las “Características avanzadas” del “Adaptador de red” marcamos “Habilitar protección DHCP”.

Configurar IP estática en las máquinas virtuales CentOS

Puedes encontrar otras maneras de hacerlo (vía nmcli, interfaz gráfica, etc.) aquí recojo la manera que permite hacerlo con los mínimos recursos, una sesión en la máquina y editando ficheros con VI.

  • Entramos en la máquina y empleamos el usuario “root”
  • Editamos el fichero de nuestro dispositivo de red. En el ejemplo es la tarjeta ethernet así que editamos /etc/sysconfig/network-scripts/ifcfg-eth0
  • Cambiamos la línea: BOOTPROTO=dchp por BOOTPROTO=none
  • Si no está (habitualmente en una configuración existente con dhcp, no estará), añadimos la línea IPADDR=192.168.0.10, con la ip de vuestra elección.Reiniciamos el servicio de red: # systemctl restart network

Confío que pueda resultar de ayuda a alguién.

Postresql en Fedora 32: ¿Cómo actualizar?

Recién actualizado el equipo de Fedora 31 a Fedora 32 si intentas iniciar el servicio de Postgrqsql ejecutando como root (en adelante, todo lo escrito se ejecuta como root) # systemctl start postgresql da un error.

Como siempre, miramos que dice el log tecleando:
# journalctl -xe

En alguna línea aparece un mensaje similar a este (las negritas son mías):

-- The job identifier is 5061. de maig 01 11:49:13 localhost.localdomain postgresql-check-db-dir[5619]: An old version of the database format was found.
de maig 01 11:49:13 localhost.localdomain postgresql-check-db-dir[5619]: Use 'postgresql-setup --upgrade' to upgrade to version '12'

Aplicamos lo que se recomienda y ejecutamos (el comando forma parte del paquete postgresql-server):
# postgresql-setup --upgrade

La actualización dejará un log en /var/lib/pgsql/upgrade_postgresql.log.
Si todo ha ido como se indica podremos iniciar el servicio con normalidad
# systemctl start postgresql