Binding WiFi and Ethernet, to make it easier to move between networks

Sometimes a network interface is not enough. Binding network allows multiple network connections to work with a single logical interface. Because you may need to connect more bandwidth to single and do this, or you might want in between wired and wireless networks to switch back and forth without losing network connectivity.

In Linux, the interface bonding binding processing by the kernel module. By default, Fedora does not enable this feature, but it is included in kernel-core package. This means that the interface is enabled to bind a single command:

  1. sudomodprobe bonding

Note that this will only take effect until you restart. To permanently enabled interface binding, create a file named bonding.conf in /etc/modules-load.d directory, the file contains only the word bonding.

Now you have enabled the binding, you can now create a binding interfaces. First, you must obtain the name of the interface to be bound. To list the available interfaces, run:

  1. sudo nmcli device status

You will see the following output:

  1. DEVICE TYPE STATE CONNECTION
  2. enp12s0u1 ethernet connected Wired connection 1
  3. tun0 tun connected tun0
  4. virbr0 bridge connected virbr0
  5. wlp2s0 wifi disconnected --
  6. p2p-dev-wlp2s0 wifi-p2p disconnected --
  7. enp0s31f6 ethernet unavailable --
  8. lo loopback unmanaged --
  9. virbr0-nic tun unmanaged --

In the present embodiment, there are two (wired) Ethernet interface available. enp12s0u1 on a laptop docking station, you can know that it is connected through the STATE column. Another is enp0s31f6, is the laptop's built-in port. Also called wlp2s0 WiFi connection. enp12s0u1 and wlp2s0 two interfaces we are interested in here. (Please note, read this without understanding the naming of network equipment, but if you're interested, you can view systemd.net-naming-scheme man page .)

The first step is to create a binding interfaces:

  1. sudo nmcli connection add type bond ifname bond0 con-name bond0

In this example, the binding interface called bond0. con-name bond0 connection name to bond0. Doing so will have a direct connection called bond-bond0 of. You can also connect the name set more humane, such as "Docking station bond" or "Ben".

The next step is to add an interface to bind the interface:

  1. sudo nmcli connection add type ethernet ifname enp12s0u1 master bond0 con-name bond-ethernet
  2. sudo nmcli connection add type wifi ifname wlp2s0 master bond0 ssid Cotton con-name bond-wifi

As indicated above, the connection name is set to be more descriptive . Be sure to replace enp12s0u1 and wlp2s0 using the appropriate interface name on the system. For the WiFi interface, use your own network name (SSID) to replace my "Cotton". If you have a WiFi connection password (which of course there will be!), You also need to add it to the configuration. The following assumes that you use WPA2-PSK authentication

  1. sudo nmcli connection modify bond-wifi wifi-sec.key-mgmt wpa-psk
  2. sudo nmcli connection edit bond-wif

The second command will enter the interactive editor, you can enter a password, without the need to record in the shell history. Enter the following, will replace the password for your actual password.

  1. set wifi-sec.psk password
  2. save
  3. quit

Now, you can start your binding interface and secondary interface you create.

  1. sudo nmcli connection up bond0
  2. sudo nmcli connection up bond-ethernet
  3. sudo nmcli connection up bond-wifi

You should now be able to disconnect a wired or wireless connection without loss of network connectivity.

Warning: Use a different WiFi network when

When moving between the specified WiFi network, this configuration is very effective, but when this remote network, then the binding is not usable SSID used. In theory, add a WiFi interface can be connected to each use, but this seems unreasonable. Instead, you can disable the binding interfaces:

  1. sudo nmcli connection down bond0

Back to the WiFi network definitions, simply launch the binding interface can be as described above.

Fine-tune your bindings

By default, the binding interface "polling round-robin" mode. This will distribute the load evenly on the interface. However, if you have a wired and wireless connection, you might want to prefer a wired connection. active-backup mode to achieve this function. You can specify the mode and the primary interface when creating interfaces, or after using this command (bound interfaces should be closed):

  1. sudo nmcli connection modify bond0 +bond.options "mode=active-backup,primary=enp12s0u1"

Kernel documentation provides more information about binding options.

via:fedoramagazine

Guess you like

Origin www.linuxidc.com/Linux/2019-07/159684.htm