知乎專欄 | 多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者” |
# yum install NetworkManager-tui # nmtui
┌─┤ NetworkManager TUI ├──┐ │ │ │ Please select an option │ │ │ │ Edit a connection │ │ Activate a connection │ │ Set system hostname │ │ │ │ Quit │ │ │ │ <OK> │ │ │ └─────────────────────────┘
# nmtui # nmtui edit eno16777736 # nmtui connect eno1677773
nmcli 是 nmtui 命令行版本。
nmclinmcli 有 8 個參數: help 提供有關 nmcli 命令和使用方法的幫助信息 general 返回 NetworkManager 的狀態和總體配置信息 networking 提供命令來查詢某個網絡連接的狀態和啟動、禁用連接的功能 radio 提供命令來查詢某個 WiFi 網絡連接的狀態和啟動、禁用連接的功能 monitor 提供命令來監控 NetworkManager 的活動並觀察網絡連接的狀態改變 connection 提供命令來啟用或禁用網絡介面、添加新的連接、刪除已有連接等功能 device 主要被用於更改與某個設備(例如介面名稱)相關聯的連接參數或者使用一個已有的連接來連接設備 secret 註冊 nmcli 來作為一個 NetworkManager 的秘密代理,用以監聽秘密信息。這個子命令很少會被用到,因為當連接到網絡時,nmcli 會自動做這些事
[root@localhost ~]# nmcli general STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN connected full enabled enabled enabled enabled
[root@localhost ~]# nmcli connection show NAME UUID TYPE DEVICE enp8s0 ff04c285-bca6-48a3-b769-4871897bca7b ethernet enp8s0 docker0 b5bcd58d-b826-4bee-b100-4ae6976d6f76 bridge docker0 The Peninsula 3-6 dc0d8214-3589-4044-9a05-8b5f50c3de1f wifi --
顯示激活狀態的介面
[root@localhost ~]# nmcli connection show NAME UUID TYPE DEVICE enp8s0 ff04c285-bca6-48a3-b769-4871897bca7b ethernet enp8s0 The Peninsula 3-6 dc0d8214-3589-4044-9a05-8b5f50c3de1f wifi -- [root@localhost ~]# nmcli connection show --active NAME UUID TYPE DEVICE enp8s0 ff04c285-bca6-48a3-b769-4871897bca7b ethernet enp8s0
$ nmcli connection modify enp8s0 ipv4.address 192.168.4.26/24 $ nmcli connection modify enp8s0 ipv4.method manual
DHCP
$ nmcli connection modify enp8s0 ipv4.method auto
[root@localhost ~]# nmcli connection modify enp8s0 ipv4.address 192.168.3.26/24 [root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp8s0 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=dhcp 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=enp8s0 UUID=ff04c285-bca6-48a3-b769-4871897bca7b DEVICE=enp8s0 ONBOOT=yes IPADDR=192.168.3.26 PREFIX=24 [root@localhost ~]# ip addr show enp8s0: 2: enp8s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:26:9e:6f:bb:23 brd ff:ff:ff:ff:ff:ff inet 192.168.3.6/24 brd 192.168.3.255 scope global dynamic noprefixroute enp8s0 valid_lft 601424sec preferred_lft 601424sec inet6 fe80::82e7:1911:232:d93/64 scope link noprefixroute valid_lft forever preferred_lft forever
[root@localhost ~]# nmcli connection down docker0 Connection 'docker0' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2) [root@localhost ~]# nmcli connection show NAME UUID TYPE DEVICE enp8s0 ff04c285-bca6-48a3-b769-4871897bca7b ethernet enp8s0 The Peninsula 6-3C dc0d8214-3589-4044-9a05-8b5f50c3de1f wifi --
[root@localhost ~]# nmcli connection edit enp8s0
print 顯示配置信息
nmcli> print =============================================================================== Connection profile details (enp8s0) =============================================================================== connection.id: enp8s0 connection.uuid: ff04c285-bca6-48a3-b769-4871897bca7b connection.stable-id: -- connection.type: 802-3-ethernet connection.interface-name: enp8s0 connection.autoconnect: yes connection.autoconnect-priority: 0 connection.autoconnect-retries: -1 (default) connection.multi-connect: 0 (default) connection.auth-retries: -1 connection.timestamp: 1599726610 connection.read-only: no connection.permissions: -- connection.zone: -- connection.master: -- connection.slave-type: -- connection.autoconnect-slaves: -1 (default) connection.secondaries: -- connection.gateway-ping-timeout: 0 connection.metered: unknown connection.lldp: default connection.mdns: -1 (default) connection.llmnr: -1 (default) connection.wait-device-timeout: -1 ------------------------------------------------------------------------------- 802-3-ethernet.port: -- 802-3-ethernet.speed: 0 802-3-ethernet.duplex: -- 802-3-ethernet.auto-negotiate: no 802-3-ethernet.mac-address: -- 802-3-ethernet.cloned-mac-address: -- 802-3-ethernet.generate-mac-address-mask:-- 802-3-ethernet.mac-address-blacklist: -- 802-3-ethernet.mtu: auto 802-3-ethernet.s390-subchannels: -- 802-3-ethernet.s390-nettype: -- 802-3-ethernet.s390-options: -- 802-3-ethernet.wake-on-lan: default 802-3-ethernet.wake-on-lan-password: -- ------------------------------------------------------------------------------- ipv4.method: auto ipv4.dns: -- ipv4.dns-search: -- ipv4.dns-options: -- ipv4.dns-priority: 0 ipv4.addresses: 192.168.3.26/24 ipv4.gateway: -- ipv4.routes: -- ipv4.route-metric: -1 ipv4.route-table: 0 (unspec) ipv4.routing-rules: -- ipv4.ignore-auto-routes: no ipv4.ignore-auto-dns: no ipv4.dhcp-client-id: -- ipv4.dhcp-iaid: -- ipv4.dhcp-timeout: 0 (default) ipv4.dhcp-send-hostname: yes ipv4.dhcp-hostname: -- ipv4.dhcp-fqdn: -- ipv4.dhcp-hostname-flags: 0x0 (none) ipv4.never-default: no ipv4.may-fail: yes ipv4.dad-timeout: -1 (default) ------------------------------------------------------------------------------- ipv6.method: auto ipv6.dns: -- ipv6.dns-search: -- ipv6.dns-options: -- ipv6.dns-priority: 0 ipv6.addresses: -- ipv6.gateway: -- ipv6.routes: -- ipv6.route-metric: -1 ipv6.route-table: 0 (unspec) ipv6.routing-rules: -- ipv6.ignore-auto-routes: no ipv6.ignore-auto-dns: no ipv6.never-default: no ipv6.may-fail: yes ipv6.ip6-privacy: -1 (unknown) ipv6.addr-gen-mode: stable-privacy ipv6.ra-timeout: 0 (default) ipv6.dhcp-duid: -- ipv6.dhcp-iaid: -- ipv6.dhcp-timeout: 0 (default) ipv6.dhcp-send-hostname: yes ipv6.dhcp-hostname: -- ipv6.dhcp-hostname-flags: 0x0 (none) ipv6.token: -- ------------------------------------------------------------------------------- proxy.method: none proxy.browser-only: no proxy.pac-url: -- proxy.pac-script: -- ------------------------------------------------------------------------------- nmcli>
設置 DHCP
nmcli> goto ipv4 You may edit the following properties: method, dns, dns-search, dns-options, dns-priority, addresses, gateway, routes, route-metric, route-table, routing-rules, ignore-auto-routes, ignore-auto-dns, dhcp-client-id, dhcp-iaid, dhcp-timeout, dhcp-send-hostname, dhcp-hostname, dhcp-fqdn, dhcp-hostname-flags, never-default, may-fail, dad-timeout nmcli ipv4> set method auto Do you also want to clear 'ipv4.addresses'? [yes]: nmcli ipv4> save Connection 'enp8s0' (ff04c285-bca6-48a3-b769-4871897bca7b) successfully updated. nmcli ipv4> quit
[root@localhost ~]# nmcli device status DEVICE TYPE STATE CONNECTION enp8s0 ethernet connected enp8s0 docker0 bridge unmanaged -- lo loopback unmanaged -- wlp5s0 wifi unmanaged --
網卡設備詳細信息
[root@localhost ~]# nmcli device show enp8s0 GENERAL.DEVICE: enp8s0 GENERAL.TYPE: ethernet GENERAL.HWADDR: 00:26:9E:6F:BB:23 GENERAL.MTU: 1500 GENERAL.STATE: 100 (connected) GENERAL.CONNECTION: enp8s0 GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/1 WIRED-PROPERTIES.CARRIER: on IP4.ADDRESS[1]: 192.168.3.6/24 IP4.GATEWAY: 192.168.3.1 IP4.ROUTE[1]: dst = 0.0.0.0/0, nh = 192.168.3.1, mt = 100 IP4.ROUTE[2]: dst = 192.168.3.0/24, nh = 0.0.0.0, mt = 100 IP4.DNS[1]: 192.168.3.1 IP4.DOMAIN[1]: home IP6.ADDRESS[1]: fe80::82e7:1911:232:d93/64 IP6.GATEWAY: -- IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 100 IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255