translated

This commit is contained in:
geekpi 2019-07-25 08:47:45 +08:00
parent 3c42ae2d37
commit f6b5353084
2 changed files with 126 additions and 126 deletions

View File

@ -1,126 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Bond WiFi and Ethernet for easier networking mobility)
[#]: via: (https://fedoramagazine.org/bond-wifi-and-ethernet-for-easier-networking-mobility/)
[#]: author: (Ben Cotton https://fedoramagazine.org/author/bcotton/)
Bond WiFi and Ethernet for easier networking mobility
======
![][1]
Sometimes one network interface isnt enough. Network bonding allows multiple network connections to act together with a single logical interface. You might do this because you want more bandwidth than a single connection can handle. Or maybe you want to switch back and forth between your wired and wireless networks without losing your network connection.
The latter applies to me. One of the benefits to working from home is that when the weather is nice, its enjoyable to work from a sunny deck instead of inside. But every time I did that, I lost my network connections. IRC, SSH, VPN — everything goes away, at least for a moment while some clients reconnect. This article describes how I set up network bonding on my Fedora 30 laptop to seamlessly move from the wired connection my laptop dock to a WiFi connection.
In Linux, interface bonding is handled by the bonding kernel module. Fedora does not ship with this enabled by default, but it is included in the kernel-core package. This means that enabling interface bonding is only a command away:
```
sudo modprobe bonding
```
Note that this will only have effect until you reboot. To permanently enable interface bonding, create a file called _bonding.conf_ in the _/etc/modules-load.d_ directory that contains only the word “bonding”.
Now that you have bonding enabled, its time to create the bonded interface. First, you must get the names of the interfaces you want to bond. To list the available interfaces, run:
```
sudo nmcli device status
```
You will see output that looks like this:
```
DEVICE TYPE STATE CONNECTION
enp12s0u1 ethernet connected Wired connection 1
tun0 tun connected tun0
virbr0 bridge connected virbr0
wlp2s0 wifi disconnected --
p2p-dev-wlp2s0 wifi-p2p disconnected --
enp0s31f6 ethernet unavailable --
lo loopback unmanaged --
virbr0-nic tun unmanaged --
```
In this case, there are two (wired) Ethernet interfaces available. _enp12s0u1_ is on a laptop docking station, and you can tell that its connected from the _STATE_ column. The other, _enp0s31f6_, is the built-in port in the laptop. There is also a WiFi connection called _wlp2s0_. _enp12s0u1_ and _wlp2s0_ are the two interfaces were interested in here. (Note that its not necessary for this exercise to understand how network devices are named, but if youre interested you can see the [systemd.net-naming-scheme man page][2].)
The first step is to create the bonded interface:
```
sudo nmcli connection add type bond ifname bond0 con-name bond0
```
In this example, the bonded interface is named _bond0_. The “_con-name bond0_” sets the connection name to _bond0_; leaving this off would result in a connection named _bond-bond0_. You can also set the connection name to something more human-friendly, like “Docking station bond” or “Ben”
The next step is to add the interfaces to the bonded interface:
```
sudo nmcli connection add type ethernet ifname enp12s0u1 master bond0 con-name bond-ethernet
sudo nmcli connection add type wifi ifname wlp2s0 master bond0 ssid Cotton con-name bond-wifi
```
As above, the connection name is specified to be [more descriptive][3]. Be sure to replace _enp12s0u1_ and _wlp2s0_ with the appropriate interface names on your system. For the WiFi interface, use your own network name (SSID) where I use “Cotton”. If your WiFi connection has a password (and of course it does!), youll need to add that to the configuration, too. The following assumes youre using [WPA2-PSK][4] authentication
```
sudo nmcli connection modify bond-wifi wifi-sec.key-mgmt wpa-psk
sudo nmcli connection edit bond-wif
```
The second command will bring you into the interactive editor where you can enter your password without it being logged in your shell history. Enter the following, replacing _password_ with your actual password
```
set wifi-sec.psk password
save
quit
```
Now youre ready to start your bonded interface and the secondary interfaces you created
```
sudo nmcli connection up bond0
sudo nmcli connection up bond-ethernet
sudo nmcli connection up bond-wifi
```
You should now be able to disconnect your wired or wireless connections without losing your network connections.
### A caveat: using other WiFi networks
This configuration works well when moving around on the specified WiFi network, but when away from this network, the SSID used in the bond is not available. Theoretically, one could add an interface to the bond for every WiFi connection used, but that doesnt seem reasonable. Instead, you can disable the bonded interface:
```
sudo nmcli connection down bond0
```
When back on the defined WiFi network, simply start the bonded interface as above.
### Fine-tuning your bond
By default, the bonded interface uses the “load balancing (round-robin)” mode. This spreads the load equally across the interfaces. But if you have a wired and a wireless connection, you may want to prefer the wired connection. The “active-backup” mode enables this. You can specify the mode and primary interface when you are creating the interface, or afterward using this command (the bonded interface should be down):
```
sudo nmcli connection modify bond0 +bond.options "mode=active-backup,primary=enp12s0u1"
```
The [kernel documentation][5] has much more information about bonding options.
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/bond-wifi-and-ethernet-for-easier-networking-mobility/
作者:[Ben Cotton][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/bcotton/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2019/07/networkingmobility-816x345.jpg
[2]: https://www.freedesktop.org/software/systemd/man/systemd.net-naming-scheme.html
[3]: https://en.wikipedia.org/wiki/Master/slave_(technology)#Terminology_concerns
[4]: https://en.wikipedia.org/wiki/Wi-Fi_Protected_Access#Target_users_(authentication_key_distribution)
[5]: https://www.kernel.org/doc/Documentation/networking/bonding.txt

View File

@ -0,0 +1,126 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (Bond WiFi and Ethernet for easier networking mobility)
[#]: via: (https://fedoramagazine.org/bond-wifi-and-ethernet-for-easier-networking-mobility/)
[#]: author: (Ben Cotton https://fedoramagazine.org/author/bcotton/)
绑定 WiFi 和以太网,以便于更轻松的网络移动
======
![][1]
有时一个网络接口是不够的。网络绑定允许将多条网络连接与单个逻辑接口一起工作。你可能因为需要单条连接更多的带宽而需要这么做。或者你可能希望在有线和无线网络之间来回切换而不会丢失网络连接。
我是后面一种情况。在家工作的好处之一是,当天气晴朗时,在阳光明媚的阳台而不是在室内工作是很愉快的。但每当我这样做时,我都会失去网络连接。 IRC、SSH、VPN一切都断开了客户端重连至少需要一会。本文介绍了如何在 Fedora 30 笔记本上设置网络绑定,以便从笔记本扩展坞的有线连接无缝切换到 WiFi。
在 Linux 中接口绑定由绑定内核模块处理。默认情况下Fedora 没有启用此功能,但它包含在 kernel-core 软件包中。这意味着启用接口绑定只需一个命令:
```
sudo modprobe bonding
```
请注意,这只会在你重启之前生效。要永久启用接口绑定,请在 _/etc/modules-load.d_ 目录中创建一个名为 _bonding.conf_ 的文件,该文件仅包含单词 “bonding”。
现在你已启用绑定,现在可以创建绑定接口了。首先,你必须获取要绑定的接口的名称。要列出可用的接口,请运行:
```
sudo nmcli device status
```
你将看到如下输出:
```
DEVICE TYPE STATE CONNECTION
enp12s0u1 ethernet connected Wired connection 1
tun0 tun connected tun0
virbr0 bridge connected virbr0
wlp2s0 wifi disconnected --
p2p-dev-wlp2s0 wifi-p2p disconnected --
enp0s31f6 ethernet unavailable --
lo loopback unmanaged --
virbr0-nic tun unmanaged --
```
在本例中,有两个(有线)以太网接口可用。 _enp12s0u1_ 在笔记本电脑扩展坞上,你可以通过 _STATE_ 列知道它已连接。另一个是 _enp0s31f6_,是笔记本电脑中的内置端口。还有一个名为 _wlp2s0_ 的 WiFi 连接。 _enp12s0u1__wlp2s0_ 是我们在这里感兴趣的两个接口。(请注意,本文无需了解网络设备的命名方式,但如果你感兴趣,可以查看 [systemd.net-naming-scheme 手册页][2]。)
第一步是创建绑定接口:
```
sudo nmcli connection add type bond ifname bond0 con-name bond0
```
在此示例中,绑定接口名为 _bond0_。 “_con-name bond0_” 将连接名称设置为 _bond0_。直接这样会有一个名为 _bond-bond0_ 的连接。你还可以将连接名设置得更加人性化,例如 “Docking station bond” 或 “Ben”
下一步是将接口添加到绑定接口:
```
sudo nmcli connection add type ethernet ifname enp12s0u1 master bond0 con-name bond-ethernet
sudo nmcli connection add type wifi ifname wlp2s0 master bond0 ssid Cotton con-name bond-wifi
```
如上所示,连接名称被设置为[更具描述性][3]。请务必使用系统上相应的接口名称替换 _enp12s0u1__wlp2s0_。对于 WiFi 接口,请使用你自己的网络名称 SSID替换我的 “Cotton”。如果你的 WiFi 连接有密码(这当然会有!),你也需要将其添加到配置中。以下假设你使用 [WPA2-PSK][4] 身份验证
```
sudo nmcli connection modify bond-wifi wifi-sec.key-mgmt wpa-psk
sudo nmcli connection edit bond-wif
```
第二条命令将进入交互式编辑器,你可以在其中输入密码,而无需将其记录在 shell 历史记录中。输入以下内容,将 _password_ 替换为你的实际密码
```
set wifi-sec.psk password
save
quit
```
现在,你可以启动你的绑定接口以及你创建的辅助接口
```
sudo nmcli connection up bond0
sudo nmcli connection up bond-ethernet
sudo nmcli connection up bond-wifi
```
你现在应该能够在不丢失网络连接的情况下断开有线或无线连接。
### 警告:使用其他 WiFi 网络时
在指定的 WiFi 网络间移动时,此配置很有效,但是当远离此网络时,那么绑定中使用的 SSID 就不可用了。从理论上讲,可以为每个使用的 WiFi 连接添加一个接口,但这似乎并不合理。相反,你可以禁用绑定接口:
```
sudo nmcli connection down bond0
```
回到定义的 WiFi 网络时,只需按上述方式启动绑定接口即可。
### 微调你的绑定
默认情况下绑定接口使用“负载平衡round-robin”模式。 这会在接口上平均分配负载。 但是,如果你有有线和无线连接,你可能希望更喜欢有线连接。 “active-backup” 模式能实现此功能。 你可以在创建接口时指定模式和主接口,或者之后使用此命令(绑定接口应该关闭):
```
sudo nmcli connection modify bond0 +bond.options "mode=active-backup,primary=enp12s0u1"
```
[kernel 文档][5]提供了有关绑定选项的更多信息。
--------------------------------------------------------------------------------
via: https://fedoramagazine.org/bond-wifi-and-ethernet-for-easier-networking-mobility/
作者:[Ben Cotton][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://fedoramagazine.org/author/bcotton/
[b]: https://github.com/lujun9972
[1]: https://fedoramagazine.org/wp-content/uploads/2019/07/networkingmobility-816x345.jpg
[2]: https://www.freedesktop.org/software/systemd/man/systemd.net-naming-scheme.html
[3]: https://en.wikipedia.org/wiki/Master/slave_(technology)#Terminology_concerns
[4]: https://en.wikipedia.org/wiki/Wi-Fi_Protected_Access#Target_users_(authentication_key_distribution)
[5]: https://www.kernel.org/doc/Documentation/networking/bonding.txt