Ubuntu20.04LTS包括两个版本:Server版本和Desktop版本,在 Ubuntu Server中,默认使用interfaces管理网络,而在Desktop版本中,默认使用NetworkManager来管理网络,那么如何在命令行中对NetworkManager进行管理呢?

使用nmcli命令

用户和脚本都可使用命令行工具 nmcli 控制 NetworkManager。该命令的基本格式为:

nmcli OPTIONS OBJECT { COMMAND | help }

其中 OBJECT 可为 generalnetworkingradioconnectiondevice 之一。最常用的选项为:-t, --terse(用于脚本)、-p, --pretty 选项(用于用户)及 -h, --help 选项。

~]$ nmcli help
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }

OPTIONS
  -t[erse]                                   terse output
  -p[retty]                                  pretty output
  -m[ode] tabular|multiline                  output mode
  -f[ields] <field1,field2,...>|all|common   specify fields to output
  -e[scape] yes|no                           escape columns separators in values
  -n[ocheck]                                 don't check nmcli and NetworkManager versions
  -a[sk]                                     ask for missing parameters
  -w[ait] <seconds>                          set timeout waiting for finishing operations
  -v[ersion]                                 show program version
  -h[elp]                                    print this help

OBJECT
  g[eneral]       NetworkManager's general status and operations
  n[etworking]    overall networking control
  r[adio]         NetworkManager radio switches
  c[onnection]    NetworkManager's connections
  d[evice]        devices managed by NetworkManager
以上内容来自redhat文档网站

那么,根据文档所说,我们就可以使用此命令来对网络信息进行修改

首先,我们需要查看网络的链接信息:

nmcli device show

使用此命令可以看到设备eno1上显示已连接的网络信息,对此网络进行修改,比如修改DNS:

nmcli device modify eno1 ipv4.dns 119.29.29.29

参考资料

更多的信息,可以访问下方的文档进行查看

2.3. 使用 NetworkManager 命令行工具 nmcli Red Hat Enterprise Linux 7 | Red Hat Customer Portal


LIZHI_STORE
如果觉得我的文章对你有用,请随意赞赏