Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build Bridge in Linux system

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article shows you how to build a bridge in the Linux system, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

A bridge, also known as a bridge, is a storage / forwarding device that connects two Lans. A simple bridge has two ports, while a more complex bridge can have more ports.

Introduction to the bridge: works at the data link layer (L2). In Ethernet, the data link layer address is the mac address. The difference between the bridge and the hub is that the bridge filters the mac and only the data that matches the destination mac address is sent to the exit. A bridge refers to a bridge from an input to an output.

Specific steps for Linux system to build bridges: network bridging management commands brctl   # bridging management commands brctl show; brctl addbr br0 add bridges; show   # display addbr   # add bridges delbr   # delete bridges addif   # add network bridges delif   # delete network bridges

Network bridging in the form of files.

It can be operated in the real machine on the premise that the original ifcfg-enp0s25,ifcfg-br0 should be transferred to another place for later recovery.

[root@foundation12 ~] # cd / etc/sysconfig/network-scripts/ in this directory [root@foundation12 network-scripts] # ls ifcfg-br0 ifdown-ovs ifup-eth ifup-sit ifcfg-enp0s25 ifdown-post ifup-ib ifup-Team ifcfg-lo ifdown-ppp ifup-ippp ifup-TeamPort ifcfg- Xiaomi mobile phone ifdown-routes ifup-ipv6 ifup-tunnel ifdown ifdown-sit ifup -isdn ifup-wireless ifdown-bnep ifdown-Team ifup-ovs init.ipv6-global ifdown-eth ifdown-TeamPort ifup-plip keys- Xiaomi Mobile ifdown-ib ifdown-tunnel ifup-plusb network-functions ifdown-ippp ifup ifup-post network-functions-ipv6 ifdown-ipv6 ifup-aliases ifup-ppp ifdown-isdn ifup-bnep ifup-routes [root@foundation12 network-scripts] # mv ifcfg -br0 ifcfg-enp0s25 / opt move to another place 1234567891011121314 operate the new network bridge under / etc/sysconfig/networl-scipts directory

[root@foundation12 network-scripts] # vim ifcfg-br0 set the network card of the real host [root@foundation12 network-scripts] # ifconfig to view the real physical network card br0: flags=4163 mtu 1500 inet 172.25.12.250 netmask 255.255.255.0 broadcast 172.25.12.255 inet6 fe80::221:ccff:fe6f:78a8 prefixlen 64 scopeid 0x20 ether 00:21:cc:6f:78:a8 txqueuelen 1000 (Ethernet) RX packets 106032 bytes 133746644 (127.5 MiB) RX errors 0 dropped 1 overruns 0 frame 0 TX packets 45193 bytes 3062537 (2.9MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s25: flags=4163 mtu 1500 physical network card ether 00:21:cc:6f:78:a8 txqueuelen 1000 (Ethernet) RX packets 149532 bytes 138685095 (132.2 MiB) RX errors 0 Dropped 0 overruns 0 frame 0 TX packets 45246 bytes 3249632 (3.0 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 20 memory 0xf2600000-f2620000 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 1 (Local Loopback) RX packets 850589 bytes 296471850 (282.7 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 850589 bytes 296471850 (282.7 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 privbr0: flags=4099 mtu 1500 inet 172.250.250 netmask 255.255.255.0 broadcast 172.25.250.255 ether 52:54:00:18:3d:3a txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr0: flags=4099 mtu 1500 inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255 ether 52:54:00:b1:87:41 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 virbr1: flags=4099 mtu 1500 ether 52:54:00:d9:96:d6 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vnet0: flags=4163 mtu 1500 inet6 fe80::fc54 : ff:fe00:c0a prefixlen 64 scopeid 0x20 ether fe:54:00:00:0c:0a txqueuelen 1000 (Ethernet) RX packets 167 bytes 29997 (29.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 43833 bytes 3052031 (2.9 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vnet1: flags=4163 mtu 1500 inet6 fe80::fc54:ff:fe21:641b prefixlen 64 scopeid 0x20 ether fe : 54 MiB 0021 bytes 64 txqueuelen 1000 (Ethernet) RX packets 31 bytes 4118 RX errors 0 dropped 0 overruns 0 frame 0 TX packets 58438 bytes 4125919 (3.9 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 vnet2: flags=4163 mtu 1500 inet6 fe80::fc54:ff:fe67:d8a7 prefixlen 64 scopeid 0x20 ether fe:54:00:67:d8:a7 txqueuelen 1000 (Ethernet) RX packets 6 bytes 364 (364.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 43808 bytes 3046200 (2.9 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlp3s0: flags=4163 mtu 1500 inet 192.168.43.236 netmask 255.255.255.0 broadcast 192.168.43.255 inet6 fe80::2d9f:805d:d4b5:f0d1 prefixlen 64 scopeid 0x20 ether 08:11:96 : 9a:1f:a4 txqueuelen 1000 (Ethernet) RX packets 28627 bytes 26833776 (25.5 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 23792 bytes 8576662 (8.1 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@foundation12 network-scripts] # vim ifcfg-enp0s25 to write a physical network card. [root@foundation12 network-scripts] # systemctl restart network restart Network [root@foundation12 network-scripts] # brctl show View Network Information bridge name bridge id STP enabled interfaces br0 8000.0021cc6f78a8 no enp0s25 Bridge build privbr0 8000.525400183d3a yes privbr0-nic virbr0 8000.525400b18741 yes virbr0-nic virbr1 8000.525400d996d6 yes virbr1-nic [root@foundation12 network-scripts] # cat ifcfg-br0 DEVICE=br0 ONBOOT=yes BOOTPROTO=none IPADDR=172.25.254.12 PREFIX=24 TYPE=Bridge [root@foundation12 network-scripts] # cat ifcfg-enp0s25 DEVICE=enp0s25 ONBOOT=yes BOOTPROTO=none BRIDGE=br0 [root@foundation12 network-scripts] # rm-rf ifcfg-br0 [root@foundation12 network-scripts] # rm-rf ifcfg-enp0s25 delete [root@foundation12 network-scripts] # mv / opt/ifcfg-br0. [root@foundation12 network-scripts] # mv / opt/ifcfg-enp0s25. Move the original and back to [root@foundation12 network-scripts] # ls ifcfg-br0 ifdown-ovs ifup-eth ifup-sit ifcfg-enp0s25 ifdown-post ifup-ib ifup-Team 1234567891011121314151718192021222325262728293031333435363738394041424454648495051545557585960616265666769701727374757878808183848788899091929394969899100110210310510610710910111112

[root@localhost ~] # brctl show View Bridge Information bridge name bridge id STP enabled interfaces [root@localhost ~] # brctl addbr br0 add a new virtual interface [root@localhost ~] # brctl show View Bridge information already have br0 this virtual interface bridge name bridge id STP enabled interfaces br0 8000.000000000000 no [root@localhost ~] # ifconfig br0 172.25.254.112On24 assign to br0 virtual interface An IP address [root@localhost ~] # ifconfig view virtual interface information with IP address br0: flags=4163 mtu 1500 inet 172.254.112 netmask 255.255.255.0 broadcast 172.25.254.255 inet6 fe80::90b8:3ff:feae:295a prefixlen 64 scopeid 0x20 ether 92:b8:03:ae:29:5a txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 16 bytes 2835 (2.7KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth0: flags=4163 mtu 1500 ether 52:54:00:00:0c:0a txqueuelen 1000 (Ethernet) RX packets 23707 bytes 1686713 (1.6MiB) RX errors 0 dropped 1228 overruns 0frame 0TX packets 128bytes 18818 (18.3KiB) TX errors 0 Dropped 0 overruns 0 carrier 0 collisions 0 eth2: flags=4163 mtu 1500 ether 52:54:00:67:d8:a7 txqueuelen 1000 (Ethernet) RX packets 23718 bytes 1686113 (Ethernet) RX errors 0 dropped 4480 overruns 0 frame 0 TX packets 3 bytes 182.0 (182.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 Inet6:: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 0 (Local Loopback) RX packets 3598 bytes 305844 (298.6 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3598 bytes 305844 (298.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost ~] # ping 172.25.254.12 ping below the host It is found that ping is different because PING 172.25.254.12 (172.25.254.12) 56 (84) bytes of data is not loaded on the network card. From 172.25.254.112 icmp_seq=1 Destination Host Unreachable From 172.25.254.112 icmp_seq=2 Destination Host Unreachable From 172.25.254.112 icmp_seq=3 Destination Host Unreachable From 172.25.254.112 icmp_seq=4 Destination Host Unreachable ^ C-172.25.254.12 ping statistics-5 packets transmitted, 0 received, + 4 errors, 100% packet loss Time 4001ms [root@localhost ~] # brctl addif br0 eth0 loads this virtual interface on the eth0 network card [root@localhost ~] # brctl show View the bridge information bridge name bridge id STP enabled interfaces br0 8000.525400000c0a no eth0 virtual interface has been installed on the eth0 network card [root@localhost ~] # ping 172.25.254.12 ping is ping accessible Because PING 172.25.254.12 (172.25.254.12) 56 (84) bytes of data. 64 bytes from 172.25.254.12: icmp_seq=1 ttl=64 time=0.292 ms 64 bytes from 172.25.254.12: icmp_seq=2 ttl=64 time=0.143 ms 64 bytes from 172.25.254.12: icmp_seq=3 ttl=64 time=0.214 ms 64 bytes from 172.25.254.12: icmp_seq=4 ttl=64 time=0.220 ms ^ C-172.25.254.12 ping statistics-4 packets transmitted, 4 received, 0 packet loss Time 2999ms rtt min/avg/max/mdev = 0.143 ms [root@localhost ~] # 12345678910111213141517181920212232426272829303133343536383940414454647484950515355575859606162636465 remove temporary network interface [root@localhost Desktop] # brctl show view bridge information bridge name bridge id STP enabled interfaces br0 8000.525400000c0a no eth0 [root@localhost Desktop] # brctl delif br0 eth0 removes the br0 virtual interface from the eth0 card [root@localhost Desktop] # brctl show To check the bridge information again, there is no eth0 network card bridge name bridge id STP enabled interfaces br0 8000.000000000000 no [root@localhost Desktop] # ifconfig br0 down because the So you have to make its down drop before you can delete [root@localhost Desktop] # brctl delbr br0 delete the virtual interface [root@localhost Desktop] # brctl show to view the bridge information. There is no bridge name bridge id STP enabled interfaces [root@localhost Desktop] # ifconfig to view the network information. There is no br0 temporary interface eth0: flags=4163 mtu 1500 ether 52:54:00:00:0c:0a txqueuelen 1000 (Ethernet) RX packets 44359 bytes 3095658 (2.9MiB) RX errors 0 dropped 1228 overruns 0 frame 0 TX packets 166bytes 29931 (29.2 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eth2: flags=4163 mtu 1500 ether 52:54:00:67:d8:a7 txqueuelen 1000 ( Ethernet) RX packets 44334 bytes 3089827 (2.9MiB) RX errors 0 dropped 4481 overruns 0 frame 0 TX packets 3 bytes 182.0 (182.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6:: 1 prefixlen 128 scopeid 0x10 loop txqueuelen 0 (Local Loopback) RX packets 3859 bytes 328676 .9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 3859 bytes 328676 (320.9 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 [root@localhost Desktop] # above is how to build a bridge in Linux system Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report