Linux Network Bridge (refs)
From WikiMLT
References
- Red Hat Blog: How to set up a network bridge for virtual machine communication (NetworkManager and nmtui)
- Red Hat Docs: Red Hat > [9] > Configuring and managing networking > Chapter 4. Using nmtui to manage network connections using a text-based interface
- Heiko's Blog: Define a network bridge using Ubuntu’s / Linux Mint's / Kali Linux's NetworkManager GUI application
- Netplain: Netplan configuration examples
- Fabian Lee: KVM: Creating a bridged network with Netplan on Ubuntu bionic
- LinuxTechi: How to Install KVM on Ubuntu 20.04 LTS Server (Netplan bridge)
- Ask Ubuntu: Netplan vs NetworkManager on Ubuntu 18.04 and above
- Arch Linux Wiki: Network bridge
Create Network Bridge by Netplain on Ubuntu Server
Use the the commands ip, ifconfig or networkctl to get the list of the available network adapters. Here we will create a bridge for eno2 which is the second network adapter of the physical server.
ifconfig -a
#Output
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:c6ff:fe17:93db prefixlen 64 scopeid 0x20<link>
ether 02:42:c6:17:93:db txqueuelen 0 (Ethernet)
RX packets 1625 bytes 108954 (108.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1888 bytes 5226160 (5.2 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.1.201 netmask 255.255.255.0 broadcast 172.16.1.255
inet6 fe80::72e2:84ff:fe13:8e6e prefixlen 64 scopeid 0x20<link>
ether 70:e2:84:13:8e:6e txqueuelen 1000 (Ethernet)
RX packets 16825485 bytes 23665075680 (23.6 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 3451343 bytes 333386187 (333.3 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xfb300000-fb37ffff
eno2: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 70:e2:84:13:8e:6f txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xfb200000-fb27ffff
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 131995267 bytes 12281222578 (12.2 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 131995267 bytes 12281222578 (12.2 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
veth26b9b17: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::78a9:8cff:fe0b:8cd prefixlen 64 scopeid 0x20<link>
ether 7a:a9:8c:0b:08:cd txqueuelen 0 (Ethernet)
RX packets 1625 bytes 131704 (131.7 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1915 bytes 5228146 (5.2 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ip address
#Output
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 70:e2:84:13:8e:6e brd ff:ff:ff:ff:ff:ff
inet 172.16.1.201/24 brd 172.16.1.255 scope global eno1
valid_lft forever preferred_lft forever
inet6 fe80::72e2:84ff:fe13:8e6e/64 scope link
valid_lft forever preferred_lft forever
4: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:c6:17:93:db brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
valid_lft forever preferred_lft forever
inet6 fe80::42:c6ff:fe17:93db/64 scope link
valid_lft forever preferred_lft forever
6: veth26b9b17@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default
link/ether 7a:a9:8c:0b:08:cd brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::78a9:8cff:fe0b:8cd/64 scope link
valid_lft forever preferred_lft forever
9: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 70:e2:84:13:8e:6f brd ff:ff:ff:ff:ff:ff
networkctl
#Output
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 eno1 ether routable configured
4 docker0 bridge routable unmanaged
6 veth26b9b17 ether degraded unmanaged
9 eno2 ether off unmanaged
5 links listed.
Now we are going to edit Netplains's configuration. Note the configuration file may have different name within your distribution.
sudo nano /etc/netplan/00-installer-config.yaml # cat /etc/netplan/00-installer-config.yaml
#Apply
# This is the network config written by 'subiquity'
network:
version: 2
ethernets:
eno1:
dhcp4: true
#addresses: [172.16.1.201/24]
#gateway4: 172.16.1.1
#nameservers:
# addresses: [172.16.1.1, 8.8.8.8, 8.8.4.4]
dhcp6: no
eno2:
dhcp4: no
dhcp6: no
bridges:
br0:
interfaces: [eno2]
addresses: [172.16.1.205/24]
gateway4: 172.16.1.1
nameservers:
addresses: [172.16.1.1, 8.8.8.8, 8.8.4.4]
Apply the new network configuration and check the result.
sudo netplan apply
networkctl
#Output
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
2 eno1 ether routable configured
4 docker0 bridge routable unmanaged
6 veth26b9b17 ether degraded unmanaged
9 eno2 ether carrier configured
10 br0 bridge routable configured
6 links listed.
networkctl status br0
#Output
● 10: br0
Link File: /usr/lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-br0.network
Type: bridge
State: routable (configured)
Driver: bridge
HW Address: 70:e2:84:13:8e:6f (Wistron Infocomm (Zhongshan) Corporation)
MTU: 1500 (min: 68, max: 65535)
Forward Delay: 15s
Hello Time: 2s
Max Age: 20s
Ageing Time: 5min
Priority: 32768
STP: no
Multicast IGMP Version: 2
Queue Length (Tx/Rx): 1/1
Address: 172.16.1.205
fe80::70be:baff:fed1:2d93
Gateway: 172.16.1.1 (TP-LINK TECHNOLOGIES CO.,LTD.)
DNS: 172.16.1.1
8.8.8.8
8.8.4.4
Activation Policy: up
ip a show br0 && ip a show eno2
#Output
10: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 70:e2:84:13:8e:6f brd ff:ff:ff:ff:ff:ff
inet 172.16.1.205/24 brd 172.16.1.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::70be:baff:fed1:2d93/64 scope link
valid_lft forever preferred_lft forever
9: eno2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether 70:e2:84:13:8e:6f brd ff:ff:ff:ff:ff:ff
ifconfig br0 && ifconfig eno2
#Output
br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.1.205 netmask 255.255.255.0 broadcast 172.16.1.255
inet6 fe80::70be:baff:fed1:2d93 prefixlen 64 scopeid 0x20<link>
ether 70:e2:84:13:8e:6f txqueuelen 1000 (Ethernet)
RX packets 7935 bytes 3090030 (3.0 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 11575 bytes 11225034 (11.2 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 70:e2:84:13:8e:6f txqueuelen 1000 (Ethernet)
RX packets 9115 bytes 3543374 (3.5 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 16426 bytes 11489692 (11.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xfb200000-fb27ffff