您好,登錄后才能下訂單哦!
本篇文章為大家展示了Linux系統中如何進行網橋搭建,內容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
工作在數據鏈路層(L2)。以太網中,數據鏈路層地址就是mac地址,網橋與hub的區別在于,網橋會過濾mac,只有目的mac地址匹配的數據才會發送到出口。一個bridge指的是一個輸入到一個輸出的橋接。
brctl   # 橋接管理命令 brctl show ;brctl addbr br0 添加網橋; show   # 顯示 addbr   # 添加網橋 delbr   # 刪除網橋 addif   # 添加網絡橋接 delif  # 刪除網絡橋接
文件方式的網絡橋接。
可以在其真機中操作,操作前提是要將原本的 ifcfg-enp0s25,ifcfg-br0 轉移阿到其他的地方,以備后期恢復
[root@foundation12 ~]# cd /etc/sysconfig/network-scripts/ 在此目錄下 [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-小米手機 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-小米手機 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 移動到其他地方 1234567891011121314
在/etc/sysconfig/networl-scipts 目錄下 操作新的網絡橋接
[root@foundation12 network-scripts]# vim ifcfg-br0 設置真實主機的網卡 [root@foundation12 network-scripts]# ifconfig 查看真實物理網卡 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.9 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 enp0s25: flags=4163 mtu 1500 物理網卡 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.25.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.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 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.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 virbr1: flags=4099 mtu 1500 ether 52:54:00:d9:96:d6 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 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:00:21:64:1b txqueuelen 1000 (Ethernet) RX packets 31 bytes 4118 (4.0 KiB) 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 編寫物理網卡。 [root@foundation12 network-scripts]# systemctl restart network 重啟網絡 [root@foundation12 network-scripts]# brctl show 查看網絡信息 bridge name bridge id STP enabled interfaces br0 8000.0021cc6f78a8 no enp0s25 橋接搭建好 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 刪掉自己做的 [root@foundation12 network-scripts]# mv /opt/ifcfg-br0 . [root@foundation12 network-scripts]# mv /opt/ifcfg-enp0s25 . 將原本的和重新移動回來 [root@foundation12 network-scripts]# ls ifcfg-br0 ifdown-ovs ifup-eth ifup-sit ifcfg-enp0s25 ifdown-post ifup-ib ifup-Team 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
網絡接口的臨時搭建
[root@localhost ~]# brctl show 查看網橋信息 bridge name bridge id STP enabled interfaces [root@localhost ~]# brctl addbr br0 添加一塊新的虛擬接口 [root@localhost ~]# brctl show 查看網橋信息 已經有了 br0 這個虛擬接口 bridge name bridge id STP enabled interfaces br0 8000.000000000000 no [root@localhost ~]# ifconfig br0 172.25.254.112/24 給 br0 虛擬接口 賦予一個IP地址 [root@localhost ~]# ifconfig 查看虛擬接口信息 有了IP地址 br0: flags=4163 mtu 1500 inet 172.25.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.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 16 bytes 2835 (2.7 KiB) 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.6 MiB) RX errors 0 dropped 1228 overruns 0 frame 0 TX packets 128 bytes 18818 (18.3 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 23718 bytes 1686113 (1.6 MiB) RX errors 0 dropped 4480 overruns 0 frame 0 TX packets 3 bytes 182 (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一下主機 ,發現是ping不同的,因為是沒有加載在網卡上的 PING 172.25.254.12 (172.25.254.12) 56(84) bytes of data. 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 將這個虛擬接口加載到eth0 這塊網卡上 [root@localhost ~]# brctl show 查看網橋信息 bridge name bridge id STP enabled interfaces br0 8000.525400000c0a no eth0 虛擬接口已經裝到eth0網卡上 [root@localhost ~]# ping 172.25.254.12 ping 一下是可以ping 通的,因為已經有了網卡的 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/0.217/0.292/0.053 ms [root@localhost ~]# 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
[root@localhost Desktop]# brctl show 查看網橋的信息 bridge name bridge id STP enabled interfaces br0 8000.525400000c0a no eth0 [root@localhost Desktop]# brctl delif br0 eth0 將br0這個虛擬接口 從eth0這塊網卡上刪除掉 [root@localhost Desktop]# brctl show 再次查看網橋信息 已經沒有了eth0 這塊網卡 bridge name bridge id STP enabled interfaces br0 8000.000000000000 no [root@localhost Desktop]# ifconfig br0 down 因為正在工作的,所以是要讓其down掉,才能刪除 [root@localhost Desktop]# brctl delbr br0 刪除虛擬接口 [root@localhost Desktop]# brctl show 查看網橋信息 是已經全部沒有了 bridge name bridge id STP enabled interfaces [root@localhost Desktop]# ifconfig 查看網絡信息 ,已經沒有了br0臨時接口 eth0: flags=4163 mtu 1500 ether 52:54:00:00:0c:0a txqueuelen 1000 (Ethernet) RX packets 44359 bytes 3095658 (2.9 MiB) RX errors 0 dropped 1228 overruns 0 frame 0 TX packets 166 bytes 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.9 MiB) RX errors 0 dropped 4481 overruns 0 frame 0 TX packets 3 bytes 182 (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 (320.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]#
上述內容就是Linux系統中如何進行網橋搭建,你們學到知識或技能了嗎?如果還想學到更多技能或者豐富自己的知識儲備,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。