需要使用 nmcli 配置静态 IP,但不知道如何配置

需要使用 nmcli 配置静态 IP,但不知道如何配置

我试图在 CentOS 6.9 中使用 nmcli 创建静态 IP,但无法这样做,因为 man nmcli 没有像在线示例那样显示足够的选项。为了让大家理解,我将把手册页粘贴到这里;请告诉我哪里出了问题或者是发行版的错,因为我从 Ubuntu 更改后发现了很多差异。

NMCLI(1)                                                              NMCLI(1)

NAME
       nmcli - command-line tool for controlling NetworkManager

SYNOPSIS
       nmcli  [ OPTIONS ] OBJECT { COMMAND | help }

       OBJECT := { nm | con | dev }

       OPTIONS := {
       -t[erse]
       -p[retty]
       -m[mode] tabular | multiline
       -f[ields] <field1,field2,...> | all | common
       -e[scape] yes | no
       -v[ersion]
       -h[elp]
       }



DESCRIPTION
       nmcli is a command-line tool for controlling NetworkManager and getting its status.  It is not meant as a replacement of nm-applet or other similar clients.  Rather it’s a complementary utility to these pro-
       grams.  The main nmcli’s usage is on servers, headless machines or just for power users who prefer the command line.

       The use cases comprise:

       —   Initscripts: ifup/ifdown can utilize NetworkManager via nmcli instead of having to manage connections itself and possible interfere with NetworkManager.

       —   Servers, headless machines: No GUI is available; then nmcli is used to talk directly to NetworkManager and control only system-wide connections.

       —   User sessions: For this case, nmcli can talk to nm-applet to find user connections.  It can still talk directly to NetworkManager for manipulating these connections.  As nmcli doesn’t have direct access
           to user configuration data in GConf, nm-applet handles that itself.  That may, for example, cause the applet to pop up keyring dialogs when secrets are needed.

   OPTIONS
       -t, --terse
              Output is terse.  This mode is designed and suitable for computer (script) processing.

       -p, --pretty
              Output is pretty.  This causes nmcli to produce easy readable outputs for humans, i.e. values are aligned, headers are printed, etc.

       -m, --mode tabular | multiline
              Switch between tabular and multiline output.  If omitted, default is tabular for most commands.  For the commands producing more structured information, that cannot be displayed on a single line,
              default is multiline. Currenly, they are:
                ’nmcli con list id|uuid <name>’
                ’nmcli dev list’
              tabular   - Output is a table where each line describes a single entry.  Columns define particular properties of the entry.
              multiline - Each entry comprises more lines, each property on its own line.  The values are prefixed with the property name.

       -f, --fields <field1,field2,...> | all | common
              This option is used to specify what fields (column names) should be printed.  Valid field names differ for specific commands. List available fields by providing an invalid value to the --fields
              option.
              all is used to print all valid field values of the command.  common is used to print common field values of the command.  If omitted, default is common.  The option is mandatory when --terse is used.
              In this case, generic values all and common cannot be used.  (This is to maintain compatibility when new fields are added in the future).

       -e, --escape yes | no
              Whether to escape ’:’ and ’\’ characters in terse tabular mode.  The escape character is ’\’.  If omitted, default is yes.

       -v, --version
              Show nmcli version.

       -h, --help
              Print help information.


   OBJECT
       nm     NetworkManager
              Use this object to inquire and change state of NetworkManager.

          COMMAND := { status | sleep | wakeup | wifi | wwan }

              status
                     Show overall status of NetworkManager.  This is the default action, when no command is provided to nm object.
                     Reference to D-Bus:
                     No simple reference.

              sleep
                     Put NetworkManager to sleeping mode.  Thus all interfaces that NetworkManager manages are deactivated.
                     Reference to D-Bus:
                     interface: org.freedesktop.NetworkManager
                     method:    Sleep
                     arguments: TRUE

              wakeup
                     Awake NetworkManager from sleep.  When NetworkManager is awaken, devices are available to be activated.
                     Reference to D-Bus:
                     interface: org.freedesktop.NetworkManager
                     method:    Sleep
                     arguments: FALSE

              wifi [on|off]
                     Inquire or set status of WiFi in NetworkManager.  Without any further argument, WiFi status is printed; on enables WiFi; off disables WiFi.
                     Reference to D-Bus:
                     No simple reference.

              wwan [on|off]
                     Inquire or set status of WWAN in NetworkManager.  Without any further argument, WWAN status is printed; on enables WWAN; off disables WWAN.
                     Reference to D-Bus:
                     No simple reference.

       con    Connections
              Get information about NetworkManager’s connections.

       con    Connections
              Get information about NetworkManager’s connections.

          COMMAND := { list | status | up | down }

              list [id <id> | uuid <id> | system | user]
                     List configured connections.  Without a parameter, configured connection from both system and user settings services are listed.  system argument filters only system-wide connections, user
                     prints user connections only.  In order to get connection details, id with connection’s name or uuid with connection’s UUID shall be specified.  When no command is given to con object, the
                     default action is ’nmcli con list’.
                     Reference to D-Bus:
                     No simple reference.

              status
                     Print status of active connections.
                     Reference to D-Bus:
                     No simple reference.

              up id <id> | uuid <id> [iface <iface>] [ap <hwaddr>] [--nowait] [--timeout <timeout>]
                     Activate a connection.  The connection is identified by its name using id or UUID using uuid.  For requiring particular device to activate the connection on, iface option with interface name
                     should be given.  ap option can further concretize what AP should be used in case of WiFi connection.  --nowait option causes nmcli to exit immediately and not to wait for command completion.
                     --timeout option provides a means to specify how long to wait for operation completion.
                     Reference to D-Bus:
                     interface: org.freedesktop.NetworkManager
                     method:    ActivateConnection
                     arguments: according to arguments

              down id <id> | uuid <id>
                     Deactivate a connection.  The connection is identified by its name using id or UUID using uuid.
                     Reference to D-Bus:
                     interface: org.freedesktop.NetworkManager
                     method:    DeactivateConnection
                     arguments: according to arguments
 dev    Devices
              Get information about devices.

          COMMAND := { status | list | disconnect | wifi }

              status
                     Print status of devices.  This is the default action, when no command is specified to dev object.
                     Reference to D-Bus:
                     No simple reference.

              list [iface <iface>]
                     Get detailed information about devices.  Without an argument, all devices are examined.  To get information for a specific device, iface argument with the interface name should be provided.
                     Reference to D-Bus:
                     No simple reference.

              disconnect iface <iface> [--nowait] [--timeout <timeout>]
                     Disconnect a device and prevent the device from automatically activating further connections without user/manual intervention.  --nowait option causes nmcli to exit immediately and not to wait
                     for command completion.  --timeout option provides a means to specify how long to wait for operation completion.
                     Reference to D-Bus:
                     interface: org.freedesktop.NetworkManager.Device
                     method:    Disconnect
                     arguments: none

              wifi [list [iface <iface>] [hwaddr <hwaddr>]]
                     List available WiFi access points.  iface and hwaddr options can be used to get just APs for particular interface or specific AP, respectively.
                     Reference to D-Bus:
                     No simple reference.

BUGS
       There are probably some.  If you find a bug, please report to https://bugzilla.gnome.org/ - product NetworkManager.

SEE ALSO
       nm-tool(1), NetworkManager(8).

                                 14 April 2010                        NMCLI(1)
(END) 

答案1

列出可用连接:

nmcli con show

或者

nmcli connection show

编辑连接

nmcli con edit "connection name"

或者

nmcli connection edit "connection name"

设置静态IP:

nmcli> set ipv4.addresses 192.168.1.100/24
nmcli> save
nmcli> quit

然后重新启动网络管理器。

您可以通过以下方式查看配置的IP:

nmcli> print

要删除IP地址(您应该在添加静态IP之前使用它,以避免添加多个IP):

nmcli> remove ipv4.addresses

相关内容