All Products
Search
Document Center

Alibaba Cloud Linux:Common NetworkManager operations

Last Updated:Oct 17, 2024

NetworkManager is a utility that is used to manage the configurations of network interface controllers (NICs) and the status of NIC connections. NetworkManager can automatically detect available networks and switch connections between the networks on demand. You can configure network settings, such as IP addresses, gateways, and DNS settings, based on your business requirements.

Limits

Operating system: Alibaba Cloud Linux 3.

Configure NICs

NetworkManager uses nmcli commands to query and manage NIC configurations based on connections and devices. You can configure NICs based on your actual scenario.

  • Connection-based configurations are persistent. You must activate connections to allow the configurations to take effect.

  • Device-based configurations are temporary. The configurations immediately take effect but become invalid after the system restarts.

Configure NICs based on connections

Replace the $name parameter with a value of the NAME field, as shown in the following figure.

  • Query information about the current connections and the configuration files that correspond to the connections.

    nmcli -f NAME,FILENAME,TYPE,DEVICE connection

    The following figure shows the command output.

    image

  • Query the details of a specific NIC connection.

    nmcli connection show "$name"
  • Manage NIC connections.

    • Activate a NIC connection.

      sudo nmcli connection up "$name"
    • Terminate a NIC connection.

      sudo nmcli connection down "$name"
  • Change the MTU of a NIC connection.

    1. Replace the new_mtu parameter with a new MTU value.

      sudo nmcli connection modify "$name" 802-3-ethernet.mtu new_mtu
    2. Run the following command to allow the configuration to take effect:

      sudo nmcli connection up "$name"
  • Manage IP addresses.

    • Assign an IP address to a NIC connection.

      1. Replace the new_ip_addr parameter with the IP address that you want to assign.

        sudo nmcli connection modify "$name" +ipv4.addresses new_ip_addr
      2. Run the following command to allow the configuration to take effect:

        sudo nmcli connection up "$name"
    • Change the IP address of a NIC connection.

      1. Replace the new_ip_addr parameter with the new IP address that you want to assign.

        sudo nmcli connection modify "$name" ipv4.addresses new_ip_addr
      2. Run the following command to allow the configuration to take effect:

        sudo nmcli connection up "$name"
    • Remove an IP address from a NIC connection.

      1. Replace the old_ip_addr parameter with the IP address that you want to remove.

        sudo nmcli connection modify "$name" -ipv4.addresses old_ip_addr
      2. Run the following command to allow the configuration to take effect:

        sudo nmcli connection up "$name"
  • Change the MAC address of a NIC connection.

    1. Replace the new_mac_addr parameter with the new MAC address that you want to specify.

      sudo nmcli connection modify "$name" 802-3-ethernet.cloned-mac-address new_mac_addr
    2. Run the following command to allow the configuration to take effect:

      sudo nmcli connection up "$name"
  • Manage routes.

    • Add a routing rule to a NIC connection.

      Replace the new_rule parameter with the routing rule that you want to add.

      sudo nmcli connection modify "$name" +ipv4.routing-rules "new_rule"
    • Update the routing rule of a NIC connection.

      Replace the new_rule parameter with the new routing rule that you want to specify.

      sudo nmcli connection modify "$name" ipv4.routing-rules "new_rule"
    • Remove a routing rule from a NIC connection.

      Replace the old_rule parameter with the routing rule that you want to remove.

      sudo nmcli connection modify "$name" -ipv4.routing-rules "old_rule"
    • Add a route to a NIC connection.

      Replace the new_route parameter with the route that you want to add.

      sudo nmcli connection modify "$name" +ipv4.routes "new_route"
    • Update the route of a NIC connection.

      Replace the new_route parameter with the new route that you want to specify.

      nmcli connection modify "$name" ipv4.routes "new_route"
    • Remove a route from a NIC connection.

      Replace the old_route parameter with the route that you want to remove.

      sudo nmcli connection modify "$name" -ipv4.routes "old_route"

Configure NICs based on devices

Replace the $device parameter with a value of the DEVICE field, as shown in the following figure.

  • View the status of devices.

    nmcli device status

    The following figure shows the command output.

    image

  • Manage NIC connections.

    • Enable network connectivity for a NIC.

      sudo nmcli device up "$device"
    • Disable network connectivity for a NIC.

      sudo nmcli device down "$device"
  • Change the MTU of a NIC.

    Replace the new_mtu parameter with a new MTU value.

    sudo nmcli device modify "$device" 802-3-ethernet.mtu new_mtu
  • Manage IP addresses.

    • Assign an IP address to a NIC.

      Replace the new_ip_addr parameter with the IP address that you want to assign.

      sudo nmcli device modify "$device" +ipv4.addresses new_ip_addr
    • Change the IP address of a NIC.

      Replace the new_ip_addr parameter with the new IP address that you want to assign.

      sudo nmcli device modify "$device" ipv4.addresses new_ip_addr
    • Remove an IP address from a NIC.

      Replace the old_ip_addr parameter with the IP address that you want to remove.

      sudo nmcli device modify "$device" -ipv4.addresses old_ip_addr
  • Manage routes.

    • Add a routing rule to a NIC.

      Replace the new_rule parameter with the routing rule that you want to add.

      sudo nmcli device modify "$device" +ipv4.routing-rules "new_rule"
    • Update the routing rule of a NIC.

      Replace the new_rule parameter with the new routing rule that you want to specify.

      sudo nmcli device modify "$device" ipv4.routing-rules "new_rule"
    • Remove a routing rule from a NIC.

      Replace the old_rule parameter with the routing rule that you want to remove.

      sudo nmcli device modify "$device" -ipv4.routing-rules "old_rule"
    • Add a route to a NIC.

      Replace the new_route parameter with the route that you want to add.

      sudo nmcli device modify "$device" +ipv4.routes "new_route"
    • Update the route of a NIC.

      Replace the new_route parameter with the new route that you want to specify.

      sudo nmcli device modify "$device" ipv4.routes "new_route"
    • Remove a route from a NIC.

      Replace the old_route parameter with the route that you want to remove.

      sudo nmcli device modify "$device" -ipv4.routes "old_route"

Monitor networks

Monitor the status of networks.

nmcli monitor

References