19

A similar question was asked for windows Automatically prefer Ethernet over WLAN but I'm on linux and am using NetworkManager.

Right now if the ethernet cable is plugged in and is available while wifi connections are also available NetworkManager chooses the wifi connection. How can I tell it to always choose the wired connection if available?

I'm on Fedora 17 using NetworkManager-0.9.4.0-9.git20120521

1
  • I'm in Fedora 20, and have the same problem. Toggling WiFi off seems to be a workaround. At least this can be done from the top panel (drop-down user menu). Mar 2, 2014 at 21:17

3 Answers 3

4

NetworkManager has a GUI frontend named networkmanager-connection-editor or nm-connection-editor, where priorities can be set for individual connections.

0 - Highest Priority and so on.

1
  • 1
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 23, 2022 at 16:15
8

Note: @Proxy user’s answer served me as the basis for my answer.


You can accomplish this using nmcli (Command Line Interface of NetworkManager), no need to install ifmetric.

All you need to do is set the ipv4.route-metric option of each required network to some positive integer (default is -1); the lower the number, the higher the priority. After that you need to reconnect to all changed/required networks (simple up is enough, no need to turn them down first).

# List of connections
# You need to get the connection name (first column)
nmcli con

# Set the `ipv4.route-metric` of each required network
# Change the `$con_name_x` and integer as required
nmcli con mod $con_name_1 ipv4.route-metric 20  # This connection is more prefered
nmcli con mod $con_name_2 ipv4.route-metric 40  # This connection is less prefered

# Disconnect and reconnect the networks to make the changes effective
nmcli con down $con_name_1
nmcli con down $con_name_2
nmcli con up $con_name_1
nmcli con up $con_name_2

You can also set ipv6.route-metric for each network.

7

Just a couple things:

You could try these commands in your environment to see if they work and bring desired results:

  • auto Ethernet
  • auto ethX (Replace X with whatever number your kernel assigns (run ifconfig to check))

Alternatively, you can have a look at your IP routes found by issuing:

sudo route -n

By looking at the output, see if wlan0 is on all routes.

Several other questions have been asked with this and the only way to get Linux to favour an interface (by default it is eth0 but in your case, something went awry) is to manipulate the metrics.

You can configure the metric for an interface using ifmetric which manipulates the metric on an interface you specify. I haven't tested this on Fedora per se, but I can see it is in the repositories. So, issue:

yum install ifmetric

Then when it is installed, you will want to go to:

/etc/network/interfaces

Use vi, nano, emacs, whatever editor you use and then add underneath whichever interface you want to configure (in this case eth0):

up ifmetric eth0 X

X relates to a number determining the priority, 0 by default is the highest priority, but to avoid hitting static/default routes, use something above 2. Then you will want to add a higher number to wlan0. So:

up ifmetric eth0 10

and under wlan0:

up ifmetric wlan0 20

Your file should be looking like this:

 iface eth0 inet dhcp
    up ifmetric eth0 10

iface wlan0 inet dhcp
    up ifmetric wlan0 20

Let us know if it helps!

EDIT: Just come across a few links:

How do I configure a linux machine to ignore wifi when connected via LAN?

How do I set the priority of network connections in Ubuntu?

EDIT 2:

There is also a metric field in Network Manager GUI!

1
  • A network interface is either managed by Network Manager or by /etc/network/interfaces. While this answer is technically correct, the question is about Network Manager and this answer does not match the question.
    – Juergen
    Oct 20, 2023 at 12:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .