Como utilizar nmcli para configurar las funciones de red de forma estática o dinámica.

Antes de comenzar me gustaria aclarar que los siguientes pasos en la configuracion de la red utilizando nmcli, los voy hacer en RHEL 7.3
Se que existen diferencias entre las versiones anteriores, pero si usted entiende el procedimiento de como hacerlo en una version, no va a tener problemas con las restantes versiones.

Para comenzar vamos a ver en que version de red hat estamos trabajando con el siguiente comando:

[root@class2 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.3 (Maipo)
[root@class2 ~]#

Como ven estamos trabajando con la versio 7.3

Ahora vamos a ver algunos comandos basicos.

Para ver los dispositivos de red que tenemos en nuestro sistema

[root@class2 ~]# nmcli device s
DEVICE TYPE STATE CONNECTION
virbr0 bridge connected virbr0
ens3 ethernet connected ens3
lo loopback unmanaged --
virbr0-nic tun unmanaged --
[root@class2 ~]#

Ojo, si usamos la palabra completa “show”, nos mostrara una salida un poco dificil de leer, pero siempre se puede arreglar mandando la salida al comando less:

[root@class2 ~]# nmcli device show | less

Otro comando util es:

[root@class2 ~]# nmcli connection show

Lo que tambien es lo mismo que:

[root@class2 ~]# nmcli connection s
[root@class2 ~]# nmcli conn s
[root@class2 ~]# nmcli con s

Esto es al gusto del consumidor. Si ya sabe cual interfaz de red queire mostrar, puede mostrar la configuracion que esta presente midiante:

[root@class2 ~]# nmcli connection show ens3

El nombre del dispositivo puede cambiar en dependencia de su sistema. Esta salida tambien es muy larga y un poco dificil de leer. Pero si la agrupa le sera mucho mas facil:

[root@class2 ~]# nmcli -p connection show ens3
[root@class2 ~]# nmcli -p connection show ens3 | less

[root@class2 ~]# nmcli -p connection show ens3
===============================================================================
Connection profile details (ens3)
===============================================================================
connection.id: ens3
connection.uuid: 5e65ecac-9564-4fd6-b227-aba5266db737
connection.stable-id: --
connection.interface-name: ens3
connection.type: 802-3-ethernet
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.timestamp: 1493134629
connection.read-only: no
connection.permissions:
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries:
connection.gateway-ping-timeout: 0
connection.metered: unknown
connection.lldp: -1 (default)
-------------------------------------------------------------------------------
802-3-ethernet.port: --
802-3-ethernet.speed: 0
802-3-ethernet.duplex: --
802-3-ethernet.auto-negotiate: yes
802-3-ethernet.mac-address: --
802-3-ethernet.cloned-mac-address: --
802-3-ethernet.generate-mac-address-mask:--
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu: auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype: --
802-3-ethernet.s390-options:
802-3-ethernet.wake-on-lan: 1 (default)
802-3-ethernet.wake-on-lan-password: --
-------------------------------------------------------------------------------
ipv4.method: manual
ipv4.dns: 192.168.4.2
ipv4.dns-search:
ipv4.dns-options: (default)
ipv4.dns-priority: 0
ipv4.addresses: 192.168.4.100/24
ipv4.gateway: 192.168.4.2
ipv4.routes:
ipv4.route-metric: -1
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-timeout: 0
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv4.dad-timeout: -1 (default)
-------------------------------------------------------------------------------
ipv6.method: auto
ipv6.dns:
ipv6.dns-search:
ipv6.dns-options: (default)
ipv6.dns-priority: 0
ipv6.addresses:
ipv6.gateway: --
ipv6.routes:
ipv6.route-metric: -1
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: 0 (disabled)
ipv6.addr-gen-mode: stable-privacy
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
ipv6.token: --
-------------------------------------------------------------------------------
===============================================================================
Activate connection details (5e65ecac-9564-4fd6-b227-aba5266db737)
===============================================================================
GENERAL.NAME: ens3
GENERAL.UUID: 5e65ecac-9564-4fd6-b227-aba5266db737
GENERAL.DEVICES: ens3
GENERAL.STATE: activated
GENERAL.DEFAULT: yes
GENERAL.DEFAULT6: no
GENERAL.VPN: no
GENERAL.ZONE: --
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/0
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/0
GENERAL.SPEC-OBJECT: /
GENERAL.MASTER-PATH: --
-------------------------------------------------------------------------------
IP4.ADDRESS[1]: 192.168.4.100/24
IP4.GATEWAY: 192.168.4.2
IP4.DNS[1]: 192.168.4.2
-------------------------------------------------------------------------------
IP6.ADDRESS[1]: fe80::5db9:6c3c:470f:6a18/64
IP6.GATEWAY:
-------------------------------------------------------------------------------
[root@class2 ~]#

De esta forma tendra una salida mas limpia en su terminal.

En todo esto, existen varias lineas de configuracion en las cuales usted debe prestar mucha atencion. Mencionando las principales y las que usted debe tener en cuenta en el examen estan las siguientes:

...
connection.autoconnect: yes
...
ipv4.method: manual
ipv4.dns: 192.168.4.2
ipv4.dns-search:
ipv4.dns-options: (default)
ipv4.dns-priority: 0
ipv4.addresses: 192.168.4.100/24
ipv4.gateway: 192.168.4.2
...
IP4.ADDRESS[1]: 192.168.4.100/24
IP4.GATEWAY: 192.168.4.2
IP4.DNS[1]: 192.168.4.2
...

Aclarado estos punto, vamos a comenzar con un poco de configuracion. En este ejemplo voy a partir asumiendo que no tengo nada configurado.

Vamos a eliminar al configuracion actual con:

[root@class2 ~]# nmcli connection delete ens3
Connection 'ens3' (5e65ecac-9564-4fd6-b227-aba5266db737) successfully deleted.
[root@class2 ~]#

Ahora comenzamos con la configuracion aumiendo las siguientes caracteristicas:
IP Fija o estatica: 192.168.4.123
NETMASK: 255.255.255.0 (/24)
GATEWAY: 192.168.4.2
DNS1: 192.168.4.2
Debe de iniciar automaticamente despuesd e cada reinicio

[root@class2 ~]# nmcli connection add type ethernet ifname ens3 con-name eth0 ipv4.addresses 192.168.4.123/24 ipv4.gateway 192.168.4.2 ipv4.dns 192.168.4.2 ipv4.method manual connection.autoconnect yes
Connection 'eth0' (25a11bce-4ed4-432e-b554-7487da6250aa) successfully added.
[root@class2 ~]#

Si tiene alguna duda sobre el order o directiva, puede presionar la tecla TAB dos veces y les mostrara todas las opciones posibles.

Ahora verificamos:

[root@class2 ~]# nmcli connection show
NAME UUID TYPE DEVICE
eth0 25a11bce-4ed4-432e-b554-7487da6250aa 802-3-ethernet ens3
virbr0 b891ce89-6519-4003-b7ec-a9412f0cd463 bridge virbr0
[root@class2 ~]#
[root@class2 ~]# nmcli -p connection show eth0
===============================================================================
Connection profile details (eth0)
===============================================================================
connection.id: eth0
connection.uuid: 25a11bce-4ed4-432e-b554-7487da6250aa
connection.stable-id: --
connection.interface-name: ens3
connection.type: 802-3-ethernet
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.timestamp: 1493135350
connection.read-only: no
connection.permissions:
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries:
connection.gateway-ping-timeout: 0
connection.metered: unknown
connection.lldp: -1 (default)
-------------------------------------------------------------------------------
802-3-ethernet.port: --
802-3-ethernet.speed: 0
802-3-ethernet.duplex: --
802-3-ethernet.auto-negotiate: yes
802-3-ethernet.mac-address: --
802-3-ethernet.cloned-mac-address: --
802-3-ethernet.generate-mac-address-mask:--
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu: auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype: --
802-3-ethernet.s390-options:
802-3-ethernet.wake-on-lan: 1 (default)
802-3-ethernet.wake-on-lan-password: --
-------------------------------------------------------------------------------
ipv4.method: manual
ipv4.dns: 192.168.4.2
ipv4.dns-search:
ipv4.dns-options: (default)
ipv4.dns-priority: 0
ipv4.addresses: 192.168.4.123/24
ipv4.gateway: 192.168.4.2
ipv4.routes:
ipv4.route-metric: -1
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-timeout: 0
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv4.dad-timeout: -1 (default)
-------------------------------------------------------------------------------
ipv6.method: auto
ipv6.dns:
ipv6.dns-search:
ipv6.dns-options: (default)
ipv6.dns-priority: 0
ipv6.addresses:
ipv6.gateway: --
ipv6.routes:
ipv6.route-metric: -1
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (unknown)
ipv6.addr-gen-mode: stable-privacy
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
ipv6.token: --
-------------------------------------------------------------------------------
===============================================================================
Activate connection details (25a11bce-4ed4-432e-b554-7487da6250aa)
===============================================================================
GENERAL.NAME: eth0
GENERAL.UUID: 25a11bce-4ed4-432e-b554-7487da6250aa
GENERAL.DEVICES: ens3
GENERAL.STATE: activated
GENERAL.DEFAULT: yes
GENERAL.DEFAULT6: no
GENERAL.VPN: no
GENERAL.ZONE: --
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/3
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/3
GENERAL.SPEC-OBJECT: /
GENERAL.MASTER-PATH: --
-------------------------------------------------------------------------------
IP4.ADDRESS[1]: 192.168.4.123/24
IP4.GATEWAY: 192.168.4.2
IP4.DNS[1]: 192.168.4.2
-------------------------------------------------------------------------------
IP6.ADDRESS[1]: fe80::463e:a631:ef13:f4bf/64
IP6.GATEWAY:
-------------------------------------------------------------------------------
[root@class2 ~]#

Esto es todo por ahora. Si se percatan no fue necesario reiniciar la red. Esto es porque se realizo una configuracion nueva.

Pero como se configura si ya tenemos una configuracion existente?
Si partimos de una configuracion existente es mucho mas facild e lo que usted cree. Para esto vamos a modificar usando los siguientes valores:

IP Fija o estatica: 192.168.4.8
NETMASK: 255.255.255.0 (/24)
GATEWAY: 192.168.4.2
DNS1: 192.168.4.2
DNS2: 8.8.8.8
Debe de iniciar automaticamente despuesd e cada reinicio

Aqui vamos a cambiar la direccion IP. Entonces el comando completo quedaria:

[root@class2 ~]# nmcli connection modify eth0 ipv4.addresses 192.168.4.8/24 +ipv4.dns 8.8.8.8
[root@class2 ~]# nmcli connection down eth0 ; nmcli connection up eth0
Connection 'eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/3)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@class2 ~]# nmcli -p connection show eth0
===============================================================================
Connection profile details (eth0)
===============================================================================
connection.id: eth0
connection.uuid: 25a11bce-4ed4-432e-b554-7487da6250aa
connection.stable-id: --
connection.interface-name: ens3
connection.type: 802-3-ethernet
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.timestamp: 1493135711
connection.read-only: no
connection.permissions:
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries:
connection.gateway-ping-timeout: 0
connection.metered: unknown
connection.lldp: -1 (default)
-------------------------------------------------------------------------------
802-3-ethernet.port: --
802-3-ethernet.speed: 0
802-3-ethernet.duplex: --
802-3-ethernet.auto-negotiate: yes
802-3-ethernet.mac-address: --
802-3-ethernet.cloned-mac-address: --
802-3-ethernet.generate-mac-address-mask:--
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu: auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype: --
802-3-ethernet.s390-options:
802-3-ethernet.wake-on-lan: 1 (default)
802-3-ethernet.wake-on-lan-password: --
-------------------------------------------------------------------------------
ipv4.method: manual
ipv4.dns: 192.168.4.2,8.8.8.8
ipv4.dns-search:
ipv4.dns-options: (default)
ipv4.dns-priority: 0
ipv4.addresses: 192.168.4.8/24
ipv4.gateway: 192.168.4.2
ipv4.routes:
ipv4.route-metric: -1
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-timeout: 0
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv4.dad-timeout: -1 (default)
-------------------------------------------------------------------------------
ipv6.method: auto
ipv6.dns:
ipv6.dns-search:
ipv6.dns-options: (default)
ipv6.dns-priority: 0
ipv6.addresses:
ipv6.gateway: --
ipv6.routes:
ipv6.route-metric: -1
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (unknown)
ipv6.addr-gen-mode: stable-privacy
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
ipv6.token: --
-------------------------------------------------------------------------------
===============================================================================
Activate connection details (25a11bce-4ed4-432e-b554-7487da6250aa)
===============================================================================
GENERAL.NAME: eth0
GENERAL.UUID: 25a11bce-4ed4-432e-b554-7487da6250aa
GENERAL.DEVICES: ens3
GENERAL.STATE: activated
GENERAL.DEFAULT: yes
GENERAL.DEFAULT6: no
GENERAL.VPN: no
GENERAL.ZONE: --
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/4
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/3
GENERAL.SPEC-OBJECT: /
GENERAL.MASTER-PATH: --
-------------------------------------------------------------------------------
IP4.ADDRESS[1]: 192.168.4.8/24
IP4.GATEWAY: 192.168.4.2
IP4.DNS[1]: 192.168.4.2
IP4.DNS[2]: 8.8.8.8
-------------------------------------------------------------------------------
IP6.ADDRESS[1]: fe80::463e:a631:ef13:f4bf/64
IP6.GATEWAY:
-------------------------------------------------------------------------------
[root@class2 ~]#

Fijense, que he agregado el DNS de google en este ejemplo, noten el signo “+”, esto quiere decir que se va agregar.
Lo pueden comprobar en el archivo que nunca deben tocar manualmente:

[root@class2 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 192.168.4.2
nameserver 8.8.8.8
[root@class2 ~]#

Ahora, si queremos eliminat el DNS1, entonces ejecutamos lo siguiente:

[root@class2 ~]# nmcli connection modify eth0 -ipv4.dns 192.168.4.2
[root@class2 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 192.168.4.2
nameserver 8.8.8.8
[root@class2 ~]# nmcli connection down eth0 ; nmcli connection up eth0
Connection 'eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@class2 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 8.8.8.8
[root@class2 ~]#

Elimine el DNS1, y como ven compruebo que aun esta la entrada en resolv.conf ; pero despues de reiniciar la red ya el cambio toma ejecto.

No olviden verificar todo estos cambios de la forma mas basica, la cual es hacer ping al DNS y al GATEWAY:

[root@class2 ~]# ping -c2 192.168.4.2
PING 192.168.4.2 (192.168.4.2) 56(84) bytes of data.
64 bytes from 192.168.4.2: icmp_seq=1 ttl=64 time=0.456 ms
64 bytes from 192.168.4.2: icmp_seq=2 ttl=64 time=0.666 ms

--- 192.168.4.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.456/0.561/0.666/0.105 ms
[root@class2 ~]# ping -c2 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=53 time=26.5 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=53 time=26.1 ms

--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 26.174/26.346/26.519/0.236 ms
[root@class2 ~]#

Otro detalle que ustedes como administrador de sistemas linux deben tener en cuenta en la configuracion de la red es, que si el servidor va a tomar la configuracion de la red dinamica (DHCP); pues en ves de definis “manual” en el metodo de coneccion, deben de estableces “auto”. Esto se traduce a lo siguiente:

[root@class2 ~]# nmcli connection delete eth0
Connection 'eth0' (25a11bce-4ed4-432e-b554-7487da6250aa) successfully deleted.
[root@class2 ~]# nmcli connection add type ethernet ifname ens3 con-name eth0 ipv4.method auto connection.autoconnect yesConnection 'eth0' (28dab966-64d8-43f9-a824-24de2cc3de8a) successfully added.
[root@class2 ~]# nmcli connection down eth0 ; nmcli connection up eth0
Connection 'eth0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/10)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/11)
[root@class2 ~]# nmcli -p connection show eth0
===============================================================================
Connection profile details (eth0)
===============================================================================
connection.id: eth0
connection.uuid: 28dab966-64d8-43f9-a824-24de2cc3de8a
connection.stable-id: --
connection.interface-name: ens3
connection.type: 802-3-ethernet
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.timestamp: 1493136344
connection.read-only: no
connection.permissions:
connection.zone: --
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries:
connection.gateway-ping-timeout: 0
connection.metered: unknown
connection.lldp: -1 (default)
-------------------------------------------------------------------------------
802-3-ethernet.port: --
802-3-ethernet.speed: 0
802-3-ethernet.duplex: --
802-3-ethernet.auto-negotiate: yes
802-3-ethernet.mac-address: --
802-3-ethernet.cloned-mac-address: --
802-3-ethernet.generate-mac-address-mask:--
802-3-ethernet.mac-address-blacklist:
802-3-ethernet.mtu: auto
802-3-ethernet.s390-subchannels:
802-3-ethernet.s390-nettype: --
802-3-ethernet.s390-options:
802-3-ethernet.wake-on-lan: 1 (default)
802-3-ethernet.wake-on-lan-password: --
-------------------------------------------------------------------------------
ipv4.method: auto
ipv4.dns:
ipv4.dns-search:
ipv4.dns-options: (default)
ipv4.dns-priority: 0
ipv4.addresses:
ipv4.gateway: --
ipv4.routes:
ipv4.route-metric: -1
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-timeout: 0
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
ipv4.never-default: no
ipv4.may-fail: yes
ipv4.dad-timeout: -1 (default)
-------------------------------------------------------------------------------
ipv6.method: auto
ipv6.dns:
ipv6.dns-search:
ipv6.dns-options: (default)
ipv6.dns-priority: 0
ipv6.addresses:
ipv6.gateway: --
ipv6.routes:
ipv6.route-metric: -1
ipv6.ignore-auto-routes: no
ipv6.ignore-auto-dns: no
ipv6.never-default: no
ipv6.may-fail: yes
ipv6.ip6-privacy: -1 (unknown)
ipv6.addr-gen-mode: stable-privacy
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
ipv6.token: --
-------------------------------------------------------------------------------
===============================================================================
Activate connection details (28dab966-64d8-43f9-a824-24de2cc3de8a)
===============================================================================
GENERAL.NAME: eth0
GENERAL.UUID: 28dab966-64d8-43f9-a824-24de2cc3de8a
GENERAL.DEVICES: ens3
GENERAL.STATE: activated
GENERAL.DEFAULT: yes
GENERAL.DEFAULT6: no
GENERAL.VPN: no
GENERAL.ZONE: --
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/11
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/4
GENERAL.SPEC-OBJECT: /
GENERAL.MASTER-PATH: --
-------------------------------------------------------------------------------
IP4.ADDRESS[1]: 192.168.4.102/24
IP4.GATEWAY: 192.168.4.2
IP4.DNS[1]: 192.168.4.2
-------------------------------------------------------------------------------
DHCP4.OPTION[1]: requested_classless_static_routes = 1
DHCP4.OPTION[2]: requested_rfc3442_classless_static_routes = 1
DHCP4.OPTION[3]: subnet_mask = 255.255.255.0
DHCP4.OPTION[4]: requested_subnet_mask = 1
DHCP4.OPTION[5]: domain_name_servers = 192.168.4.2
DHCP4.OPTION[6]: ip_address = 192.168.4.102
DHCP4.OPTION[7]: requested_static_routes = 1
DHCP4.OPTION[8]: dhcp_server_identifier = 192.168.4.2
DHCP4.OPTION[9]: requested_nis_servers = 1
DHCP4.OPTION[10]: requested_time_offset = 1
DHCP4.OPTION[11]: broadcast_address = 192.168.4.255
DHCP4.OPTION[12]: requested_interface_mtu = 1
DHCP4.OPTION[13]: dhcp_rebinding_time = 3150
DHCP4.OPTION[14]: requested_domain_name_servers = 1
DHCP4.OPTION[15]: dhcp_message_type = 5
DHCP4.OPTION[16]: requested_broadcast_address = 1
DHCP4.OPTION[17]: routers = 192.168.4.2
DHCP4.OPTION[18]: dhcp_renewal_time = 1800
DHCP4.OPTION[19]: requested_domain_name = 1
DHCP4.OPTION[20]: requested_routers = 1
DHCP4.OPTION[21]: expiry = 1493139944
DHCP4.OPTION[22]: requested_wpad = 1
DHCP4.OPTION[23]: host_name = class2
DHCP4.OPTION[24]: requested_nis_domain = 1
DHCP4.OPTION[25]: requested_ms_classless_static_routes = 1
DHCP4.OPTION[26]: network_number = 192.168.4.0
DHCP4.OPTION[27]: requested_domain_search = 1
DHCP4.OPTION[28]: next_server = 192.168.4.2
DHCP4.OPTION[29]: requested_ntp_servers = 1
DHCP4.OPTION[30]: requested_host_name = 1
DHCP4.OPTION[31]: dhcp_lease_time = 3600
-------------------------------------------------------------------------------
IP6.ADDRESS[1]: fe80::363f:e8e5:ccd0:fa73/64
IP6.GATEWAY:
-------------------------------------------------------------------------------
[root@class2 ~]# ]#

En este ejemplo comence por eliminar la configuracion existente, y entonces ejecute el comando que vimos para crear una coneccion nueva, pero en este caso, no especifique el DNS, ni el gateway. Ya que estos valores seran configurados por el servidos DHCP. Ahora procedemos a verificar algunos detalles despues de este cambio:

[root@class2 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 192.168.4.2
[root@class2 ~]# ip a | grep "inet "
inet 127.0.0.1/8 scope host lo
inet 192.168.4.102/24 brd 192.168.4.255 scope global dynamic ens3
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
[root@class2 ~]#

Como ven, tenemos una ip nueva y el archivo resolv.conf fue actualizado con la configuracion que provee el servidor DHCP.

Existen muchas mas opciones que puede definir con nmcli, como por ejemplo definir sus DNS usando una configuracion DHCP; como se traduce esto. Quiere decir que no va a utilizar los DNS que provee el DHCP, sino; que utilizaria otros diferentes. Para eso es necesario hacer algunos ajustes que les muestro a continuacion.

Comenzaremos por agregar otro DNS a la configuradcion existente, partiendo de que el sistema esta tomando todo del DHCP:

[root@class2 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 192.168.4.2
nameserver 8.8.8.8

Ahora agregamos el DNS nuevo y cambiamos una directiva

[root@class2 ~]# nmcli connection modify eth0 +ipv4.dns 8.8.8.8
[root@class2 ~]# nmcli connection modify eth0 ipv4.ignore-auto-dns yes
[root@class2 ~]# nmcli connection down eth0 ; nmcli connection up eth0
[root@class2 ~]# nmcli -p connection show eth0 | grep ipv4.ignore-auto-dns
[root@class2 ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 8.8.8.8
[root@class2 ~]#

Como ven de esta forma, no tomamos los DNS que el servido DHCP ofrece. Esto es solo una muestra de todo lo que podemos hacer con nmcli.

3 thoughts on “Como utilizar nmcli para configurar las funciones de red de forma estática o dinámica.”

  1. Buenos dias, saludo. Para manejar las conexiones inalambricas, en el caso de que estoy conectado a una red y quiero conectarme a otra, como seria?

    1. Se maneja de la misma forma, solo que la estructura del comando cambia un poco. Teniendo en cuenta de que por lo general las redes wifi requieren de una clave para conectarse.

      usuario-linux ~ $ nmcli radio
      WIFI-HW WIFI WWAN-HW WWAN
      enabled enabled enabled enabled
      usuario-linux ~ $ nmcli device wifi rescan
      usuario-linux ~ $ nmcli device wifi list
      IN-USE SSID MODE CHAN RATE SIGNAL BARS SECURITY
      name1 Infra 11 195 Mbit/s 80 ▂▄▆_ —
      — Infra 11 195 Mbit/s 79 ▂▄▆_ WPA2 802.1X
      * name2 Infra 11 195 Mbit/s 63 ▂▄▆_ WPA2 802.1X
      name3 Infra 1 195 Mbit/s 62 ▂▄▆_ —
      name4 Infra 1 195 Mbit/s 60 ▂▄▆_ WPA2 802.1X



      usuario-linux ~ $

      Note que el signo ‘*’ significa que es la red activa a la cual estas conectado actualmente

      Entonces una vez identificada el nombre de la red wifi a la cual te quieres conectar ejecutas lo siguiente:
      nmcli dev wifi connect SSID password password-aqui

Leave a Reply

Your email address will not be published. Required fields are marked *