Network bridge

出自 Arch Linux 中文维基

本文內容或本節內容已經過期。

原因: 請提供模板的第一個位置參數以概括原因。 (在Talk:Network bridge討論)

這篇文章或章節的翻譯不反映原文。

原因:Last updated in 2015 (372839), out of sync with English page(在 Talk:Network bridge# 中討論)

網橋是一種軟件配置,用於連結兩個或更多個不同網段。網橋的行為就像是一台虛擬的網絡交換機,工作於透明模式(即其他機器不必關注網橋的存在與否)。任意的真實物理設備(例如 eth0)和虛擬設備(例如 tap0)都可以連接到網橋。

本文講述如何創建至少包含一個以太網設備的網橋,這種應用常見於QEMU、設置基於軟件的訪問點等場景。

創建網橋[編輯 | 編輯原始碼]

創建網橋有多種途徑。

通過 bridge-utils[編輯 | 編輯原始碼]

本節講述用 bridge-utils 軟件包裏面的 brctl 工具管理網橋。該軟件包已進入官方倉庫(official repositories)。brctl 的完整選項清單請參閱 brctl(8)

新建一個網橋:

# brctl addbr bridge_name

添加一個設備(例如eth0)到網橋:

# brctl addif bridge_name eth0

顯示當前存在的網橋及其所連接的網絡端口:

$ brctl show

啟動網橋:

# ip link set up dev bridge_name

刪除網橋,需要先關閉它:

# ip link set dev bridge_name down
# brctl delbr bridge_name

通過 iproute2[編輯 | 編輯原始碼]

本節講述用 iproute2 軟件包裏面的 ip 工具管理網橋。該軟件包包含在 base 包組中。

創建一個網橋並設置其狀態為已啟動:

# ip link add name bridge_name type bridge
# ip link set dev bridge_name up

添加一個網絡端口(比如 eth0)到網橋中,要求先將該端口設置為混雜模式並啟動該端口:

# ip link set dev eth0 promisc on
# ip link set dev eth0 up

把該端口添加到網橋中,再將其所有者設置為 bridge_name 就完成了配置:

# ip link set dev eth0 master bridge_name

要顯示現存的網橋及其關聯的端口,可以用 bridge 工具(它也是 iproute2 的組成部分)。詳閱 bridge(8)

# bridge link show

若要刪除網橋,應首先移除它所關聯的所有端口,同時關閉端口的混雜模式並關閉端口以將其恢復至原始狀態。

# ip link set eth0 promisc off
# ip link set eth0 down
# ip link set dev eth0 nomaster

當網橋的配置清空後就可以將其刪除:

# ip link delete bridge_name type bridge

通過 netctl[編輯 | 編輯原始碼]

參閱 Bridge with netctl.

通過 systemd-networkd[編輯 | 編輯原始碼]

參閱 systemd-networkd#Bridge interface.

通過 NetworkManager[編輯 | 編輯原始碼]

Gnome's NetworkManager can create bridges, but currently will not auto-connect to them. Open Network Settings, add a new interface of type Bridge, add a new bridged connection, and select the MAC address of the device to attach to the bridge.

Now, find the UUID of the attached device (by default named "bridge0 slave 1"):

$ nmcli connection

Finally, enable that connection:

$ nmcli con up <UUID>

If NetworkManager's default interface for the device you added to the bridge connects automatically, you may want to disable that by clicking the gear next to it in Network Settings, and unchecking "Connect automatically" under "Identity."

分配 IP 地址[編輯 | 編輯原始碼]

When the bridge is fully set up, it can be assigned an IP address:

# ip addr add dev bridge_name 192.168.66.66/24

這篇文章的某些內容需要擴充。

原因: This section needs to be connected to the link-level part described in QEMU#Tap networking with QEMU. For now, see the instructions given there. (在 Talk:Network bridge 中討論)

提示與技巧[編輯 | 編輯原始碼]

網橋使用無線網絡端口[編輯 | 編輯原始碼]

To add a wireless interface to a bridge, you first have to assign the wireless interface to an access point or start an access point with hostapd. Otherwise the wireless interface will not be added to the bridge.

See also Bridging with a wireless NIC on Debian wiki.

參閱[編輯 | 編輯原始碼]