运行环境:VMware16pro + centos8.3
用途:提供网络配置界面。
命令:nmtui
用途:可以完成网卡上的所有配置,并写入配置文件中。
命令:nmcli [参数]
参数 | 说明 |
---|---|
d | 监控和管理网络设备的接口 |
c | 监控和管理网络设备的连接 |
说明 | 命令 |
---|---|
修改配置文件的主机名 | hostnamectl set-hostname name |
显示所有设备状态 | nmcli device status |
显示所有激活的连接 | nmcli connection show --active |
显示具体的网络连接信息 | nmcli connection show eth0 |
查看网卡信息 | nmcli connection 或 nmcli con show |
删除一个网卡连接 | nmcli connection delete eth0 |
添加一个网卡连接 | nmcli connection add type ethernet con-name eth0 ifname eno33 |
配置网卡: IP地址IPADDR 子网掩码NETMASK 网关GATEWAY DNS 搜索域DOMAIN 手动配置 |
nmcli connection modify bond0 ipv4.addresses 192.168.10.10 ipv4.addresses 192.168.10.10/24 ipv4.gateway 192.168.10.1 ipv4.dns 192.168.10.1 ipv4.dns-search baidu.com ipv4.method manual |
网络接口的启用/停用 | nmcli connection up/down ens33 |
重新加载网络服务 | nmcli connection reload ens33 |
[root@centos1905 yum.repos.d]# nmcli connection show
NAME UUID TYPE DEVICE
ens33 717781ac-6666-6666-6666-20184a9ad666 ethernet ens33
virbr0 1095bcf4-6666-6666-6666-2806870dffa7 bridge virbr0
[root@centos1905 yum.repos.d]# nmcli con show ens33
connection.id: ens33
connection.uuid: 717781ac-6666-6666-6666-20184a9ad666
connection.stable-id: --
connection.type: 666-3-ethernet
connection.interface-name: ens33
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.multi-connect: 0 (default)
connection.auth-retries: -1
connection.timestamp: 6666666666
[root@centos1905 ~]# nmcli connection modify bond0 ipv4.addresses 192.168.10.10
ipv4.addresses 192.168.10.10/24 ipv4.gateway 192.168.10.1 ipv4.dns 192.168.10.1
ipv4.dns-search baidu.com ipv4.method manual
BONDING_OPTS="miimon=100 mode=balance-alb"
TYPE=Bond
BONDING_MASTER=yes
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.10.10
PREFIX=24
GATEWAY=192.168.10.1
DNS1=192.168.10.1
DOMAIN=baidu.com
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=bond0
UUID=ad33d8b0-1f7b-cab9-9447-ba07f855b143
DEVICE=bond0
ONBOOT=yes
[root@CentOS64 ~]# nmtui
重启生效
[root@centos1905 network-scripts]# nmcli connection reload ens33
利用网络会话保存网络配置,只需在不同的环境激活相应的网络会话,就可以实现网络配置信息的切换。
格式:nmcli connection add con-name type ifname
命令 | 会话名称 | 网卡名称 | 是否自动激活 | 网络类型 | 地址 |
---|---|---|---|---|---|
nmcli connection add con-name | company | ifname ens33 | autoconnect no | type ethernet | ip4 192.168.10.10/24 gw4 192.168.10. |
[root@centos1905 yum.repos.d]# nmcli connection add con-name company ifname ens33 autoconnect
no type ethernet ip4 192.168.10.10/24 gw4 192.168.10.1
Connection 'company' (f06301b0-0293-4ad5-b16b-3dea23f2256a) successfully added.
[root@centos1905 yum.repos.d]# nmcli connection add con-name house type ethernet ifname ens33
Connection 'house' (aaa0c4ac-80ff-4fa3-9117-08c43cd2945c) successfully added.
格式:nmcli connection show
[root@centos1905 yum.repos.d]# nmcli connection show
NAME UUID TYPE DEVICE
ens33 717781ac-6c83-4464-a3e4-20184a9db717 ethernet ens33
virbr0 1095bcf4-c5a3-4525-b4f6-2806870dffa7 bridge virbr0
company f06301b0-0293-4ad5-b16b-3dea23f2256a ethernet --
house aaa0c4ac-80ff-4fa3-9117-08c43cd2945c ethernet --
格式:nmcli connection up ifname
[root@centos1905 yum.repos.d]# nmcli connection up house
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@centos1905 yum.repos.d]#
[root@centos1905 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
略
ens38: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
略
模式 | 名称 | 具体说明 |
---|---|---|
mode0 | balance-rr | 平衡轮转策略:两卡均工作,自动备援,需要交换机支持 |
mode1 | active-backup | 主-备份策略:一卡工作,自动备援 |
mode2 | balance-xor | 平衡策略 |
mode3 | broadcast | 广播策略 |
mode4 | 802.3ad | IEEE 802.3ad 动态链接聚合 |
mode5 | balance-tlb | 适配器传输负载均衡 |
mode6 | balance-alb | 适配器适应性负载均衡:两卡均工作,自动备援,无需交换机支持 |
名称 | 参数 |
---|---|
BOOTPROTO | 地址配置协议,常用的dhcp, static, none,bootp等 |
BONDING_MASTER | 是否为“主” |
BONDING_OPTS | “主”网卡模式参数。例如:采用mode6,切换时长100ms:mode=6 miimon=100 |
DNS | DNS地址 |
DEVICE | 配置应用设备 |
GATEWAY | 默认网关 |
HWADDR | 对应的设备的MAC地址 |
MASTER | “主”网卡 |
NETMASK | 子网掩码 |
NM_CONTROLLED | NM是NetworkManager的简写,此网卡是否接受NM控制 |
IPV4_FAILURE_FATAL | 如果为yes,则ipv4配置失败禁用设备 |
IPADDR | 指明IP地址 |
ONBOOT | 在系统引导时是否激活此设备 |
SLAVE | 是否为“从” |
TYPE | 接口类型。常见有的Ethernet, Bridge等 |
USERCTL | 普通用户是否可控制此设备 |
UUID | 通用唯一识别码 |
[root@centos1905 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO=none
DEVICE=ens33
NAME=ens33
ONBOOT=yes
MASTER=bond0
USERCTL=no
SLAVE=yes
[root@centos1905 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens38
BOOTPROTO=none
DEVICE=ens38
NAME=ens33
ONBOOT=yes
MASTER=bond0
USERCTL=no
SLAVE=yes
[root@centos1905 ~]# vim /etc/sysconfig/network-scripts/ifcfg-bond0
BOOTPROTO=static
NAME=bond0
DEVICE=bond0
ONBOOT=yes
BONDING_MASTER=yes
BONDING_OPTS="mode=6 miimon=100"
IPADDR=192.168.10.10
NETMASK=255.255.255.0
DNS=192.168.10.10
[root@centos1905 ~]# nmcli connection up bond0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
[root@centos1905 ~]# ping 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.072 ms
[centos1905@centos1905 ~]$ ifconfig
bond0: flags=5187<UP,BROADCAST,RUNNING,MASTER,MULTICAST> mtu 1500
inet 192.168.10.10 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::20c:29ff:fef6:6517 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:f6:65:17 txqueuelen 1000 (Ethernet)
RX packets 15 bytes 900 (900.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 196 bytes 14882 (14.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens33: flags=6211<UP,BROADCAST,RUNNING,SLAVE,MULTICAST> mtu 1500
ether 00:0c:29:f6:65:17 txqueuelen 1000 (Ethernet)
RX packets 15 bytes 900 (900.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 196 bytes 14882 (14.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
略
[centos1905@centos1905 ~]$ ping 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.043 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.042 ms
略
[root@centos1905 ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33
1 TYPE=Ethernet
2 PROXY_METHOD=none
3 BROWSER_ONLY=no
4 BOOTPROTO=none
5 DEFROUTE=yes
6 IPV4_FAILURE_FATAL=no
7 IPV6INIT=yes
8 IPV6_AUTOCONF=yes
9 IPV6_DEFROUTE=yes
10 IPV6_FAILURE_FATAL=no
11 IPV6_ADDR_GEN_MODE=stable-privacy
12 NAME=ens33
13 UUID=ad33d8b0-1f7b-cab9-9447-ba07f855b143
14 DEVICE=ens33
15 ONBOOT=yes
16 HWADDR=00:0c:29:f6:65:17
17 IPADDR=192.168.10.10
18 IPADDR1=192.168.10.20
19 IPADDR2=192.168.10.30
20 PREFIX=24
21 IPV6_PRIVACY=no
[root@centos1905 ~]# nmcli connection reload ens33
[root@centos1905 ~]# nmcli connection up ens33
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
[root@centos1905 ~]# ping 192.168.10.10
PING 192.168.10.10 (192.168.10.10) 56(84) bytes of data.
64 bytes from 192.168.10.10: icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from 192.168.10.10: icmp_seq=2 ttl=64 time=0.040 ms
^C
--- 192.168.10.10 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 88ms
rtt min/avg/max/mdev = 0.040/0.040/0.042/0.007 ms
[root@centos1905 ~]# ping 192.168.10.20
PING 192.168.10.20 (192.168.10.20) 56(84) bytes of data.
64 bytes from 192.168.10.20: icmp_seq=1 ttl=64 time=0.047 ms
64 bytes from 192.168.10.20: icmp_seq=2 ttl=64 time=0.042 ms
^C
--- 192.168.10.20 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 65ms
rtt min/avg/max/mdev = 0.042/0.043/0.047/0.008 ms
[root@centos1905 ~]# ping 192.168.10.30
PING 192.168.10.30 (192.168.10.30) 56(84) bytes of data.
64 bytes from 192.168.10.30: icmp_seq=1 ttl=64 time=0.041 ms
64 bytes from 192.168.10.30: icmp_seq=2 ttl=64 time=0.040 ms
^C
--- 192.168.10.30 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 73ms
rtt min/avg/max/mdev = 0.040/0.040/0.041/0.004 ms
1、nmcli参考:https://www.cnblogs.com/djlsunshine/p/9733182.html
2、绑定参考 :https://www.cnblogs.com/wangshuyang/p/12242823.html