|
|
|
@ -0,0 +1,613 @@
|
|
|
|
|
<h1><center>Stream9 网络配置</center></h1>
|
|
|
|
|
|
|
|
|
|
作者:行癫(盗版必究)
|
|
|
|
|
|
|
|
|
|
------
|
|
|
|
|
|
|
|
|
|
## 一:NetworkManager基础
|
|
|
|
|
|
|
|
|
|
#### 1.简介
|
|
|
|
|
|
|
|
|
|
红帽公司在2004年发起了NetworkManager项目,其目标是让Linux用户能够更容易的处理现代的网络需求,特别是无线网络
|
|
|
|
|
|
|
|
|
|
NetworkManager项目是第一个在Linux桌面上广泛使用D-Bus与HAL的组件
|
|
|
|
|
|
|
|
|
|
2009年6月起,NetworkManager已不再依赖于HAL
|
|
|
|
|
|
|
|
|
|
NetworkManager也不再需要D-Bus守护进程来执行根用户操作
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
D-Bus是一个行程间通讯及远程过程调用机制,可以让多个不同的计算机程序(即行程)在同一台电脑上同时进行通讯,其设计目的是使Linux桌面环境(如GNOME与KDE等)提供的服务标准化
|
|
|
|
|
|
|
|
|
|
HAL是类 UNIX操作系统的软件子系统,提供硬件抽象
|
|
|
|
|
|
|
|
|
|
#### 2.组成
|
|
|
|
|
|
|
|
|
|
NetworkManager守护进程
|
|
|
|
|
|
|
|
|
|
多种不同外观的图形前端及命令行接口
|
|
|
|
|
|
|
|
|
|
#### 3.管理工具
|
|
|
|
|
|
|
|
|
|
NetworkManagement:KDE SC 4的NetworkManager前端,plasma控件前端
|
|
|
|
|
|
|
|
|
|
KNetworkManager:由Novell所开发的KDE 3前端
|
|
|
|
|
|
|
|
|
|
nm-applet:GNOME的NetworkManager小工具
|
|
|
|
|
|
|
|
|
|
nmcli:内置的命令行界面(于2010年加入)
|
|
|
|
|
|
|
|
|
|
nmtui:内置的文字接口;其并不完整
|
|
|
|
|
|
|
|
|
|
cnetworkmanager:NetworkManager的命令行界面
|
|
|
|
|
|
|
|
|
|
#### 4.详解
|
|
|
|
|
|
|
|
|
|
第一个概念是Device,也就是设备,一个设备对应一个网口,基本上ip link里看到的那些都有对应的设备,基本上可以认为就是物理的网卡,每个物理网卡都会是一个device,当然,有些虚拟的网卡,也会是一个device,比如网桥bridge等。当然也有些区别,物理网卡是现实存在的设备,本质上最终是NetworkManager来管理它,而虚拟机网卡就是NetworkManager因为连接需要而生成的网卡。使用命令,可以看到当前NetworkManager所识别的设备,以及:这个设备是否在NetworkManager的管理之下;设备所对应的连接配置信息;设备当前的连接配置
|
|
|
|
|
|
|
|
|
|
可以很明确的看到我这台机器有两个设备,分别是eth0和lo,其中eth0是以太网类型,被NetworkManager管理且对应的连接配置为eth0,而lo是loopback,目前不被NetworkManager所管理。在终端里执行,正常的设备会显示绿色,不正常的设备显示成红色,不被管理的显示为灰色
|
|
|
|
|
|
|
|
|
|
![image-20230624161955404](https://xingdian-image.oss-cn-beijing.aliyuncs.com/xingdian-image/image-20230624161955404.png)
|
|
|
|
|
|
|
|
|
|
第一个概念是*connection*,也就是连接。连接就是一系列配置,比如IP地址获取方式是DHCP或者手动配置,如果是手动配置,则配置哪些IP地址,网关,DNS等等信息
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 二:Centos Stream 9 网络
|
|
|
|
|
|
|
|
|
|
#### 1.网卡配置文件
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# cd /etc/NetworkManager/system-connections
|
|
|
|
|
[root@xingdiancloud system-connections]# ls ens3.nmconnection
|
|
|
|
|
[root@xingdiancloud system-connections]# cat ens3.nmconnection [connection] id=ens3 uuid=1fba3c55-be8d-3cf9-9943-7e85d86168cf type=ethernet autoconnect-priority=-999 interface-name=ens3 timestamp=1683711036 [ethernet] [ipv4] method=auto [ipv6] addr-gen-mode=eui64 method=auto [proxy]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
参数解释
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
method=manual // 手动配置IP
|
|
|
|
|
method=dhcp // dhcp获取IP
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 2.配置IP地址
|
|
|
|
|
|
|
|
|
|
动态IP(默认)
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud system-connections]# cat ens3.nmconnection
|
|
|
|
|
[connection]
|
|
|
|
|
id=ens3
|
|
|
|
|
uuid=1fba3c55-be8d-3cf9-9943-7e85d86168cf
|
|
|
|
|
type=ethernet
|
|
|
|
|
autoconnect-priority=-999
|
|
|
|
|
interface-name=ens3
|
|
|
|
|
timestamp=1683711036
|
|
|
|
|
[ethernet]
|
|
|
|
|
[ipv4]
|
|
|
|
|
method=auto
|
|
|
|
|
[ipv6]
|
|
|
|
|
addr-gen-mode=eui64
|
|
|
|
|
method=auto
|
|
|
|
|
[proxy]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
手动IP
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud system-connections]# cat ens3.nmconnection
|
|
|
|
|
[connection]
|
|
|
|
|
id=ens3
|
|
|
|
|
uuid=1fba3c55-be8d-3cf9-9943-7e85d86168cf
|
|
|
|
|
type=ethernet
|
|
|
|
|
autoconnect-priority=-999
|
|
|
|
|
interface-name=ens3
|
|
|
|
|
timestamp=1683711036
|
|
|
|
|
[ethernet]
|
|
|
|
|
[ipv4]
|
|
|
|
|
method=manual
|
|
|
|
|
address=10.9.12.136/24,10.9.12.1
|
|
|
|
|
dns=223.5.5.5;114.114.114.114;8.8.8.8
|
|
|
|
|
[ipv6]
|
|
|
|
|
addr-gen-mode=eui64
|
|
|
|
|
method=auto
|
|
|
|
|
[proxy]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
修改后重启服务
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# systemctl restart NetworkManager.service
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 三:nmcli命令行
|
|
|
|
|
|
|
|
|
|
#### 1.语法格式
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
|
|
|
|
|
[root@xingdiancloud ~]# nmcli -h
|
|
|
|
|
用法:nmcli [选项] 对象 { 命令 | help }
|
|
|
|
|
|
|
|
|
|
选项
|
|
|
|
|
-a, --ask 询问缺少的参数
|
|
|
|
|
-c, --colors auto|yes|no 是否在输出中使用颜色
|
|
|
|
|
-e, --escape yes|no 转义值中的列分隔符
|
|
|
|
|
-f, --fields <字段,...>|all|common 指定要输出的字段
|
|
|
|
|
-g, --get-values <字段,...>|all|common -m tabular -t -f 的快捷方式
|
|
|
|
|
-h, --help 打印此帮助
|
|
|
|
|
-m, --mode tabular|multiline 输出模式
|
|
|
|
|
-o, --overview 概览模式
|
|
|
|
|
-p, --pretty 美化输出
|
|
|
|
|
-s, --show-secrets 允许显示密码
|
|
|
|
|
-t, --terse 简介输出
|
|
|
|
|
-v, --version 显示程序版本
|
|
|
|
|
-w, --wait <秒数> 设定操作完成的等待超时
|
|
|
|
|
|
|
|
|
|
对象
|
|
|
|
|
g[eneral] NetworkManager 的常规状态和操作
|
|
|
|
|
n[etworking] 整体网络控制
|
|
|
|
|
r[adio] NetworkManager 无线电开关
|
|
|
|
|
c[onnection] NetworkManager 的连接
|
|
|
|
|
d[evice] NetworkManager 管理的设备
|
|
|
|
|
a[gent] NetworkManager 机密(secret)或 polkit 代理
|
|
|
|
|
m[onitor] 监视 NetworkManager 更改
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 2.对象g
|
|
|
|
|
|
|
|
|
|
NetworkManager常规操作
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli g -h
|
|
|
|
|
Usage: nmcli general { COMMAND | help }
|
|
|
|
|
COMMAND := { status | hostname | permissions | logging | reload }
|
|
|
|
|
status
|
|
|
|
|
hostname [<hostname>]
|
|
|
|
|
permissions
|
|
|
|
|
logging [level <log level>] [domains <log domains>]
|
|
|
|
|
reload [<flags>]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
查看状态
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli g status
|
|
|
|
|
STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
|
|
|
|
|
已连接 完全 missing 已启用 missing 已启用
|
|
|
|
|
|
|
|
|
|
STATE 显示网络是否连接
|
|
|
|
|
WIFI-HW 表示 WIFI 硬件开关、WIFI 表示 WIFI 软件开关
|
|
|
|
|
WWAN-HW 表示 WWAN 硬件开关、WWAN 表示 WWAN 软件开关
|
|
|
|
|
HW 代表 HardWare,WWAN 代表 Wireless Wide Area Network
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
修改主机名
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli g hostname xingdiancloud
|
|
|
|
|
|
|
|
|
|
主机名存放在 /etc/hostname 文件中
|
|
|
|
|
修改主机名后,需要重启 NetworkManager
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
显示当前用户对NetworkManager的操作权限
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli g permissions
|
|
|
|
|
PERMISSION VALUE
|
|
|
|
|
org.freedesktop.NetworkManager.checkpoint-rollback 是
|
|
|
|
|
org.freedesktop.NetworkManager.enable-disable-connectivity-check 是
|
|
|
|
|
org.freedesktop.NetworkManager.enable-disable-network 是
|
|
|
|
|
org.freedesktop.NetworkManager.enable-disable-statistics 是
|
|
|
|
|
org.freedesktop.NetworkManager.enable-disable-wifi 是
|
|
|
|
|
org.freedesktop.NetworkManager.enable-disable-wimax 是
|
|
|
|
|
org.freedesktop.NetworkManager.enable-disable-wwan 是
|
|
|
|
|
org.freedesktop.NetworkManager.network-control 是
|
|
|
|
|
org.freedesktop.NetworkManager.reload 是
|
|
|
|
|
org.freedesktop.NetworkManager.settings.modify.global-dns 是
|
|
|
|
|
org.freedesktop.NetworkManager.settings.modify.hostname 是
|
|
|
|
|
org.freedesktop.NetworkManager.settings.modify.own 是
|
|
|
|
|
org.freedesktop.NetworkManager.settings.modify.system 是
|
|
|
|
|
org.freedesktop.NetworkManager.sleep-wake 是
|
|
|
|
|
org.freedesktop.NetworkManager.wifi.scan 是
|
|
|
|
|
org.freedesktop.NetworkManager.wifi.share.open 是
|
|
|
|
|
org.freedesktop.NetworkManager.wifi.share.protected 是
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
获取和更改NetworkManager日志记录级别和域
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli g logging
|
|
|
|
|
LEVEL DOMAINS
|
|
|
|
|
INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6,AUTOIP4,DNS,VPN,SHARING,SUPPLICANT,AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,INFINIBAND,FIREWALL,ADSL,BOND,VLAN,BRIDGE,TEAM,CONCHECK,DCB,DISPATCH,AUDIT,SYSTEMD,PROXY
|
|
|
|
|
|
|
|
|
|
[root@xingdiancloud ~]# nmcli g logging level WARN domains proxy,BT //没有特殊要求不要修改
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
NetworkManager日志级别:ERR, WARN, INFO, DEBUG, TRACE
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
关闭将禁用所有日志记录。INFO是常规操作的默认详细信息。TRACE用于调试;其他级别在大多数情况下都没有用处。例如,DEBUG介于TRACE和INFO之间,但它也是对于常规操作来说是冗长的,并且可能缺少用于调试的有趣消息。几乎总是,当调试问题或报告错误,收集完整级别的TRACE日志以获取完整信息
|
|
|
|
|
|
|
|
|
|
在排除某些主题的罕见情况下,以下日志域可用:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
PLATFORM:操作系统(平台)操作
|
|
|
|
|
RFKILL:RFKILL子系统操作
|
|
|
|
|
ETHER:以太网设备操作
|
|
|
|
|
WIFI:Wi-Fi设备操作
|
|
|
|
|
BT:蓝牙操作
|
|
|
|
|
MB:移动宽带运营
|
|
|
|
|
DHCP4:IPv4的DHCP
|
|
|
|
|
DHCP6:用于IPv6的DHCP
|
|
|
|
|
PPP:点对点协议操作
|
|
|
|
|
WIFI_SCAN:Wi-Fi扫描操作
|
|
|
|
|
IP4:IPv4相关操作
|
|
|
|
|
IP6:IPv6相关操作
|
|
|
|
|
AUTOIP4:自动IP操作
|
|
|
|
|
DNS:域名系统相关操作
|
|
|
|
|
VPN:虚拟专用网络连接和操作
|
|
|
|
|
SHARING:连接共享。使用针对dnsmasq实例的TRACE级别日志查询
|
|
|
|
|
SUPPLICANT:WPA请求程序相关操作
|
|
|
|
|
AGENTS:特工行动和通讯
|
|
|
|
|
SETTINGS:设置/配置服务操作
|
|
|
|
|
SUSPEND(暂停):暂停/恢复
|
|
|
|
|
CORE:核心守护进程和策略操作
|
|
|
|
|
DEVICE:激活和通用界面操作
|
|
|
|
|
OLPC:OLPC网格设备操作
|
|
|
|
|
WIMAX:WIMAX设备操作
|
|
|
|
|
INFINIBAND:INFINIBAND设备操作
|
|
|
|
|
FIREWALL:防火墙相关操作
|
|
|
|
|
ADSL:ADSL设备操作
|
|
|
|
|
BOND:粘接操作
|
|
|
|
|
VLAN:VLAN操作
|
|
|
|
|
BRIDG:桥接操作
|
|
|
|
|
DBUS_PROPS:D-Bus属性更改
|
|
|
|
|
TEAM:团队运作
|
|
|
|
|
CONCHECK:连接检查
|
|
|
|
|
DCB:数据中心桥接(DCB)操作
|
|
|
|
|
DISPATCH:调度程序脚本
|
|
|
|
|
AUDIT:审计记录
|
|
|
|
|
SYSTEMD:来自内部libsystemd的消息
|
|
|
|
|
VPN_PLUGIN:记录来自VPN插件的消息
|
|
|
|
|
PROXY:记录代理处理的消息
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
重新加载配置
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli g reload
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 3.对象n
|
|
|
|
|
|
|
|
|
|
整体网络控制
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli n -h
|
|
|
|
|
用法:nmcli networking { 命令 | help }
|
|
|
|
|
命令 := { [ on | off | connectivity ] }
|
|
|
|
|
on
|
|
|
|
|
off
|
|
|
|
|
connectivity [check]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
关闭所有网络连接
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli n off
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
开启所有网络连接
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli n on
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
获取网络状态
|
|
|
|
|
|
|
|
|
|
none :主机未连接到任何网络
|
|
|
|
|
|
|
|
|
|
portal:主机在一个被捕获的入口之后并且无法访问整个互联网络。
|
|
|
|
|
|
|
|
|
|
limited:主机已经连接到网络,但是无法访问互联网
|
|
|
|
|
|
|
|
|
|
full:主机已经连接到网络,并且可以访问互联网
|
|
|
|
|
|
|
|
|
|
unknown:未知状态
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli n connectivity
|
|
|
|
|
full
|
|
|
|
|
[root@xingdiancloud ~]# nmcli n connectivity check
|
|
|
|
|
full
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
check参数告诉NetworkManager重新检测网络连接性,否则将显示最近感知的网络状态,并且不重新检测
|
|
|
|
|
|
|
|
|
|
4.对象r
|
|
|
|
|
|
|
|
|
|
NetworkManager 无线电开关
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli r h
|
|
|
|
|
用法:nmcli radio { 命令 | help }
|
|
|
|
|
命令 := { all | wifi | wwan }
|
|
|
|
|
all | wifi | wwan [ on | off ]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
显示无线交换机开关状态,或开启和关闭交换机
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli r
|
|
|
|
|
WIFI-HW WIFI WWAN-HW WWAN
|
|
|
|
|
missing 已禁用 missing 已禁用
|
|
|
|
|
[root@xingdiancloud ~]# nmcli g s
|
|
|
|
|
STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
|
|
|
|
|
已连接 完全 missing 已启用 missing 已启用
|
|
|
|
|
[root@xingdiancloud ~]# nmcli r all off
|
|
|
|
|
[root@xingdiancloud ~]# nmcli g s
|
|
|
|
|
STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
|
|
|
|
|
已连接 完全 missing 已禁用 missing 已禁用
|
|
|
|
|
[root@xingdiancloud ~]# nmcli r all on
|
|
|
|
|
[root@xingdiancloud ~]# nmcli r
|
|
|
|
|
WIFI-HW WIFI WWAN-HW WWAN
|
|
|
|
|
missing 已启用 missing 已启用
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 4.对象c(重点)
|
|
|
|
|
|
|
|
|
|
NetworkManager 的连接
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c -h
|
|
|
|
|
用法:nmcli connection { 命令 | help }
|
|
|
|
|
命令 := { show | up | down | add | modify | clone | edit | delete | monitor | reload | load | import | export }
|
|
|
|
|
show [--active] [--order <排序规则>]
|
|
|
|
|
show [--active] [id | uuid | path | apath] <ID> ...
|
|
|
|
|
up [[id | uuid | path] <ID>] [ifname <接口名称>] [ap <BSSID>] [passwd-file <密码文件>]
|
|
|
|
|
down [id | uuid | path | apath] <ID> ...
|
|
|
|
|
add 常用选项 类型特定选项 从选项 IP_选项 [-- ([+|-]<设置>.<属性> <值>)+]
|
|
|
|
|
modify [--temporary] [id | uuid | path] <ID> ([+|-]<设置>.<属性> <值>)+
|
|
|
|
|
clone [--temporary] [id | uuid | path ] <ID> <新名称>
|
|
|
|
|
edit [id | uuid | path] <ID>
|
|
|
|
|
edit [type <新连接类型>] [con-name <新连接名称>]
|
|
|
|
|
delete [id | uuid | path] <ID>
|
|
|
|
|
monitor [id | uuid | path] <ID> ...
|
|
|
|
|
reload
|
|
|
|
|
load <文件名> [ <文件名>... ]
|
|
|
|
|
import [--temporary] type <类型> file <要导入的文件>
|
|
|
|
|
export [id | uuid | path] <ID> [<输出文件>]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
显示所有网络连接的信息
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c show
|
|
|
|
|
NAME UUID TYPE DEVICE
|
|
|
|
|
ens160 639d6c39-a14a-36f9-b18f-7c1ff3c082d7 ethernet ens160
|
|
|
|
|
lo 178dd56f-118d-4b71-9fc6-90324e7df976 loopback lo
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c
|
|
|
|
|
NAME UUID TYPE DEVICE
|
|
|
|
|
ens160 639d6c39-a14a-36f9-b18f-7c1ff3c082d7 ethernet ens160
|
|
|
|
|
lo 178dd56f-118d-4b71-9fc6-90324e7df976 loopback lo
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
connection 可以简写为 c、co、con、conn……
|
|
|
|
|
|
|
|
|
|
show 是 connection 的默认项,可以省略不写
|
|
|
|
|
|
|
|
|
|
显示某一特定连接的详细信息
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c s ens160
|
|
|
|
|
connection.id: ens160
|
|
|
|
|
connection.uuid: 639d6c39-a14a-36f9-b18f-7c1ff3c082d7
|
|
|
|
|
connection.stable-id: --
|
|
|
|
|
connection.type: 802-3-ethernet
|
|
|
|
|
connection.interface-name: ens160
|
|
|
|
|
connection.autoconnect: 是
|
|
|
|
|
connection.autoconnect-priority: -999
|
|
|
|
|
......
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
启动指定连接
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c up ens33
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
关闭指定连接
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c down ens33
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
修改连接
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c m ens33 ipv4.address 192.168.80.10/24 # 修改 IP 地址和子网掩码
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c m ens33 +ipv4.addresses 192.168.80.100/24
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c m ens33 ipv4.method manual # 修改为静态配置,默认是 auto
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c m ens33 ipv4.gateway 192.168.80.2 # 修改默认网关
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c m ens33 ipv4.dns 192.168.80.2 # 修改 DNS
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c m ens33 +ipv4.dns 114.114.114.114 # 添加一个 DNS
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c m ens33 ipv6.method ignored # 将 IPv6 禁用,针对CentOS8,三个可选项:disabled、auto、manual
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c m ens33 connection.autoconnect yes # 开机启动
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
注意,必须先修改 ipv4.address,然后才能修改 ipv4.method
|
|
|
|
|
|
|
|
|
|
用空引号""代替选项的值,可将选项设回默认值
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c m ens33 ipv4.method ""
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
选项有很多,详细信息可以通过以下命令查看
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# man 5 nm-settings-nmcli
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
新增连接
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c a type ethernet con-name ens36 ifname ens36
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
type 为必选项,我们通常用到的是 802-3-ethernet(别名 ethernet)
|
|
|
|
|
|
|
|
|
|
选项与前面介绍的“修改连接”中的选项一样,其中重要的几个选项:
|
|
|
|
|
|
|
|
|
|
connection.id(别名 con-name):连接名
|
|
|
|
|
|
|
|
|
|
connection.interface-name(别名 ifname):设备名
|
|
|
|
|
|
|
|
|
|
connection.autoconnect(别名 autoconnect):是否开机自启,其值只能是 yes 或 no,默认 yes
|
|
|
|
|
|
|
|
|
|
删除指定连接
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c delete ens33 # 或
|
|
|
|
|
[root@xingdiancloud ~]# nmcli c de ens33 # delete 不可简写为 d,否则与 down 冲突,但可以简写为 de
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
重载所有连接的配置文件
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
nmcli c reload # 或
|
|
|
|
|
nmcli c r
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
重载某一指定连接的配置文件
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
nmcli c load ifcfg-ens33 # 或
|
|
|
|
|
nmcli c l ifcfg-ens33
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 5.对象d
|
|
|
|
|
|
|
|
|
|
NetworkManager 管理的设备
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d -h
|
|
|
|
|
用法:nmcli device { 命令 | help }
|
|
|
|
|
|
|
|
|
|
命令 := { status | show | set | connect | reapply | modify | disconnect | delete | monitor | wifi | lldp }
|
|
|
|
|
|
|
|
|
|
status
|
|
|
|
|
show [<接口名称>]
|
|
|
|
|
set [ifname] <接口名称> [autoconnect yes|no] [managed yes|no]
|
|
|
|
|
connect <接口名称>
|
|
|
|
|
reapply <接口名称>
|
|
|
|
|
modify <接口名称> ([+|-]<设置>.<属性> <值>)+
|
|
|
|
|
disconnect <接口名称> ...
|
|
|
|
|
delete <接口名称> ...
|
|
|
|
|
monitor <接口名称> ...
|
|
|
|
|
wifi [list [ifname <接口名称>] [bssid <BSSID>] [--rescan yes|no|auto]]
|
|
|
|
|
wifi connect <(B)SSID> [password <密码>] [wep-key-type key|phrase] [ifname <接口名称>]
|
|
|
|
|
[bssid <BSSID>] [name <名称>] [private yes|no] [hidden yes|no]
|
|
|
|
|
wifi hotspot [ifname <接口名称>] [con-name <名称>] [ssid <SSID>] [band a|bg] [channel <信道>] [password <密码>]
|
|
|
|
|
wifi rescan [ifname <接口名称>] [[ssid <要扫描的 SSID>] ...]
|
|
|
|
|
wifi show-password [ifname <接口名称>]
|
|
|
|
|
lldp [list [ifname <接口名称>]]
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
显示所有网络接口设备的状态
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d s
|
|
|
|
|
DEVICE TYPE STATE CONNECTION
|
|
|
|
|
ens160 ethernet 已连接 ens160
|
|
|
|
|
lo loopback 连接(外部) lo
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
device 可以简写为 d、de、dev……
|
|
|
|
|
|
|
|
|
|
status 是 device 的默认项,可以省略不写
|
|
|
|
|
|
|
|
|
|
显示所有设备的详细信息
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d show
|
|
|
|
|
GENERAL.DEVICE: ens160
|
|
|
|
|
GENERAL.TYPE: ethernet
|
|
|
|
|
GENERAL.HWADDR: 00:0C:29:53:2F:E9
|
|
|
|
|
GENERAL.MTU: 1500
|
|
|
|
|
GENERAL.STATE: 100(已连接)
|
|
|
|
|
GENERAL.CONNECTION: ens160
|
|
|
|
|
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/4
|
|
|
|
|
WIRED-PROPERTIES.CARRIER: 开
|
|
|
|
|
IP4.ADDRESS[1]: 10.0.0.116/24
|
|
|
|
|
IP4.GATEWAY: 10.0.0.2
|
|
|
|
|
IP4.ROUTE[1]: dst = 10.0.0.0/24, nh = 0.0.0.0, mt = 100
|
|
|
|
|
IP4.ROUTE[2]: dst = 0.0.0.0/0, nh = 10.0.0.2, mt = 100
|
|
|
|
|
IP4.DNS[1]: 8.8.8.8
|
|
|
|
|
IP6.ADDRESS[1]: fe80::20c:29ff:fe53:2fe9/64
|
|
|
|
|
IP6.GATEWAY: --
|
|
|
|
|
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 1024
|
|
|
|
|
|
|
|
|
|
GENERAL.DEVICE: lo
|
|
|
|
|
GENERAL.TYPE: loopback
|
|
|
|
|
GENERAL.HWADDR: 00:00:00:00:00:00
|
|
|
|
|
GENERAL.MTU: 65536
|
|
|
|
|
GENERAL.STATE: 100(连接(外部))
|
|
|
|
|
GENERAL.CONNECTION: lo
|
|
|
|
|
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/3
|
|
|
|
|
IP4.ADDRESS[1]: 127.0.0.1/8
|
|
|
|
|
IP4.GATEWAY: --
|
|
|
|
|
IP6.ADDRESS[1]: ::1/128
|
|
|
|
|
IP6.GATEWAY: --
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
显示某一特定设备的详细信息
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d sh ens33
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
连接设备
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d connect ens33
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d c ens33
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
如果 ens33 本来就出于连接状态,那此命令会重启 ens33
|
|
|
|
|
|
|
|
|
|
断开设备
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d disconnect ens33
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d d ens33
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
更新设备信息
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d reapply ens33
|
|
|
|
|
[root@xingdiancloud ~]# nmcli d r ens33
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注意:
|
|
|
|
|
|
|
|
|
|
只有在设备处于连接状态,才可以更新设备
|
|
|
|
|
|
|
|
|
|
更新设备也会重启连接
|