Linux入门篇-RHEL8的网络管理

简介

没有比 Linux 网络管理更重要的知识。
只适用于 centos rhel 系列(不低于 rhel7 版本)

RHEL8网络管理服务

在早期的Linux发行版本里几乎所有的网络服务都是network服务,从RHEL7开始红帽官方建议采用
NetworkManager的“方式”配置网络,而不建议再使用network服务传统的方式配置网络。
原因:
网络是非常复杂的,需要配置的网络相关的参数非常多。早期配置网络的方法,几乎只有创建网卡配置
文件,添加网络参数,修改网络参数,然后重启network服务,让network服务加载网卡配置文件到内
存,然后让内核读取内存里面的网卡配置文件来获取网络配置。
NetworkManager早期的设计目的是为了统一网络配置,同一网络配置的意思就是以后所有网络相关的
配置都使用NetworkManager来实现。
NetworkManager服务提供了3种工具来让你配置我们的网卡参数,无论哪一种工具,都不需要你去手
工的修改网卡配置文件。
[root@server ~]# systemctl status NetworkManager
● NetworkManager.service - Network Manager
Loaded: loaded (/usr/lib/systemd/system/NetworkManager.service; enabled;
vendor preset: enabled)
Active: active (running) since 三 2020-04-22 10:40:56 CST; 3 days ago
Docs: man:NetworkManager(8)
Main PID: 1086 (NetworkManager)
CGroup: /system.slice/NetworkManager.service
└─1086 /usr/sbin/NetworkManager --no-daemon
确认NetworkManager服务是开启的,如果服务不开启,就无法使用NetworkManager提供的工具

RHEL8网络管理工具

