This article shows how to create a network bridge device and a TUN/TAP device, which then is added to the bridge. The CentOS 8 Stream is used along with the console NetworkManager program nmcli.
TUN/TAP devices are often used in the virtualization world as a link device between the host machine and the virtual machine.
This article is for the case when the bridge does not include the main network interface (Internet network interface and so on) of the server but is an additional device, which MAC and virtual machine MACs would not be exposed through the server’s main network interface.
If the server’s main network interface should be included in the bridge device, i.e. replace the main network interface with the bridge there is another article on the subject – Replace current interface configuration with a bridge device using nmcli (NetworkManager)
Device name are as follow:
- br0 is the name of the network bridge.
- 10.10.10.1 with mask /24 is the IP of the bridge device with name br0. Because the idea is to use the bridge only locally, a local interface is used. The IP is set manually.
- tap0 is the name of TUN/TAP device.
- enp0s3is the server’s main network connection. Not used in this howto.
Here are all the commands to create a bridge, create a TUN/TAP device and add it to the bridge, and then activate the bridge‘s link.
nmcli connection add type bridge ifname br0 con-name br0 ipv4.method manual ipv4.addresses "10.10.10.1/24" nmcli con up br0 nmcli connection add type tun ifname tap0 con-name tap0 mode tap owner 0 ip4 0.0.0.0/24 nmcli con add type bridge-slave ifname tap0 master br0
Here are the steps with much more details and information including all the command output.
The networking before any reconfiguration:
[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: 8.8.8.8 1.1.1.1 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. [root@srv ~]# nmcli con NAME UUID TYPE DEVICE enp0s3 09497bbf-da59-42b7-a72c-d69369760b36 ethernet enp0s3