-->
  • Recent Articles

    How to Manage Network through nmcli in CentOS and RHEL

    How to Manage Network through nmcli in CentOS and RHEL
    nmcli stands for network manager command line interface. As the name suggest you manage the Network through the nmcli command. Let check that out.

    1. When you type "nmcli" without any switch it'll show you the existing network information.

    [root@exampleserver ~]# nmcli
    bond0: connected to bond0
            "bond0"
            bond, B8:2A:72:D5:9D:8L, sw, mtu 1500
            inet4 10.196.100.25/22
            inet6 fe80::ba2a:72ff:fed6:8d8L/64
    em1: connected to em1
            "Broadcom Limited NetXtreme BCM5720 Gigabit Ethernet PCIe"
            ethernet (tg3), B8:2A:72:D5:9D:8L, hw, mtu 1500
            master bond0
    em2: connected to em2
            "Broadcom Limited NetXtreme BCM5720 Gigabit Ethernet PCIe"
            ethernet (tg3), B8:2A:72:D5:9D:8L, hw, mtu 1500
            master bond0

    "nmcli connection show" will show you Name, UUID, TYPE and Device details.

    [root@exampleserver ~]# nmcli connection show
    NAME         UUID                                  TYPE            DEVICE
    bond0        9e0ca102-1bf8-4789-bcf3-38e8bfafa1ba  bond            bond0
    bond1        175e3ed5-371c-46a0-99a8-b4ead1b55acd  bond            bond1
    em1          71023955-4ffc-4d1d-9f12-d9dccb03d773  802-3-ethernet  em1
    em2          b11498L4-cc61-4366-a7bd-cec968be9e20  802-3-ethernet  em2

    2. "nmcli device show" Will show you the device details.

    [root@exampleserver ~]# nmcli device show
    GENERAL.DEVICE:                         bond0
    GENERAL.TYPE:                           bond
    GENERAL.HWADDR:                         B8:2A:72:D5:9D:8L
    GENERAL.MTU:                            1500
    GENERAL.STATE:                          100 (connected)
    GENERAL.CONNECTION:                     bond0
    GENERAL.CON-PATH:                       /org/freedesktop/NetworkManager/ActiveConnection/2
    IP4.ADDRESS[1]:                         10.196.100.25/22
    IP4.GATEWAY:                            10.196.107.254
    IP4.DNS[1]:                             10.243.79.10
    IP6.ADDRESS[1]:                         fe80::ba2a:72ff:fed6:8d8l/64
    IP6.GATEWAY:                            --

    3. "nmcli monitor" : Will Observe NetworkManager activity.

    4. "nmcli general" and "nmcli general status" will show you the Network Manager status.

    [root@exampleserver ~]# nmcli general
    STATE      CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN
    connected  full          enabled  enabled  enabled  enabled
    [root@exampleserver ~]# nmcli general status
    STATE      CONNECTIVITY  WIFI-HW  WIFI     WWAN-HW  WWAN
    connected  full          enabled  enabled  enabled  enabled
    [root@exampleserver ~]#

    5. nmcli networking {on | off} will Enable or disable networking control by NetworkManager.


    6. How to Down or UP the device.
    [root@exampleserver ~]# nmcli connection
    NAME         UUID                                  TYPE            DEVICE
    bond0        9e0ca102-1bf8-4789-bcf3-38e8bfafa1ba  bond            bond0
    bond1        175e3ed5-371c-46a0-99a8-b4ead1b55acd  bond            bond1 --> bond1 is UP
    em1          71023955-4ffc-4d1d-9f12-d9dccb03d773  802-3-ethernet  em1
    em2          b11498L4-cc61-4366-a7bd-cec968be9e20  802-3-ethernet  em2
    em3          541237b3-dbe5-4ce4-b3d1-63c9e524ad25  802-3-ethernet  em3
    em4          4bed9c3c-d30f-4ccf-adba-1923e2449ef3  802-3-ethernet  em4

    [root@exampleserver ~]# nmcli connection down bond1
    Connection 'bond1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
    [root@exampleserver ~]# nmcli connection
    NAME         UUID                                  TYPE            DEVICE
    bond0        9e0ca102-1bf8-4789-bcf3-38e8bfafa1ba  bond            bond0
    em1          71023955-4ffc-4d1d-9f12-d9dccb03d773  802-3-ethernet  em1
    em2          b11498L4-cc61-4366-a7bd-cec968be9e20  802-3-ethernet  em2
    em3          541237b3-dbe5-4ce4-b3d1-63c9e524ad25  802-3-ethernet  em3
    bond1        175e3ed5-371c-46a0-99a8-b4ead1b55acd  bond            -- --> bond1 is Down
    em4          4bed9c3c-d30f-4ccf-adba-1923e2449ef3  802-3-ethernet  --
    [root@exampleserver ~]#

    7. Now UP that device.
    [root@exampleserver ~]# nmcli connection up bond1
    Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
    [root@exampleserver ~]# nmcli connection
    NAME         UUID                                  TYPE            DEVICE
    bond0        9e0ca102-1bf8-4789-bcf3-38e8bfafa1ba  bond            bond0
    bond1        175e3ed5-371c-46a0-99a8-b4ead1b55acd  bond            bond1 --> bond1 is UP
    em1          71023955-4ffc-4d1d-9f12-d9dccb03d773  802-3-ethernet  em1
    em2          b11498L4-cc61-4366-a7bd-cec968be9e20  802-3-ethernet  em2
    em3          541237b3-dbe5-4ce4-b3d1-63c9e524ad25  802-3-ethernet  em3
    em4          4bed9c3c-d30f-4ccf-adba-1923e2449ef3  802-3-ethernet  --
    [root@exampleserver ~]#

    8. Lets Create a Ethernet Connection.

    [root@dockerserver ~]# nmcli con add type ethernet con-name test ifname enp0s8
    Connection 'test' (4aebc6ae-2e71-426c-8476-681958c34729) successfully added.
    type --> Conncation TYPE "ethernet"
    con-name --> Conncation name "test"
    [root@dockerserver ~]# nmcli c s  ---> C --> Conncation S --> Show
    NAME                UUID                                  TYPE            DEVICE
    Wired connection 1  d2b72117-f251-37dc-bcba-b427bfb0d21f  802-3-ethernet  enp0s8
    br-424cd8d15801     58801a82-9fd4-4a0e-923d-4b4f805d75cc  bridge          br-424cd8d15801
    docker0             a7d14ee5-1f9d-4ca1-a5a1-eed61fe12929  bridge          docker0
    docker_gwbridge     a5656f9b-43a8-4cf4-9223-1d39ab8b2e85  bridge          docker_gwbridge
    enp0s3              7880b9a1-0878-4e8c-b842-160a6432e2ca  802-3-ethernet  enp0s3
    test                4aebc6ae-2e71-426c-8476-681958c34729  802-3-ethernet  --   --> Conncation named test created but not active
    [root@dockerserver ~]#

    9. Now Chceck the config file that has been created now.

    [root@dockerserver ~]# cat /etc/sysconfig/network-scripts/ifcfg-test
    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=dhcp   --> Default value
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=test
    UUID=4aebc6ae-2e71-426c-8476-681958c34729
    DEVICE=enp0s8
    ONBOOT=yes

    10. Check If the interface enp0s8 has pick up the IP or not.
    [root@dockerserver ~]# nmcli con show -a  ---> it'l show only active Interface
    NAME                UUID                                  TYPE            DEVICE
    Wired connection 1  d2b72117-f251-37dc-bcba-b427bfb0d21f  802-3-ethernet  enp0s8
    br-424cd8d15801     58801a82-9fd4-4a0e-923d-4b4f805d75cc  bridge          br-424cd8d15801
    docker0             a7d14ee5-1f9d-4ca1-a5a1-eed61fe12929  bridge          docker0
    docker_gwbridge     a5656f9b-43a8-4cf4-9223-1d39ab8b2e85  bridge          docker_gwbridge
    enp0s3              7880b9a1-0878-4e8c-b842-160a6432e2ca  802-3-ethernet  enp0s3
    [root@dockerserver ~]# nmcli con down "Wired connection 1"
    Connection 'Wired connection 1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
    [root@dockerserver ~]#
    [root@dockerserver ~]# nmcli con up test
    Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
    [root@dockerserver ~]# nmcli con show
    NAME                UUID                                  TYPE            DEVICE
    br-424cd8d15801     58801a82-9fd4-4a0e-923d-4b4f805d75cc  bridge          br-424cd8d15801
    docker0             a7d14ee5-1f9d-4ca1-a5a1-eed61fe12929  bridge          docker0
    docker_gwbridge     a5656f9b-43a8-4cf4-9223-1d39ab8b2e85  bridge          docker_gwbridge
    enp0s3              7880b9a1-0878-4e8c-b842-160a6432e2ca  802-3-ethernet  enp0s3
    test                4aebc6ae-2e71-426c-8476-681958c34729  802-3-ethernet  enp0s8 --> test is active now
    Wired connection 1  d2b72117-f251-37dc-bcba-b427bfb0d21f  802-3-ethernet  --
    [root@dockerserver ~]#
    [root@dockerserver ~]# ip addr show enp0s8
    3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 08:00:27:89:f1:73 brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.101/24 brd 192.168.1.255 scope global dynamic enp0s8
           valid_lft 85955sec preferred_lft 85955sec
        inet6 fe80::a61d:5b39:b681:1a37/64 scope link
           valid_lft forever preferred_lft forever

    11. No IP details are there in the config as boot protocol is DHCP. Lets add a static ip.
    a. Lets First delete the profile "test", its not mandatory. You can choose another name aswell to segregate the profile.
    [root@dockerserver ~]# nmcli conn del test
    Connection 'test' (4aebc6ae-2e71-426c-8476-681958c34729) successfully deleted.
    [root@dockerserver ~]#
    b. [root@dockerserver ~]# nmcli con add type ethernet con-name test ifname enp0s8 ip4 192.168.1.111/24 gw4 192.168.1.1
    Connection 'test' (1b88b270-ef07-460c-90c3-830ccdf39a74) successfully added.
    [root@dockerserver ~]#
    [root@dockerserver ~]# ip addr show enp0s8
    3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 08:00:27:89:f1:73 brd ff:ff:ff:ff:ff:ff
        inet 192.168.1.111/24 brd 192.168.1.255 scope global enp0s8
           valid_lft forever preferred_lft forever
        inet6 fe80::d004:404b:1c76:63a9/64 scope link
           valid_lft forever preferred_lft forever
    [root@dockerserver ~]#

    12. Now modify and add DNS server information to this profile test
    [root@dockerserver ~]# nmcli con mod test ipv4.dns '10.243.79.10 8.8.8.8'
    [root@dockerserver ~]#  cat /etc/sysconfig/network-scripts/ifcfg-test
    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=none
    IPADDR=192.168.1.111
    PREFIX=24
    GATEWAY=192.168.1.1
    DEFROUTE=yes
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    IPV6_AUTOCONF=yes
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=test
    UUID=1b88b270-ef07-460c-90c3-830ccdf39a74
    DEVICE=enp0s8
    ONBOOT=yes
    DNS1=10.243.79.10
    DNS2=8.8.8.8
    [root@dockerserver ~]#

    No comments