Centos8 nmcli 创建网桥
在centos8 上取消了常用的网桥管工具来brctl,基本网络相关的配置信息全部可以通过nmcli 来实现,下面介绍在centos8 上对网桥的相关使用;
1、基本介绍:
[root@localhost ~]# nmcli --help
Usage: nmcli [OPTIONS] OBJECT { COMMAND | help }
OPTIONS
-a, --ask ask for missing parameters
-c, --colors auto|yes|no whether to use colors in output
-e, --escape yes|no escape columns separators in values
-f, --fields <field,...>|all|common specify fields to output
-g, --get-values <field,...>|all|common shortcut for -m tabular -t -f
-h, --help print this help
-m, --mode tabular|multiline output mode
-o, --overview overview mode
-p, --pretty pretty output
-s, --show-secrets allow displaying passwords
-t, --terse terse output
-v, --version show program version
-w, --wait <seconds> set timeout waiting for finishing operations
OBJECT
g[eneral] NetworkManager's general status and operations
n[etworking] overall networking control
r[adio] NetworkManager radio switches
c[onnection] NetworkManager's connections
d[evice] devices managed by NetworkManager
a[gent] NetworkManager secret agent or polkit agent
m[onitor] monitor NetworkManager changes
2、创建网桥
[root@localhost ~]# nmcli c add type bridge ifname br0 con-name br0
Connection 'br0' (7b309691-5b24-42ab-bb8c-5e1cc24eafbd) successfully added.
上面参数命令的解释:
type : 类型,常用的vxlan,vlan,bridge,bridge-slave等,用来定义设备的类型;
ifname:设备名字;
con-name : 连接名称;
创建完成后我们查看下网桥是否创建成功,
[root@localhost ~]# nmcli c
NAME UUID TYPE DEVICE
bridge-br0 f5f43513-ba3f-49dc-a6a6-ad96e3b4bfc4 bridge br0
eno4 d855cbac-278b-44c3-8ae6-05b6f9a44a1e ethernet eno4
eno1 9b2dabf2-c1d3-4479-bd7b-9dc56ff426a7 ethernet --
eno2 2cb32179-6b65-4876-be77-b43ff9fad039 ethernet --
eno3 dbd7996f-a932-4e9c-b5d2-6174653eaf23 ethernet --
ens47f0 c5f2fd97-78e7-48c0-ad72-3015d542dca0 ethernet --
ens47f1 8ef8d139-a398-43c8-ab3c-c28a179bba11 ethernet --添加接口
[root@localhost ~]# nmcli c add type bridge-slave ifname ens47f1 master br0
Connection 'bridge-slave-ae58-ebf3b38afbae) successfully added.
这里的参数基本与之前的一致,注意设置类型即可,ifname 是需要添加到桥的接口名;
当接口添加完成后我们可以查看下简单的连接信息,如:
[root@localhost ~]# nmcli c
NAME UUID TYPE DEVICE
eno4 d855cbac-278b-44c3-8ae6-05b6f9a44a1e ethernet eno4
br0 f5f43513-ba3f-49dc-a6a6-ad96e3b4bfc4 bridge br0
bridge-slave-ens47f1 7a2a9e70-7a49-4e8f-9f14-e5b4811cb5a5 ethernet ens47f1
vnet0 f97493c4-b6d1-4efc-a1fd-7562dddf3753 tun vnet0
eno1 9b2dabf2-c1d3-4479-bd7b-9dc56ff426a7 ethernet --
eno2 2cb32179-6b65-4876-be77-b43ff9fad039 ethernet --
eno3 dbd7996f-a932-4e9c-b5d2-6174653eaf23 ethernet --
ens47f0 c5f2fd97-78e7-48c0-ad72-3015d542dca0 ethernet --
ens47f1 8ef8d139-a398-43c8-ab3c-c28a179bba11 ethernet --
当看具体的信息的时候可以添加show 参数,如:
[root@localhost ~]# nmcli c show bridge-slave-ens47f1
connection.id: bridge-slave-ens47f1
connection.uuid: 7a2a9e70-7a49-4e8f-9f14-e5b4811cb5a5
connection.stable-id: --
connection.type: 802-3-ethernet
connection.interface-name: ens47f1
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.multi-connect: 0 (default)
connection.auth-retries: -1
connection.timestamp: 1589364882
connection.read-only: no
connection.permissions: --
connection.zone: --
connection.master: br0
connection.slave-type: bridge
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: --
bridge-port.priority: 32
bridge-port.path-cost: 100
bridge-port.hairpin-mode: no
bridge-port.vlans: --
GENERAL.NAME: bridge-slave-ens47f1
GENERAL.UUID: 7a2a9e70-7a49-4e8f-9f14-e5b4811cb5a5
GENERAL.DEVICES: ens47f1
GENERAL.STATE: activated
GENERAL.DEFAULT: no
GENERAL.DEFAULT6: no
GENERAL.SPEC-OBJECT: --
GENERAL.VPN: no
GENERAL.DBUS-PATH: /org/freedesktop/NetworkManager/ActiveConnection/123
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/Settings/28
GENERAL.ZONE: --
GENERAL.MASTER-PATH: /org/freedesktop/NetworkManager/Devices/20
IP4.GATEWAY: --
IP6.GATEWAY: --
3、启动网桥
[root@localhost ~]# nmcli c up br0
Connection successfully activated (master waiting for slaves) (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/89)
查看下启动后的情况:
[root@localhost ~]# nmcli c show
NAME UUID TYPE DEVICE
eno4 d855cbac-278b-44c3-8ae6-05b6f9a44a1e ethernet eno4
br0 f5f43513-ba3f-49dc-a6a6-ad96e3b4bfc4 bridge br0
bridge-slave-ens47f1 7a2a9e70-7a49-4e8f-9f14-e5b4811cb5a5 ethernet ens47f1
eno1 9b2dabf2-c1d3-4479-bd7b-9dc56ff426a7 ethernet --
eno2 2cb32179-6b65-4876-be77-b43ff9fad039 ethernet --
eno3 dbd7996f-a932-4e9c-b5d2-6174653eaf23 ethernet --
ens47f0 c5f2fd97-78e7-48c0-ad72-3015d542dca0 ethernet --
ens47f1 8ef8d139-a398-43c8-ab3c-c28a179bba11 ethernet --
4、相关参数修改:
1、修网桥的IP形式为手动;
[root@centos111 ~]# nmcli c modify br0 ipv4.method manual
如果不修改,那么桥会自动取IP,取不到状态将错误,导致网桥无法使用;
2、设置bridge 的IP信息;
[root@centos111 ~]# nmcli c modify br0 ipv4.addresses 192.168.1.111/24
3、设置网桥自动连接;
[root@centos111 ~]# nmcli c modify br0 autoconnect yes