Configurar la red IP con nmcli
Cómo configurar la red usando la utilidad de línea de comando nmcli (Interfaz de Línea de Comando NetworkManager).
Obtener iniciado con nmcli
La utilidad de línea de comandos nmcli (Interfaz de Línea de Comandos de NetworkManager) se utiliza para controlar NetworkManager e informar sobre el estado de la red. Puede utilizarse como sustituto de nm-applet u otros clientes gráficos. nmcli se utiliza para crear, exhibir, editar, eliminar, activar y desactivar conexiones de red, así como para controlar y visualizar el estado de los dispositivos de red.
La utilidad nmcli puede utilizarse por ambos usuarios y script para controlar NetworkManager:
-
Para servidores, máquinas desencabezados, y terminales, nmcli puede ser utilizado para control de NetworkManager directamente, sin IGU, incluyendo crear, editar, iniciar y detener conexiones de red y vistas de estado de red.
-
Para guines, nmcli admite un formato de salida breve el cual es más adecuado para el procesamiento de scripts. Es una forma de integrar la configuración de red en lugar de administrar las conexiones de red manualmente.
El formato básico de un comando de nmcli se puede ver a continuación:
nmcli [OPCIONES] OBJETO { COMANDO | help }
donde OBJECT puede ser una de las siguientes opciones: general, networking, radio, connection, device, agent y monitor. Puedes usar cualquier prefijo de estas opciones en sus comandos. Por ejemplo, nmcli con help, nmcli c help, nmcli connection help genera la misma salida.
Algunas OPTIONS opcionales útiles para iniciar son:
- -t, terse
-
Este modo puede ser utilizado para guiones de computador procesando como puede consultar una salida concisa que exhibe solo los valores.
Ejemplo 1. Ver una salida breve~]$
nmcli -t deviceens3:ethernet:connected:Profile 1 lo:loopback:unmanaged: - -f, campo
-
Esta opción especifica qué campos se pueden exhibir en la salida. Por ejemplo, NAME,UUID,TYPE,AUTOCONNECT,ACTIVE,DEVICE,STATE. Puede usar uno o más campos. Si desea usar más, no separe los campos con espacio después de la coma.
Ejemplo 2. Especificar Campos en la salida~]$
nmcli -f DISPOSITIVO,TIPO deviceDISPOSITIVO TIPO ens3 ethernet lo loopbacko incluso mejor para la creación de scripts:
~]$
nmcli -t -f DEVICE,TYPE deviceens3:ethernet lo:loopback - -p, pretty
-
Esta opción hace que nmcli genere una salida legible. Por ejemplo, se alinean los valores y se imprimen los encabezados.
Ejemplo 3. Visualización de una salida en modo bonito~]$
nmcli -p device===================== Status of devices ===================== DEVICE TYPE STATE CONNECTION -------------------------------------------------------------- ens3 ethernet connected Profile 1 lo loopback unmanaged -- - -h, help
-
Prints help information.
The nmcli tool has some built-in context-sensitive help. To list the available options and object names:
~]$ nmcli help
To list available actions related to a specified object:
~]$ nmcli object help
For example,
~]$ nmcli c help
Additional resources
Brief Selection of nmcli Examples
This section provides a brief selection of nmcli examples.
Prerequisites
~]$ nmcli general status
STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
connected full enabled enabled enabled enabled
In terse mode:
~]$ nmcli -t -f STATE general
connected
~]$ nmcli general logging
LEVEL DOMAINS
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,WIFI_SCAN,IP4,IP6,A
UTOIP4,DNS,VPN,SHARING,SUPPLICANT,AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,
WIMAX,INFINIBAND,FIREWALL,ADSL,BOND,VLAN,BRIDGE,DBUS_PROPS,TEAM,CONCHECK,DC
B,DISPATCH
~]$ nmcli connection show
NAME UUID TYPE DEVICE
Profile 1 db1060e9-c164-476f-b2b5-caec62dc1b05 ethernet ens3
ens3 aaf6eb56-73e5-4746-9037-eed42caa8a65 ethernet --
~]$ nmcli connection show --active
NAME UUID TYPE DEVICE
Profile 1 db1060e9-c164-476f-b2b5-caec62dc1b05 ethernet ens3
~]$ nmcli device status
DEVICE TYPE STATE CONNECTION
ens3 ethernet connected Profile 1
lo loopback unmanaged --
You can also use the following abbreviations of the nmcli commands:
| nmcli command | abbreviation |
|---|---|
nmcli general status |
nmcli g |
nmcli general logging |
nmcli g log |
nmcli connection show |
nmcli con show |
nmcli connection show --active |
nmcli con show -a |
nmcli device status |
nmcli dev |
Additional resources
-
Para más ejemplos, consulte la página del manual nmcli-examples(5).
The nmcli options
Following are some of the important nmcli property options:
connection.type-
A connection type. Allowed values are: adsl, bond, bond-slave, bridge, bridge-slave, bluetooth, cdma, ethernet, gsm, infiniband, olpc-mesh, team, team-slave, vlan, wifi, wimax. Each connection type has type-specific command options. For example:
-
A
gsmconnection requires the access point name specified in anapn.nmcli c add connection.type gsm apn access_point_name
-
A
wifidevice requires the service set identifier specified in assid.nmcli c add connection.type wifi ssid My identifier
-
You can see the TYPE_SPECIFIC_OPTIONS list in the nmcli(1) man page.
connection.interface-name-
A device name relevant for the connection.
nmcli con add connection.interface-name eth0 type ethernet
connection.id-
A name used for the connection profile. If you do not specify a connection name, one will be generated as follows:
connection.type -connection.interface-name
The
connection.idis the name of a connection profile and should not be confused with the interface name which denotes a device (wlan0,ens3,em1). However, users can name the connections after interfaces, but they are not the same thing. There can be multiple connection profiles available for a device. This is particularly useful for mobile devices or when switching a network cable back and forth between different devices. Rather than edit the configuration, create different profiles and apply them to the interface as needed. Theidoption also refers to the connection profile name.
The most important options for nmcli commands such as show, up, down are:
id-
An identification string assigned by the user to a connection profile. Id can be used in nmcli connection commands to identify a connection. The NAME field in the command output always denotes the connection id. It refers to the same connection profile name that the con-name does.
uuid-
Una cadena de identificación única asignada por el sistema a un perfil de conexión. El
uuidse puede usar en los comandosnmcli connectionpara identificar una conexión.
Additional resources
-
See the comprehensive list in the nmcli(1) man page.
Want to help? Learn how to contribute to Fedora Docs ›