Difference between revisions of "Network bridge (简体中文)"

From ArchWiki
Jump to navigation Jump to search
m
(update man page references, updated man page links (interactive))
(Tag: wiki-scripts)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{DISPLAYTITLE:Network bridge (简体中文)}}
 
{{DISPLAYTITLE:Network bridge (简体中文)}}
 +
[[Category:简体中文]]
 
[[Category:Networking (简体中文)]]
 
[[Category:Networking (简体中文)]]
 
[[en:Network bridge]]
 
[[en:Network bridge]]
 
[[ja:ネットワークブリッジ]]
 
[[ja:ネットワークブリッジ]]
{{TranslationStatus (简体中文)|Network_bridge|2015-03-28|367464}}
+
{{TranslationStatus (简体中文)|Network_bridge|2015-05-07|367464}}
  
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related|Bridge with netctl}}
 
{{Related|Bridge with netctl}}
 
{{Related articles end}}
 
{{Related articles end}}
A bridge is a piece of software used to unite two or more network segments. A bridge behaves like a virtual network switch, working transparently (the other machines don't need to know or care about its existence). Any real devices (e.g. {{ic|eth0}}) and virtual devices (e.g. {{ic|tap0}}) can be connected to it.
+
网桥是一种软件配置,用于连结两个或更多个不同网段。网桥的行为就像是一台虚拟的网络交换机,工作于透明模式(即其他机器不必关注网桥的存在与否)。任意的真实物理设备(例如 {{ic|eth0}})和虚拟设备(例如 {{ic|tap0}})都可以连接到网桥。
  
This article explains how to create a bridge that contains at least an ethernet device. This is useful for things like the bridge mode of [[QEMU]], setting a software based access point, etc.
+
本文讲述如何创建至少包含一个以太网设备的网桥,这种应用常见于[[QEMU]]、设置基于软件的访问点等场景。
  
== Creating a bridge ==
+
== 创建网桥 ==
  
There are a number of ways to create a bridge.
+
创建网桥有多种途径。
  
=== With bridge-utils ===
+
=== 通过 bridge-utils ===
  
This section describes the management of a network bridge using the ''brctl'' tool from the {{Pkg|bridge-utils}} package, which is available in the [[official repositories]]. See {{ic|man brctl}} for full listing of options.
+
本节讲述用 {{Pkg|bridge-utils}} 软件包里面的 ''brctl'' 工具管理网桥。该软件包已进入官方仓库([[official repositories]])。''brctl'' 的完整选项清单请参阅 {{man|8|brctl}}
  
Create a new bridge:
+
新建一个网桥:
  
 
  # brctl addbr ''bridge_name''
 
  # brctl addbr ''bridge_name''
  
Add a device to a bridge, for example {{ic|eth0}}:
+
添加一个设备(例如{{ic|eth0}})到网桥:
  
 
  # brctl addif ''bridge_name'' eth0
 
  # brctl addif ''bridge_name'' eth0
  
Show current bridges and what interfaces they are connected to:
+
显示当前存在的网桥及其所连接的网络端口:
  
 
  $ brctl show
 
  $ brctl show
  
Set the bridge device up:
+
启动网桥:
  
 
  # ip link set up dev ''bridge_name''
 
  # ip link set up dev ''bridge_name''
  
Delete a bridge, you need to first set it to ''down'':
+
删除网桥,需要先关闭它:
  
 
  # ip link set dev ''bridge_name'' down
 
  # ip link set dev ''bridge_name'' down
 
  # brctl delbr ''bridge_name''
 
  # brctl delbr ''bridge_name''
  
=== With iproute2 ===
+
=== 通过 iproute2 ===
  
This sections describes the management of a network bridge using the ''ip'' tool from the {{Pkg|iproute2}} package, which is included in the {{Grp|base}} group.
+
本节讲述用 {{Pkg|iproute2}} 软件包里面的 ''ip'' 工具管理网桥。该软件包包含在 {{Grp|base}} 包组中。
  
Create a new bridge and change its state to up:
+
创建一个网桥并设置其状态为已启动:
  
 
  # ip link add name ''bridge_name'' type bridge
 
  # ip link add name ''bridge_name'' type bridge
 
  # ip link set dev ''bridge_name'' up
 
  # ip link set dev ''bridge_name'' up
  
To add an interface (e.g. eth0) into the bridge, it must be first set to ''promiscuous'' mode and its state must be up:
+
添加一个网络端口(比如 eth0)到网桥中,要求先将该端口设置为混杂模式并启动该端口:
  
 
  # ip link set dev eth0 promisc on
 
  # ip link set dev eth0 promisc on
 
  # ip link set dev eth0 up
 
  # ip link set dev eth0 up
  
Adding the interface into the bridge is done by setting its master to {{ic|''bridge_name''}}:
+
把该端口添加到网桥中,再将其所有者设置为 {{ic|''bridge_name''}} 就完成了配置:
  
 
  # ip link set dev eth0 master ''bridge_name''
 
  # ip link set dev eth0 master ''bridge_name''
  
To show the existing bridges and associated interfaces, use the ''bridge'' utility (also part of {{Pkg|iproute2}}). See {{ic|man bridge}} for details.
+
要显示现存的网桥及其关联的端口,可以用 ''bridge'' 工具(它也是 {{Pkg|iproute2}} 的组成部分)。详阅 {{man|8|bridge}}
  
 
  # bridge link show
 
  # bridge link show
  
When the bridge is to be deleted, all interfaces should be removed first. Also turn off promiscuous mode and set it down to restore the original state.
+
若要删除网桥,应首先移除它所关联的所有端口,同时关闭端口的混杂模式并关闭端口以将其恢复至原始状态。
  
 
  # ip link set eth0 promisc off
 
  # ip link set eth0 promisc off
Line 69: Line 70:
 
  # ip link set dev eth0 nomaster
 
  # ip link set dev eth0 nomaster
  
When the bridge is empty, it can be deleted:
+
当网桥的配置清空后就可以将其删除:
  
 
  # ip link delete ''bridge_name'' type bridge
 
  # ip link delete ''bridge_name'' type bridge
  
=== With netctl ===
+
=== 通过 netctl ===
  
See [[Bridge with netctl]].
+
参阅 [[Bridge with netctl]].
  
=== With systemd-networkd ===
+
=== 通过 systemd-networkd ===
  
See [[systemd-networkd#Bridge interface]].
+
参阅 [[systemd-networkd#Bridge interface]].
  
=== With NetworkManager ===
+
=== 通过 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.
 
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.
Line 95: Line 96:
 
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."
 
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."
  
== Assigning an IP address ==
+
== 分配 IP 地址 ==
  
 
When the bridge is fully set up, it can be assigned an IP address:
 
When the bridge is fully set up, it can be assigned an IP address:
Line 103: Line 104:
 
{{Expansion|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.}}
 
{{Expansion|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.}}
  
== Tips and tricks ==
+
== 提示与技巧 ==
  
=== Wireless interface on a 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 [[Software_access_point|hostapd]]. Otherwise the wireless interface won't be added to the 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 [[Software_access_point|hostapd]]. Otherwise the wireless interface won't be added to the bridge.
Line 111: Line 112:
 
See also [https://wiki.debian.org/BridgeNetworkConnections#Bridging_with_a_wireless_NIC Bridging with a wireless NIC] on Debian wiki.
 
See also [https://wiki.debian.org/BridgeNetworkConnections#Bridging_with_a_wireless_NIC Bridging with a wireless NIC] on Debian wiki.
  
== See also ==
+
== 参阅 ==
  
 
* [http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge Official documentation for bridge-utils]
 
* [http://www.linuxfoundation.org/collaborate/workgroups/networking/bridge Official documentation for bridge-utils]
 
* [http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 Official documentation for iproute2]
 
* [http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 Official documentation for iproute2]

Latest revision as of 18:27, 9 September 2017

翻译状态: 本文是英文页面 Network_bridge翻译,最后翻译时间:2015-05-07,点击这里可以查看翻译后英文页面的改动。

网桥是一种软件配置,用于连结两个或更多个不同网段。网桥的行为就像是一台虚拟的网络交换机,工作于透明模式(即其他机器不必关注网桥的存在与否)。任意的真实物理设备(例如 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

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: 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. (Discuss in 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 won't be added to the bridge.

See also Bridging with a wireless NIC on Debian wiki.

参阅