In continuation of NetworkManager management with nmcli, here is a quick Linux console tip for users like CentOS 8 (or all distributions, which use the NetworkManager for managing the networking). How to create a virtualized bridge device MacVTap device with the NetworkManager nmcli command utility, which will preserve all the configuration over reboots.
nmcli connection add type macvlan dev enp0s3 mode bridge tap yes ifname macvtap0 con-name macvtap0 ip4 0.0.0.0/24
The line above creates a virtualized bridged interface and a connection with the name macvtap0. The MAcVTap device with the name macvtap0 is in bridge mode with the physical network interface enp0s3 with manual IP setting. If the IP is not included a DHCP option will be used as default.
There is one big limitation – there is no link between the enp0s3 and macvtap0. When used macvtap0 could receive packets from the network through the enp0s3, but there is no direct link between the two network devices. In simple words, when used in a virtualized environment in a virtual machine the virtual machine may have access to the network shared with the enp0s3, but the virtual machine cannot communicate with the IPs of the enp0s3!
Typically, this is used to make both the guest and the host show up directly on the switch that the host is connected to.
Initial state, only one connection in NetworkManager.
The main server connection with name enp0s3 using the same name network interface enp0s3:
[root@srv ~]# nmcli con NAME UUID TYPE DEVICE enp0s3 09497bbf-da59-42b7-a72c-d69369760b36 ethernet enp0s3 [root@srv ~]# nmcli enp0s3: connected to enp0s3 "Intel 82540EM" ethernet (e1000), 08:00:27:03:C9:2E, hw, mtu 1500 ip4 default inet4 192.168.0.20/24 route4 192.168.0.0/24 metric 100 route4 0.0.0.0/0 via 192.168.0.1 metric 100 inet6 fe80::a00:27ff:fe03:c92e/64 route6 fe80::/64 metric 100 lo: unmanaged "lo" loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536 DNS configuration: servers: 18.104.22.168 22.214.171.124 interface: enp0s3 Use "nmcli device show" to get complete information about known devices and "nmcli connection show" to get an overview on active connection profiles. Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.
Add the MacVTap device with the name macvlan0
[root@srv ~]# nmcli connection add type macvlan dev enp0s3 mode bridge tap yes ifname macvtap0 con-name macvtap0 ip4 0.0.0.0/24 Connection 'macvtap0' (7a5ef04c-ea98-4642-ac5d-4239f715f631) successfully added.
A MacVTap device, a network connection, and a link are established. The name of the MacVTap device and the network connection is macvtap0.