centos7使用nmcli设置ip地址

2022-11-21 19:08:27 浏览数 (1)

代码语言:javascript复制
[root@localhost ~]# nmcli conn add type ethernet con-name ens35 ifname ens35
Connection 'ens35' (c32adfbd-b3fd-4484-a5d3-3b3f04cdfaa7) successfully added.
[root@localhost ~]# nmcli conn mod ens35 ipv4.address 192.168.20.111/24
[root@localhost ~]# nmcli conn mod ens35 ipv4.gateway 192.168.20.2
[root@localhost ~]# nmcli conn mod ens35 ipv4.dns 192.168.20.2
[root@localhost ~]# nmcli conn mod ens35 ipv4.method manual
[root@localhost ~]# nmcli conn up ens35
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/27)

ipv4后边可以跟以下内容:
 [method, dns, dns-search, dns-options, dns-priority, addresses, gateway, routes, route-metric, ignore-auto-routes, ignore-auto-dns, dhcp-hostname, dhcp-send-hostname, never-default, may-fail, dad-timeout, dhcp-timeout, dhcp-client-id, dhcp-fqdn].

命令参数:

代码语言:javascript复制
conn 就是connection的缩写 表示要对连接进行操作
add 表示添加连接
type 类型
con-name  连接的名字
ifname 网卡名
mod 是modify的缩写 表示要修改连接

0 人点赞