98

I'd like to move up and down available wireless access points, setting priorities as we can do in Microsoft Windows. I can't remember to have ever succeeded in this since using network-manager. Maybe something with conf files is possible...

I'm not interested in different network managers.

Falko
  • 241
jasmines
  • 11,011

6 Answers6

104

Apparently in 2014 NetworkManager team introduced such a feature -- to specify priorities for different networks. There is now connection.autoconnect-priority.

This article provides lots of information on how to interface NetworkManager via nmcli.

For example with

nmcli -f NAME,UUID,AUTOCONNECT,AUTOCONNECT-PRIORITY c

you can list known networks and see their default priority to be 0. Now I have run

nmcli connection modify HOME-WIFI connection.autoconnect-priority 10

to give my home WiFi higher priority. I have the same work WiFi points available at home as well, but need to connect to HOME-WIFI when I am home. That command heavily rewritten /etc/NetworkManager/system-connections/HOME-WIFI which added autoconnect-priority=10 into [connection] section - time will show if it works as it should.

Pablo Bianchi
  • 15,657
Yaroslav Halchenko
  • 1,141
  • 2
  • 7
  • 3
  • 3
    these features don’t seem to have arrived to LTS (14.04) yet(?) :( – törzsmókus Feb 18 '16 at 17:26
  • 3
    This is visible through KDE 16.04's Network UI as a "priority" setting. Shame it isn't available elsewhere. Not even nmtui has it. – Oli Oct 10 '16 at 15:33
  • 6
    Works perfectly in Ubuntu 16.04. Really like this approach since it uses only standard tools. GNOME 3 GUI ("Network" in "Control Center") doesn't give access to priority setting neither. Shame indeed. – dasup Nov 28 '16 at 11:43
  • 4
    From the gnome docs:

    "autoconnect-priority: The autoconnect priority. If the connection is set to autoconnect, connections with higher priority will be preferred. Defaults to 0. The higher number means higher priority."

    – Michael Mandel May 09 '17 at 00:37
  • 3
    Great! Should be the accepted answer! – Caleb Stanford Sep 21 '17 at 16:25
  • nmcli c show HOME-WIFI | grep priority, and I can find what I wanted as well. – Polv Aug 25 '21 at 02:50
40

Can WiFi priority be dragged up and down in NetworkManager?

The short answer is “Not yet.” As of mid 2018, Ubuntu has nothing as easy as Microsoft Windows for setting the WiFi priority. However, there are ways to accomplish what you want.


TL;DR? Summary

For command line use nmcli. For GUI, plasma-nm.

nmcli -f autoconnect-priority,name c
nmcli c mod "mypreferred" conn.autoconnect-p 10
nmcli c mod "xfinitywifi" conn.autoconnect-p -10

or

apt install plasma-nm
kde5-nm-connection-editor

Available alternatives

Here are the currently available ways of setting WiFi priority, along with a short description of why they don't quite answer the original question.

Command line tools (nmcli)

While this solution is probably the easiest way to do it and it does work with NetworkManager, nmcli does not allow Microsoft Windows-style drag-and-drop reordering. In fact, nmcli (as the name suggests) is a "command line interface" to NetworkManager, which means you'll need to type commands in the terminal, which can be off-putting for some people. I'll describe more how to use it below.

Plasma-nm (kde5-nm-connection-editor)

This tool does not allow drag-and-drop reordering, but it does work with NetworkManager. Despite the name "KDE", it works with any desktop environment (I tested it with GNOME). It presents a graphical interface that lets one edit the "autoconnect-priority" of a network. I'll discuss how to use it below.

Wifi Radar

This tool does allow moving network priorities up and down, as requested. However, it is not actually integrated with Network Manager; in fact I believe it is a mistake to run both at the same time. Also, despite having a graphical interface, it is not as easy to use as it should be. Another reason to not use Wifi Radar is that it is a Python script that must be run as root, a potential security risk. Also, according to the man page, WiFi Radar is very power consuming and has "probably lots" of bugs.

GNOME network control panel (not even in the running)

I mention this more for completeness as it's what people would expect to work, but it doesn't. GNOME, which is Ubuntu's current default desktop environment, comes with a network control panel that simply cannot show or edit autoconnect priorities at all. (By the way, nmcli and plasma-nm both work fine under GNOME.)

nm-connection-editor: GNOME's old network control panel

GNOME used to have the ability to set connection priorities, albeit in a clunky way, not drag and drop. The old control panel is yet included in GNOME, but is not accessible by clicking. Instead, run the command nm-connection-editor, then select a WiFi network, click Edit, go to the General tab, and click the - / + buttons next to "connection priority for auto activation".

Emacs/vi

If you're a hardcore geek, mumble code in your sleep, all you need to do is add the line "autoconnect-priority: 10" to the file /etc/NetworkManager/system-connections/foo. See nm-settings(5).


Full explanation with examples

Both nmcli and kde5-nm-connection-editor can edit individual network autoconnect priorities. Only nmcli can show you a list of all the currently set priorities. Both assume that you know that higher numbers represent higher priorities and that zero is the default. Negative numbers are allowed and work to mark a network as a "last resort" if nothing else is available (See man nm-settings and search for "autoconnect-priority".)

The changes nmcli and plasma-nm make are stored permanently by NetworkManager in /etc/NetworkManager/system-connections/.

How to use nmcli

This is my preferred solution and it already comes with Ubuntu. If you're familiar with the command line or if you have a naturally linguistic brain, you may find this solution easier than using a mouse. On the other hand, if you want to try a graphical interface first, skip ahead to the next section on KDE's plasma-nm. For all of the examples below, you'll need to open a Terminal to type in the commands.

To list current priorities

$ nmcli -f autoconnect-priority,name c 

Sample output:

AUTOCONNECT-PRIORITY  NAME
0                     Blake5Net             
0                     Caffe Ubuntu      
0                     Caffe Ubuntu Guest      
0                     Fire Hotspot          
0                     JET & Mishka             
0                     La Marzocco           
0                     Le_MX                 
0                     MobileLab             
0                     xfinitywifi           

Tip: If you have a very long list, you may want to sort them by priority:

nmcli -f autoconnect-priority,name c | tail -n +2 | sort -nr

How to set a network as preferred

nmcli connection modify "Caffe Ubuntu" connection.autoconnect-priority 10

Note that you can use any number you want for the priority. A larger number moves the network to the top of the list.

How to set a network as a last resort

nmcli connection modify "xfinitywifi" connection.autoconnect-priority -10

Negative priority values are lower than the default of 0, which means they will be tried last, if no other known WiFi network can be found. Note that, due to a bug in some versions of nmcli, you may see negative numbers listed as huge positive numbers like 4294967286. Don't worry about this as it will still work fine.

How to use plasma-nm

Plasma-nm, KDE's NetworkManager client, lets you change a network's priority through several clicks in a graphical interface. You cannot drag-and-drop, instead you must specify a number. As with nmcli, higher numbers are higher priority. Unfortunately, you cannot see a list of what other priorities you've set in the past so you may have to guess at a number. Personally, I just use "10" for preferred networks and "-10" for last resort networks and I don't differentiate between them beyond that.

You don't need to install all of KDE just to get plasma-nm. (On my machine, running GNOME, the full KDE package would have required downloading over 600MB; in contrast, plasma-nm was only 8MB). I installed plasma-nm from the command line like so:

sudo apt install plasma-nm

and I ran it by typing this:

kde5-nm-connection-editor

(Well, technically, I didn't type all that. I used TAB to autocomplete the typing for me).

If you don't use KDE, the first time you run plasma-nm, it will ask you about creating a "wallet" to store credentials. I just hit "Cancel" to the question and it worked fine for me.

Then it will show you a list of connections. Double-click on the connection you want to edit. That will bring up the "Connection Editor" panel. Choose the "General Configuration" tab. At the bottom, you'll see a box labeled "Priority". Change it from 0 to 10 (preferred) or -10 (last resort). Click "OK" to save the changes.

Connection Editor panel of plasma-nm

Since changes are permanently stored with NetworkManager, once you're finished adjusting priorities, you don't have to keep plasma-nm installed if you don't want to. (sudo apt remove plasma-nm)

hackerb9
  • 2,186
  • 15
  • 13
hackerb9
  • 5,605
  • 2
    Thank you (this should be the accepted answer). To clarify: Does GNOME [...] simply cannot show or edit autoconnect priorities at all. mean that using nmcli has no effect in Gnome? (The tool is still available in Ubuntu 17.10, but maybe as a dependency to Unity?) – leo Feb 13 '18 at 19:47
  • Thank you @leo, I've fixed it now to make it more explicit that I meant the network tools builtin to GNOME cannot handle priorities. You can still run nmcli or KDE's networking tool without any problems under GNOME. – hackerb9 Mar 07 '18 at 10:00
  • 2
    No need to install KDE tools for this. Just run nm-connection-editor (package network-manager-gnome). (So it’s not actually true that GNOME doesn’t have built-in tools to do this. It’s just that since they redesigned the network settings, there’s no way to find this without knowing what to look for.) – Socob Aug 03 '18 at 10:11
  • Thanks, Socob. I hadn't known about that. I'll fix my answer. So is this tool deprecated? If gnome is going to remove it soon, perhaps it's not the best solution. – hackerb9 Aug 04 '18 at 18:26
  • I don’t know whether it’s officially deprecated (I doubt GNOME announces an official status for things like this). I’d assume that they would only remove nm-connection-editor once/if the new control panel has all the features of the old one. – Socob Aug 08 '18 at 11:55
  • The manpage on autoconnect-priority says the format is int32 and the default is 0. Does this mean that I can specify negative priority for some WiFi APs? E.g. I only want to use the free public wifi if no other known wifi is around. This would allow me to do that without setting a priority for all of them. (Edit: I just realized your example is indeed negative. So this comment is just to make this more obvious to the skimming reader) – lucidbrot Nov 30 '20 at 09:13
21

Run nm-connection-editor

Ever since the (network) settings were redesigned in GNOME, some functionality cannot be accessed anymore from the new settings interface. To use the old one, which exposes more options, run nm-connection-editor.

Setting connection priority in <code>nm-connection-editor</code>

Socob
  • 839
  • 1
  • 9
  • 18
19

WiFi Radar is a Python/PyGTK2 utility for managing WiFi profiles. It enables you to scan for available networks and create profiles for your preferred networks. At boot time, running WiFi Radar will automatically scan for an available preferred network and connect to it. You can drag and drop your preferred networks to arrange the profile priority. 1

Install WiFi Radar, just press Ctrl+Alt+T on your keyboard to open Terminal. When it opens, run the command below.

sudo apt install wifi-radar

To run it,

sudo wifi-radar

WiFi Radar has a new version 2.0 it can be downloaded from their website. Or download it from Here

1Source: Ubuntu Geek

Pablo Bianchi
  • 15,657
Mitch
  • 107,631
  • 1
    Do I need to add it manually to startup applications? – jasmines Jul 20 '12 at 06:46
  • If you want it to automatically start, then yes. – Mitch Jul 20 '12 at 10:58
  • 1
    What if I don't? Will the priorities be ignored or remembered? – jasmines Jul 20 '12 at 11:35
  • According to WiFi Radar you don't have to. priorities will stay the same. – Mitch Jul 20 '12 at 11:43
  • 1
    The tool looks promising, but I found no way to save the changed AP priority. When restarting wifi-radar, the APs appear in the old order. – mirk May 20 '13 at 07:47
  • I can confirm that this does not work out of the box. More info on configuration would be nice. – don.joey Aug 15 '13 at 10:17
  • I have downvoted the question because this is no longer a valid option. I cannot find a way to prioritize a certain connection. – don.joey Nov 16 '13 at 09:58
  • 2
    You didn't downvote the question, but you did the answer. This has been tried with 12.10, 13.04, 13.10, and Fedora, and it works perfect out of the box. Plus the fact that this question is over a year old. Try the new release. WiFi Radar has a new version 2.0 it can be downloaded from their website. The website has also the need documentations. – Mitch Nov 16 '13 at 10:16
  • @Mitch The link is broken. – Kasisnu Sep 12 '14 at 13:39
  • 1
    @Kasisnu I've fixed the link, and added another one as well. Thanks. – Mitch Sep 12 '14 at 14:10
  • does it require to stay running to work? or after setup I can keep it closed? – Aquarius Power Dec 12 '14 at 16:52
  • It should work either way. – Mitch Dec 12 '14 at 16:58
  • Wifi-radar link has moved, https://launchpad.net/ubuntu/+source/wifi-radar. – pbhj Nov 10 '15 at 23:46
  • @mirk To make the order of wifis permanent, I edited the configuration file located at /etc/wifi-radar.conf. The relevant setting is auto_profile_order, e.g. auto_profile_order = ['eduroam','my-home-network']. (This is wifi-radar version 2.0.s08; I think I've seen somewhere on web a comment implying that prior to version 2, the format was auto_profile_order = eduroam, my-home-network.) – Ansa211 Feb 02 '17 at 15:14
  • You do not listen: "I'm not interested in different network managers." is a clear statement NOT to mention weired external software stuff. The answer lacks respect for the requestor. – opinion_no9 Aug 17 '18 at 22:49
  • @opinion_no9 I appreciate the fact that your opinion might be valid, but try not to be condescending. Thanks – Mitch Aug 18 '18 at 06:49
  • Seems 2014+ use "NetworkManager" to accomplish this task instead of wifi-radar so...probably best not to install them both, then you'd have competing connectors... – rogerdpack Nov 10 '20 at 18:56
5

If you are using xfce, for instance under xubuntu 18.04, you can do this:

  • Go to the Wifi applet (upper right corner)
  • Click "Edit Connections"
  • Double-click the network of interest
  • Click on the "General" tab
  • Enter a value for "connection priority for auto-activation"

Positive numbers are higher priority; negative numbers are lower priority. The default priority seems to be 0, so I set the priority of the ubiquitous but not always working "xfinitywifi" to a negative number so that anything else connects first.

Confession: I only found this after considerable effort toward adding the feature myself. Which goes to show that drag and drop would probably be worth adding simply because it is more intuitive to discover, although there would have to be a reckoning about how to reconcile it with the default sort order, etc. A "priority" tab in the connection list could be the right place to expose that feature.

2

I carry around a mobile Wifi device (4G) and also use the mobile hotspot from my mobile (4G but different provider). When I'm at home or work I usually use the Wifi available there. But when things are slow I sometimes need to switch wifi to the mobile devices. Here's what I did to make it faster.

Set the priorities

  1. I ran nm-connection-editor from the terminal. That opens the 'Network Connections' application where you can set the priorities for the different Wifi access point you use.

enter image description here

  1. I changed the priorities so that the mobile Wifi devices are higher up in the order.

    • Mobile hotspot -> 100
    • Mobile Wifi device -> 90
    • Office Wifi -> 50
    • Home Wifi -> 40 , etc
  2. Now when I'm in office it's usually connected to Office Wifi, if it doesn't detected the mobile ones at startup. However in case I feel the Office network is slow and wish to connect to a mobile wifi, I simply run a shortcut (Ctrl+Alt+R) key with the below command:

    sh -c "nmcli r wifi off && nmcli r wifi on"

Create a shortcut key

  1. Open Settings > Devices > Keyboard Shortcuts

  2. Scroll down and click the plus (+) button at the bottom to add a new shortcut

  3. Give it a name, key combination (Ctrl+Alt+R in my case) and enter the below code in the Command field:

    sh -c "nmcli r wifi off && nmcli r wifi on"

This is a combination of two commands - first part turns off the wifi and the second part turns it back on. When it does this it connects you to the Wifi access point with the highest priority available.

enter image description here

  1. Save and you're done.

Now whenever you want to connect to a Wifi access point with a higher priority simply use the keyboard shortcut. Saves 5-6 clicks every time!