如何在 workstation 当中添加删除网卡
1.图形工具
sudo yum install -y nm-connection-editor
[root@foundation0 ~]# nm-connection-editor
网络管理工具正常需要人为的指定配置文件和网卡名字的关系
如果是在控制台操作,系统必须安装图形软件才可以调用出来图形界面。
如果是远程操作,即使Linux并没有安装图形界面,远程的终端服务器必须安装了图形服务器软件才可
以调用出图形。(Xming,XManager)
2.伪图形工具(nmtui)(terminal UI)
通过终端的字符,模拟出图形界面,其实你看到的图形并不是真正的图形,而是字符组出来的。
3.nmcli(nm->network manager cli command line interface)
(1)nmcli查看我们的网卡参数---硬件层面
[root@rhel8 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens224 ethernet connected ens224
virbr0 bridge connected virbr0
ens256 ethernet disconnected --
lo loopback unmanaged --
virbr0-nic tun unmanaged --
总共4列:
第一列表示网卡名称(内核label)
第二列是网卡的类型(内核label)
第三列是当前网卡的状态(指的是NetworkManager服务是否接管了这块网卡)
如果第三列是unmanaged,就表示该块网卡并没有被NetworkManager服务接管。如果网卡没有被
NetworkManager服务接管,就意味着无法使用NetworkManager管理该网卡
如果第三列是disconnected,意味着该块网卡,并没有使用任何配置文件
如果第三列是connected,意味着该块网卡,正在使用某个配置文件
[root@rhel8 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens224 ethernet connected ens224
virbr0 bridge connected virbr0
ens256 ethernet connecting (getting IP configuration) dhcp
lo loopback unmanaged --
virbr0-nic tun unmanaged
如果第三列是connecting状态,就意味着该网卡正在获取ip地址。
第四列表示当前网卡使用的配置文件是什么,如果有名字,就表示该网卡的配置文件就是那个名字。如
果是"--"就表示该网卡当前没有配置文件。
DEVICE(设备) 物理网卡
CONNECTION(连接)网卡配置文件
nmcli命令是可以补全的,但是要安装bash-completion-2.7-5.el8.noarch软件。
[root@rhel8 ~]# nmcli [tab] [tab]
agent device help networking
connection general monitor radio
[root@rhel8 ~]# nmcli device [tab] [tab]
connect disconnect lldp monitor set status
delete help modify reapply show wifi
[root@rhel8 ~]# nmcli device status
看网卡和网卡配置文件的概述信息
[root@rhel8 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens224 ethernet connected ens224
virbr0 bridge connected virbr0
ens256 ethernet disconnected --
lo loopback unmanaged --
virbr0-nic tun unmanaged --

[root@rhel8 ~]# nmcli device delete ens256
Error: Device 'ens256' (/org/freedesktop/NetworkManager/Devices/7)
deletion failed: This device is not a software device or is not realized
Error: not all devices deleted.
nmcli device delete命令可以删除虚拟网卡,但是不能删除物理网卡

[root@rhel8 ~]# nmcli device delete virbr0
Device 'virbr0' successfully removed.
[root@rhel8 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens224 ethernet connected ens224
ens256 ethernet connecting (getting IP configuration) dhcp
lo loopback unmanaged --
virbr0-nic tun unmanaged

[root@rhel8 ~]# nmcli device stat
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens224 ethernet connected ens224
ens256 ethernet connecting (getting IP configuration) dhcp
lo loopback unmanaged --
virbr0-nic tun unmanaged --
[root@rhel8 ~]# nmcli device disconnect ens256
Device 'ens256' successfully disconnected.
[root@rhel8 ~]# nmcli device stat
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens224 ethernet connected ens224
ens256 ethernet disconnected --
lo loopback unmanaged --
virbr0-nic tun unmanaged --
disconnect指定一个网卡将会切断该网卡和当前配置文件的联系。

[root@rhel8 ~]# nmcli device disconnect ens224
Device 'ens224' successfully disconnected.
[root@rhel8 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens256 ethernet connecting (getting IP configuration) dhcp
ens224 ethernet disconnected --
lo loopback unmanaged --
virbr0-nic tun unmanaged --

[root@rhel8 ~]# nmcli device connect ens224
Device 'ens224' successfully activated with '60597c1e-7377-496d-9435-
3c0cb9a1003c'.
[root@rhel8 ~]#
[root@rhel8 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens224 ethernet connected ens224
ens256 ethernet connecting (getting IP configuration) dhcp
lo loopback unmanaged --
virbr0-nic tun unmanaged --
connect表示连接一个网卡的配置文件。

[root@rhel8 ~]# nmcli device show
ens160 ens224 ens256 help lo virbr0-nic

[root@rhel8 ~]# nmcli device show ens160
GENERAL.DEVICE: ens160
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:8F:F0:33
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: ens160
GENERAL.CON-PATH:
/org/freedesktop/NetworkManager/ActiveConnectio>
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.100.123/24
IP4.GATEWAY: --
IP4.ROUTE[1]: dst = 192.168.100.0/24, nh =
0.0.0.0, mt = 102
IP6.ADDRESS[1]: fe80::360e:5904:9c11:aed9/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 102
IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256,
table=255



[root@rhel8 ~]# nmcli device show ens256
GENERAL.DEVICE: ens256
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:8F:F0:47
GENERAL.MTU: 1500
GENERAL.STATE: 30 (disconnected)
GENERAL.CONNECTION: --
GENERAL.CON-PATH: --
nmcli管理网卡配置文件
WIRED-PROPERTIES.CARRIER: on

nmcli管理网卡配置文件

常用的设置网卡配置文件的参数
ip地址
ip掩码
ip gateway
ip dns
ip method(手工配置地址还是dhcp自动获取地址)
ip autoconnect(开机是否自动连接配置文件)

注意:操作网卡配置文件非常危险
私有云云服务器上的网卡一般是4~8块,2块用作管理网络,2块用作traffic网络,2块用作存储网卡
(如果使用本地存储,就不需要存储网卡),2块额外的网卡做高速虚拟化网卡转发(SR-IOV)
服务器上最少两块onboard(板载)的网卡,至少千兆,通过PCI总线接的外部网卡,至少万兆(光模
块)
一般来说,管理网卡(控制网络的网卡)配置文件是装系统的时候就配好了,我们操作网卡配置文件,
一般都是操作数据网络的网卡和存储网络的网卡。如果你是远程连接,误操作将管理网络配置文件配置
错误,导致无法远程连接,最坏的情况就是要去机房将其修复。

[root@rhel8 ~]# nmcli
agent device help networking
connection general monitor radio
[root@rhel8 ~]# nmcli connection
add delete edit help load monitor show
clone down export import modify reload up
操作网卡配置文件
[root@rhel8 ~]# nmcli connection add
添加一个网卡配置文件
[root@rhel8 ~]# nmcli connection delete
删除一个网卡配置文件
[root@rhel8 ~]# nmcli connection up
激活一个网卡配置文件
[root@rhel8 ~]# nmcli connection down
关闭一个网卡配置文件
[root@rhel8 ~]# nmcli connection show
查看一个网卡配置文件
[root@rhel8 ~]# nmcli connection reload
重新加载网卡配置文件


我们通过nmcli connection操作的网卡配置文件,默认目录都在
[root@rhel8 ~]# ls /etc/sysconfig/network-scripts/
ifcfg-dhcp ifcfg-ens160 ifcfg-ens224
都是以ifcfg-开头的,后面的就是网卡配置文件的名字
if是interface的缩写,cfg是configuration的缩写

[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
dhcp 2a8e9752-85a1-43e9-9351-33c60c51360b ethernet --
第一列NAME表示网卡配置文件的名称,该名称可以重复,但是不建议重复
第二列表示网卡配置文件的UUID,UUID一定不会重复,当名字重复的时候,UUID不会重复
第三列TYPE表示该网卡配置文件的类型,一般都是ethernet
第四列表示配置文件服务于哪个网卡(DEVICE)
配置网卡配置文件的守则
我是谁,我在哪,我要干什么
只有root才能操作网卡配置文件,因为网卡配置文件要最终关联到网卡。

千万不要操作管理网卡
[root@rhel8 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens224 ethernet connected ens224
ens256 ethernet disconnected --
lo loopback unmanaged --
virbr0-nic tun unmanaged --
我要操作ens256这块网卡,我后面只会看ens256这块网卡的ip地址等信息。

添加网卡配置文件

[root@rhel8 ~]# nmcli con add
autoconnect ipv4.ignore-auto-dns
con-name ipv4.ignore-auto-routes
connection.auth-retries ipv4.may-fail
connection.autoconnect ipv4.method
connection.autoconnect-priority ipv4.never-default
connection.autoconnect-retries ipv4.route-metric
connection.autoconnect-slaves ipv4.routes
connection.gateway-ping-timeout ipv4.route-table
connection.id ipv6.addresses
connection.interface-name ipv6.addr-gen-mode
connection.lldp ipv6.dhcp-duid
connection.llmnr ipv6.dhcp-hostname
connection.master ipv6.dhcp-send-hostname
connection.mdns ipv6.dns
connection.metered ipv6.dns-options
connection.multi-connect ipv6.dns-priority
connection.permissions ipv6.dns-search
connection.read-only ipv6.gateway
connection.secondaries ipv6.ignore-auto-dns
connection.slave-type ipv6.ignore-auto-routes
connection.stable-id ipv6.ip6-privacy
connection.timestamp ipv6.may-fail
connection.type ipv6.method
connection.uuid ipv6.never-default
connection.zone ipv6.route-metric
help ipv6.routes
ifname ipv6.route-table
ipv4.addresses ipv6.token
ipv4.dad-timeout master
ipv4.dhcp-client-id match.interface-name
ipv4.dhcp-fqdn proxy.browser-only
ipv4.dhcp-hostname proxy.method
ipv4.dhcp-send-hostname proxy.pac-script
ipv4.dhcp-timeout proxy.pac-url
ipv4.dns slave-type
ipv4.dns-options tc.qdiscs
ipv4.dns-priority tc.tfilters
ipv4.dns-search type
ipv4.gateway

必须要加的参数有三个
[root@rhel8 ~]# nmcli con add con-name 配置文件的名称 type 配置文件的类型
ifname 配置文件的网卡


[root@rhel8 ~]# nmcli con add con-name gousheng type ethernet ifname
ens256
Connection 'gousheng' (2be0ce2e-8824-4b4d-9974-1eb4fafd7328) successfully
added.
[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
gousheng 2be0ce2e-8824-4b4d-9974-1eb4fafd7328 ethernet ens256
dhcp 2a8e9752-85a1-43e9-9351-33c60c51360b ethernet --


如果一个网卡没有配置文件,那么添加之后就会直接将这个配置文件应用于这块网卡
如果在添加网卡配置文件的时候,只添加了默认的3个参数,该网卡的地址获取方式就是dhcp

[root@rhel8 ~]# nmcli con add con-name ens256-1 ifname ens256 type
ethernet ipv4.addresses 1.1.1.1/24 ipv4.gateway 1.1.1.200 ipv4.dns
114.114.114.114
Connection 'ens256-1' (61d12953-7aa7-498a-9d44-cd6865be998d) successfully
added.
[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
dhcp 2a8e9752-85a1-43e9-9351-33c60c51360b ethernet ens256
ens256-1 61d12953-7aa7-498a-9d44-cd6865be998d ethernet --
gousheng 2be0ce2e-8824-4b4d-9974-1eb4fafd7328 ethernet --

[root@rhel8 ~]# nmcli con up ens256-1
[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
ens256-1 61d12953-7aa7-498a-9d44-cd6865be998d ethernet ens256
dhcp 2a8e9752-85a1-43e9-9351-33c60c51360b ethernet --
gousheng 2be0ce2e-8824-4b4d-9974-1eb4fafd7328 ethernet --
[root@rhel8 ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
ens160 ethernet connected ens160
ens224 ethernet connected ens224
ens256 ethernet connecting (getting IP configuration) ens256-1
lo loopback unmanaged --
virbr0-nic tun unmanaged


如果想让一个网卡手工获取地址
[root@rhel8 ~]# nmcli con add con-name ens256-2 ifname ens256 type
ethernet ipv4.addresses 2.2.2.2/24 ipv4.gateway 2.2.2.200 ipv4.dns 8.8.8.8
ipv4.method manual
Connection 'ens256-2' (f25d1940-0167-446f-8af8-5e6263fe1f1c) successfully
added.
[root@rhel8 ~]# nmcli con up ens256-2
Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/50)
[root@rhel8 ~]#
[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
ens256-2 f25d1940-0167-446f-8af8-5e6263fe1f1c ethernet ens256
dhcp 2a8e9752-85a1-43e9-9351-33c60c51360b ethernet --
ens256-1 61d12953-7aa7-498a-9d44-cd6865be998d ethernet --
gousheng 2be0ce2e-8824-4b4d-9974-1eb4fafd7328 ethernet --

[root@rhel8 ~]# ip a show ens256
7: ens256:  mtu 1500 qdisc mq state UP
group default qlen 1000
link/ether 00:0c:29:8f:f0:47 brd ff:ff:ff:ff:ff:ff
inet 2.2.2.2/24 brd 2.2.2.255 scope global noprefixroute ens256
valid_lft forever preferred_lft forever
inet6 fe80::5be:d944:d1c0:5360/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@rhel8 ~]# ip a show ens256-2
Device "ens256-2" does not exist.
[root@rhel8 ~]# nmcli con add con-name ens256-3 ifname ens256 type
ethernet ipv4.addresses 3.3.3.3/24 ipv4.method manual
Connection 'ens256-3' (d09ae6ce-c951-4629-86ed-bebf5e3e3a08) successfully
added.
[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
ens256-2 f25d1940-0167-446f-8af8-5e6263fe1f1c ethernet ens256
dhcp 2a8e9752-85a1-43e9-9351-33c60c51360b ethernet --
ens256-1 61d12953-7aa7-498a-9d44-cd6865be998d ethernet --
ens256-3 d09ae6ce-c951-4629-86ed-bebf5e3e3a08 ethernet --
gousheng 2be0ce2e-8824-4b4d-9974-1eb4fafd7328 ethernet --

[root@rhel8 ~]# nmcli con up ens256-3
Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/51)

删除网卡配置文件
[root@rhel8 ~]# ip a show ens256
7: ens256:  mtu 1500 qdisc mq state UP
group default qlen 1000
link/ether 00:0c:29:8f:f0:47 brd ff:ff:ff:ff:ff:ff
inet 3.3.3.3/24 brd 3.3.3.255 scope global noprefixroute ens256
valid_lft forever preferred_lft forever
inet6 fe80::e933:3637:cf37:7222/64 scope link noprefixroute
valid_lft forever preferred_lft forever

删除网卡配置文件

[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
ens256-3 d09ae6ce-c951-4629-86ed-bebf5e3e3a08 ethernet ens256
dhcp 2a8e9752-85a1-43e9-9351-33c60c51360b ethernet --
ens256-1 61d12953-7aa7-498a-9d44-cd6865be998d ethernet --
ens256-2 f25d1940-0167-446f-8af8-5e6263fe1f1c ethernet --
gousheng 2be0ce2e-8824-4b4d-9974-1eb4fafd7328 ethernet --
[root@rhel8 ~]# nmcli con delete dhcp
Connection 'dhcp' (2a8e9752-85a1-43e9-9351-33c60c51360b) successfully
deleted.
[root@rhel8 ~]# nmcli con delete ens256-1
Connection 'ens256-1' (61d12953-7aa7-498a-9d44-cd6865be998d) successfully
deleted.
[root@rhel8 ~]# nmcli con delete uuid f25d1940-0167-446f-8af8-5e6263fe1f1c
Connection 'ens256-2' (f25d1940-0167-446f-8af8-5e6263fe1f1c) successfully
deleted.
[root@rhel8 ~]# nmcli con delete gousheng
Connection 'gousheng' (2be0ce2e-8824-4b4d-9974-1eb4fafd7328) successfully
deleted.
[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
ens256-3 d09ae6ce-c951-4629-86ed-bebf5e3e3a08 ethernet ens256


[root@rhel8 ~]# nmcli con help
Usage: nmcli connection { COMMAND | help }
COMMAND := { show | up | down | add | modify | clone | edit | delete |
monitor | reload | load | import | export }
show [--active] [--order ]
show [--active] [id | uuid | path | apath]  ...
up [[id | uuid | path] ] [ifname ] [ap ] [passwd-file
]
down [id | uuid | path | apath]  ...


add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS SLAVE_OPTIONS IP_OPTIONS [--
([+|-]. )+]
modify [--temporary] [id | uuid | path]  ([+|-].
)+
clone [--temporary] [id | uuid | path ]  
edit [id | uuid | path] 
edit [type ] [con-name ]
delete [id | uuid | path] 
monitor [id | uuid | path]  ...
reload
load  [ ... ]
import [--temporary] type  file 
export [id | uuid | path]  []


[root@rhel8 ~]# for i in {1..10}
> do
> nmcli con add con-name ergou$i ifname ens256 type ethernet
> done
Connection 'ergou1' (fdfd98eb-4fac-403f-8ddd-5fa772da17bb) successfully
added.
Connection 'ergou2' (e690b04c-fc15-4125-82aa-56885ebac5bc) successfully
added.
Connection 'ergou3' (320464e3-41c8-4cc1-8634-4d38cd10e633) successfully
added.
Connection 'ergou4' (93b232c1-9dd0-4743-b948-5a4cdace8276) successfully
added.
Connection 'ergou5' (9c5e1625-5cc8-40fc-9fd3-cc7731d10555) successfully
added.
Connection 'ergou6' (c93801ab-7570-4844-8c10-53a73f5ccaba) successfully
added.
Connection 'ergou7' (b6c7dd44-8968-442e-83c9-c72e4607d203) successfully
added.
Connection 'ergou8' (1adb93a3-0b3a-426e-9092-d6b16a89c3bd) successfully
added.
Connection 'ergou9' (b6ef6585-119f-43c9-913a-d6000bf93a8b) successfully
added.
Connection 'ergou10' (80b3ad9e-160a-45b7-8d3d-796b053795ed) successfully
added.
[root@rhel8 ~]#
[root@rhel8 ~]# ls /etc/sysconfig/network-scripts/
[root@rhel8 ~]# ls /etc/sysconfig/network-scripts/
ifcfg-ens160 ifcfg-ergou1 ifcfg-ergou3 ifcfg-ergou6 ifcfg-ergou9
ifcfg-ens224 ifcfg-ergou10 ifcfg-ergou4 ifcfg-ergou7
ifcfg-ens256-3 ifcfg-ergou2 ifcfg-ergou5 ifcfg-ergou8


如果手工修改了配置文件,需要重新将修改的配置文件加载到内存中,再激活,才可以生效
[root@rhel8 network-scripts]# nmcli connection reload
[root@rhel8 network-scripts]# nmcli con up ens256-3
Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/53)
[root@rhel8 network-scripts]# ip a show ens256
7: ens256:  mtu 1500 qdisc mq state UP
group default qlen 1000
link/ether 00:0c:29:8f:f0:47 brd ff:ff:ff:ff:ff:ff
inet 3.3.3.33/24 brd 3.3.3.255 scope global noprefixroute ens256
valid_lft forever preferred_lft forever
inet6 fe80::e933:3637:cf37:7222/64 scope link noprefixroute
valid_lft forever preferred_lft forever

修改网卡配置文件

[root@rhel8 ~]# nmcli con modify 配置文件名称
modify 后面跟的参数和 add 后面的跟的参数有 90% 的相似度
[root@rhel8 ~]# nmcli connection modify ens256-3
Display all 229 possibilities? (y or n)
802-1x.altsubject-matches
802-1x.anonymous-identity
802-1x.auth-timeout
802-1x.ca-cert
802-1x.ca-cert-password
802-1x.ca-cert-password-flags
802-1x.ca-path
802-1x.client-cert
802-1x.client-cert-password
802-1x.client-cert-password-flags
802-1x.domain-suffix-match
802-1x.eap
802-1x.identity
802-1x.pac-file
802-1x.password
802-1x.password-flags
802-1x.password-raw
802-1x.password-raw-flags
802-1x.phase1-auth-flags
802-1x.phase1-fast-provisioning
802-1x.phase1-peaplabel
802-1x.phase1-peapver
802-1x.phase2-altsubject-matches
802-1x.phase2-auth
802-1x.phase2-autheap
802-1x.phase2-ca-cert
802-1x.phase2-ca-cert-password
802-1x.phase2-ca-cert-password-flags
802-1x.phase2-ca-path
802-1x.phase2-client-cert
802-1x.phase2-client-cert-password
802-1x.phase2-client-cert-password-flags
802-1x.phase2-domain-suffix-match
802-1x.phase2-private-key
802-1x.phase2-private-key-password
802-1x.phase2-private-key-password-flags
802-1x.phase2-subject-match
802-1x.pin
802-1x.pin-flags
802-1x.private-key
802-1x.private-key-password
802-1x.private-key-password-flags
802-1x.subject-match
802-1x.system-ca-certs
802-3-ethernet.auto-negotiate
802-3-ethernet.cloned-mac-address
802-3-ethernet.duplex
802-3-ethernet.generate-mac-address-mask
802-3-ethernet.mac-address
802-3-ethernet.mac-address-blacklist
802-3-ethernet.mtu
802-3-ethernet.port
802-3-ethernet.s390-nettype
802-3-ethernet.s390-options
802-3-ethernet.s390-subchannels
802-3-ethernet.speed
802-3-ethernet.wake-on-lan
802-3-ethernet.wake-on-lan-password
autoconnect
browser-only
cloned-mac
con-name
connection.auth-retries
connection.autoconnect
connection.autoconnect-priority
connection.autoconnect-retries
connection.autoconnect-slaves
connection.gateway-ping-timeout
connection.id
connection.interface-name
connection.lldp
connection.llmnr
connection.master
connection.mdns
connection.metered
connection.multi-connect
connection.permissions
connection.read-only
connection.secondaries
connection.slave-type
connection.stable-id
connection.timestamp
connection.type
connection.uuid
connection.zone
dcb.app-fcoe-flags
dcb.app-fcoe-mode
dcb.app-fcoe-priority
dcb.app-fip-flags
dcb.app-fip-priority
dcb.app-iscsi-flags
dcb.app-iscsi-priority
dcb.priority-bandwidth
dcb.priority-flow-control
dcb.priority-flow-control-flags
dcb.priority-group-bandwidth
dcb.priority-group-flags
dcb.priority-group-id
dcb.priority-strict-bandwidth
dcb.priority-traffic-class
ethernet.auto-negotiate
ethernet.cloned-mac-address
ethernet.duplex
ethernet.generate-mac-address-mask
ethernet.mac-address
ethernet.mac-address-blacklist
ethernet.mtu
ethernet.port
ethernet.s390-nettype
ethernet.s390-options
ethernet.s390-subchannels
ethernet.speed
ethernet.wake-on-lan
ethernet.wake-on-lan-password
ethtool.feature-esp-hw-offload
ethtool.feature-esp-tx-csum-hw-offload
ethtool.feature-fcoe-mtu
ethtool.feature-gro
ethtool.feature-gso
ethtool.feature-highdma
ethtool.feature-hw-tc-offload
ethtool.feature-l2-fwd-offload
ethtool.feature-loopback
ethtool.feature-lro
ethtool.feature-ntuple
ethtool.feature-rx
ethtool.feature-rx-all
ethtool.feature-rx-fcs
ethtool.feature-rx-gro-hw
ethtool.feature-rxhash
ethtool.feature-rx-udp_tunnel-port-offload
ethtool.feature-rxvlan
ethtool.feature-rx-vlan-filter
ethtool.feature-rx-vlan-stag-filter
ethtool.feature-rx-vlan-stag-hw-parse
ethtool.feature-sg
ethtool.feature-tls-hw-record
ethtool.feature-tls-hw-tx-offload
ethtool.feature-tso
ethtool.feature-tx
ethtool.feature-tx-checksum-fcoe-crc
ethtool.feature-tx-checksum-ip-generic
ethtool.feature-tx-checksum-ipv4
ethtool.feature-tx-checksum-ipv6
ethtool.feature-tx-checksum-sctp
ethtool.feature-tx-esp-segmentation
ethtool.feature-tx-fcoe-segmentation
ethtool.feature-tx-gre-csum-segmentation
ethtool.feature-tx-gre-segmentation
ethtool.feature-tx-gso-partial
ethtool.feature-tx-gso-robust
ethtool.feature-tx-ipxip4-segmentation
ethtool.feature-tx-ipxip6-segmentation
ethtool.feature-tx-nocache-copy
ethtool.feature-tx-scatter-gather
ethtool.feature-tx-scatter-gather-fraglist
ethtool.feature-tx-sctp-segmentation
ethtool.feature-tx-tcp6-segmentation
ethtool.feature-tx-tcp-ecn-segmentation
ethtool.feature-tx-tcp-mangleid-segmentation
ethtool.feature-tx-tcp-segmentation
ethtool.feature-tx-udp-segmentation
ethtool.feature-tx-udp_tnl-csum-segmentation
ethtool.feature-tx-udp_tnl-segmentation
ethtool.feature-txvlan
ethtool.feature-tx-vlan-stag-hw-insert
gw4
gw6
ifname
ip4
ip6
ipv4.addresses
ipv4.dad-timeout
ipv4.dhcp-client-id
ipv4.dhcp-fqdn
ipv4.dhcp-hostname
ipv4.dhcp-send-hostname
ipv4.dhcp-timeout
ipv4.dns
ipv4.dns-options
ipv4.dns-priority
ipv4.dns-search
ipv4.gateway
ipv4.ignore-auto-dns
ipv4.ignore-auto-routes
ipv4.may-fail
ipv4.method
ipv4.never-default
ipv4.route-metric
ipv4.routes
ipv4.route-table
ipv6.addresses
ipv6.addr-gen-mode
ipv6.dhcp-duid
ipv6.dhcp-hostname
ipv6.dhcp-send-hostname
ipv6.dns
ipv6.dns-options
ipv6.dns-priority
ipv6.dns-search
ipv6.gateway
ipv6.ignore-auto-dns
ipv6.ignore-auto-routes
ipv6.ip6-privacy
ipv6.may-fail

ipv6.method
ipv6.never-default
ipv6.route-metric
ipv6.routes
ipv6.route-table
ipv6.token
mac
master
match.interface-name
method
mtu
pac-script
pac-url
proxy.browser-only
proxy.method
proxy.pac-script
proxy.pac-url
slave-type
sriov.autoprobe-drivers
sriov.total-vfs
sriov.vfs
tc.qdiscs
tc.tfilters
type
[root@rhel8 ~]# nmcli connection modify ens256-3 ipv4.addresses
3.3.3.23/24
[root@rhel8 ~]# nmcli con up ens256-3
Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/54)
[root@rhel8 ~]# ip a show ens256
7: ens256:  mtu 1500 qdisc mq state UP
group default qlen 1000
link/ether 00:0c:29:8f:f0:47 brd ff:ff:ff:ff:ff:ff
inet 3.3.3.23/24 brd 3.3.3.255 scope global noprefixroute ens256
valid_lft forever preferred_lft forever
inet6 fe80::e933:3637:cf37:7222/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@rhel8 ~]# nmcli connection modify ens256-3 connection.autoconnect
yes
connection.autoconnect表示该网卡配置文件是否下次开机的时候会被自动加载,如果是yes就会
自动加载,如果是no就不会自动加载。
[root@rhel8 ~]# nmcli connection modify ens256-3 connection.autoconnect
yes
[root@rhel8 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens256-3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=3.3.3.23
PREFIX=24
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=ens256-3
UUID=d09ae6ce-c951-4629-86ed-bebf5e3e3a08
DEVICE=ens256
ONBOOT=yes
[root@rhel8 ~]# nmcli connection modify ens256-3 connection.autoconnect
no
[root@rhel8 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens256-3
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=3.3.3.23
PREFIX=24
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=ens256-3
UUID=d09ae6ce-c951-4629-86ed-bebf5e3e3a08
DEVICE=ens256
ONBOOT=no

查看网卡配置文件详细信息

[root@rhel8 ~]# nmcli con show ens256-3
connection.id: ens256-3
connection.uuid: d09ae6ce-c951-4629-86edbebf5e3e3a08
connection.stable-id: --
connection.type: 802-3-ethernet
connection.interface-name: ens256
connection.autoconnect: no
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.multi-connect: 0 (default)
connection.auth-retries: -1
connection.timestamp: 1587827854
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)

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: manual
ipv4.dns: --
ipv4.dns-search: --
ipv4.dns-options: ""
ipv4.dns-priority: 0
ipv4.addresses: 3.3.3.23/24
ipv4.gateway: --
ipv4.routes: --
ipv4.route-metric: -1
ipv4.route-table: 0 (unspec)
ipv4.ignore-auto-routes: no
ipv4.ignore-auto-dns: no
ipv4.dhcp-client-id: --
ipv4.dhcp-timeout: 0 (default)
ipv4.dhcp-send-hostname: yes
ipv4.dhcp-hostname: --
ipv4.dhcp-fqdn: --
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.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.dhcp-duid: --
ipv6.dhcp-send-hostname: yes
ipv6.dhcp-hostname: --
ipv6.token: --
proxy.method: none
proxy.browser-only: no
proxy.pac-url: --
proxy.pac-script: --

GENERAL.NAME: ens256-3
GENERAL.UUID: d09ae6ce-c951-4629-86edbebf5e3e3a08
GENERAL.DEVICES: ens256
GENERAL.STATE: activated
GENERAL.DEFAULT: no
GENERAL.DEFAULT6: no
GENERAL.SPEC-OBJECT: --
GENERAL.VPN: no
GENERAL.DBUS-PATH:
/org/freedesktop/NetworkManager/ActiveConnection/54
GENERAL.CON-PATH:
/org/freedesktop/NetworkManager/Settings/11
GENERAL.ZONE: --
GENERAL.MASTER-PATH: --
IP4.ADDRESS[1]: 3.3.3.23/24
IP4.GATEWAY: --
IP4.ROUTE[1]: dst = 3.3.3.0/24, nh = 0.0.0.0, mt
= 106
IP6.ADDRESS[1]: fe80::e933:3637:cf37:7222/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 106
IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256,
table=255

[root@rhel8 ~]# nmcli connection modify ens256-3 connection.id ens256
[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
ens256 d09ae6ce-c951-4629-86ed-bebf5e3e3a08 ethernet ens256
ergou1 fdfd98eb-4fac-403f-8ddd-5fa772da17bb ethernet --
ergou10 80b3ad9e-160a-45b7-8d3d-796b053795ed ethernet --
ergou2 e690b04c-fc15-4125-82aa-56885ebac5bc ethernet --
ergou3 320464e3-41c8-4cc1-8634-4d38cd10e633 ethernet --
ergou4 93b232c1-9dd0-4743-b948-5a4cdace8276 ethernet --
ergou5 9c5e1625-5cc8-40fc-9fd3-cc7731d10555 ethernet --
ergou6 c93801ab-7570-4844-8c10-53a73f5ccaba ethernet --
ergou7 b6c7dd44-8968-442e-83c9-c72e4607d203 ethernet --
ergou8 1adb93a3-0b3a-426e-9092-d6b16a89c3bd ethernet --
ergou9 b6ef6585-119f-43c9-913a-d6000bf93a8b ethernet --
[root@rhel8 ~]# nmcli connection modify ens256 connection.interface-name
ens224
[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet ens224
ens256 d09ae6ce-c951-4629-86ed-bebf5e3e3a08 ethernet ens256
ergou1 fdfd98eb-4fac-403f-8ddd-5fa772da17bb ethernet --
ergou10 80b3ad9e-160a-45b7-8d3d-796b053795ed ethernet --
ergou2 e690b04c-fc15-4125-82aa-56885ebac5bc ethernet --
ergou3 320464e3-41c8-4cc1-8634-4d38cd10e633 ethernet --
ergou4 93b232c1-9dd0-4743-b948-5a4cdace8276 ethernet --
ergou5 9c5e1625-5cc8-40fc-9fd3-cc7731d10555 ethernet --
ergou6 c93801ab-7570-4844-8c10-53a73f5ccaba ethernet --

Vmware workstation的虚拟网络和虚拟网络结构
vmware workstation给我们提供了3种类型的虚拟交换机用于我们虚拟机的虚拟网络连接
这三种,分别是:
仅主机类型的虚拟交换机
nat类型的虚拟交换机
桥接类型的虚拟交换机
仅主机类型的虚拟交换机
ergou7 b6c7dd44-8968-442e-83c9-c72e4607d203 ethernet --
ergou8 1adb93a3-0b3a-426e-9092-d6b16a89c3bd ethernet --
ergou9 b6ef6585-119f-43c9-913a-d6000bf93a8b ethernet --
[root@rhel8 ~]# nmcli con up ens256
Connection successfully activated (D-Bus active path:
/org/freedesktop/NetworkManager/ActiveConnection/55)
[root@rhel8 ~]# nmcli con show
NAME UUID TYPE DEVICE
ens160 b7b2ae18-6790-4f0d-a299-29a06b1a46c3 ethernet ens160
ens256 d09ae6ce-c951-4629-86ed-bebf5e3e3a08 ethernet ens224
ergou8 1adb93a3-0b3a-426e-9092-d6b16a89c3bd ethernet ens256
ens224 60597c1e-7377-496d-9435-3c0cb9a1003c ethernet --
ergou1 fdfd98eb-4fac-403f-8ddd-5fa772da17bb ethernet --
ergou10 80b3ad9e-160a-45b7-8d3d-796b053795ed ethernet --
ergou2 e690b04c-fc15-4125-82aa-56885ebac5bc ethernet --
ergou3 320464e3-41c8-4cc1-8634-4d38cd10e633 ethernet --
ergou4 93b232c1-9dd0-4743-b948-5a4cdace8276 ethernet --
ergou5 9c5e1625-5cc8-40fc-9fd3-cc7731d10555 ethernet --
ergou6 c93801ab-7570-4844-8c10-53a73f5ccaba ethernet --
ergou7 b6c7dd44-8968-442e-83c9-c72e4607d203 ethernet --
ergou9 b6ef6585-119f-43c9-913a-d6000bf93a8b ethernet --
[root@rhel8 ~]# ip a show ens256
7: ens256:  mtu 1500 qdisc mq state UP
group default qlen 1000
link/ether 00:0c:29:8f:f0:47 brd ff:ff:ff:ff:ff:ff
inet6 fe80::c391:cf5b:31ba:d5fd/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@rhel8 ~]# ip a show ens224
6: ens224:  mtu 1500 qdisc mq state UP
group default qlen 1000
link/ether 00:0c:29:8f:f0:3d brd ff:ff:ff:ff:ff:ff
inet 3.3.3.23/24 brd 3.3.3.255 scope global noprefixroute ens224
valid_lft forever preferred_lft forever
inet6 fe80::9012:b2dc:6351:3949/64 scope link noprefixroute
valid_lft forever preferred_lft forever

你可能感兴趣的:(RHCE,linux,运维,服务器)