How do I set 5GHz as preferred band?

Solution 1:

To confirm that your wireless card is capable of connecting to 5ghz do iw list and look for the portion that looks like below

...
   Frequencies:
                * 5180 MHz [36] (22.0 dBm) (no IR)
                * 5200 MHz [40] (22.0 dBm) (no IR)
                * 5220 MHz [44] (22.0 dBm) (no IR)
                * 5240 MHz [48] (22.0 dBm) (no IR)
                * 5260 MHz [52] (20.0 dBm) (no IR, radar detection)
                * 5280 MHz [56] (20.0 dBm) (no IR, radar detection)
                * 5300 MHz [60] (20.0 dBm) (no IR, radar detection)
                * 5320 MHz [64] (20.0 dBm) (no IR, radar detection)
                * 5500 MHz [100] (22.0 dBm) (no IR, radar detection)
                * 5520 MHz [104] (22.0 dBm) (no IR, radar detection)
                * 5540 MHz [108] (22.0 dBm) (no IR, radar detection)
                * 5560 MHz [112] (22.0 dBm) (no IR, radar detection)
                * 5580 MHz [116] (22.0 dBm) (no IR, radar detection)
                * 5600 MHz [120] (22.0 dBm) (no IR, radar detection)
                * 5620 MHz [124] (22.0 dBm) (no IR, radar detection)
                * 5640 MHz [128] (22.0 dBm) (no IR, radar detection)
                * 5660 MHz [132] (22.0 dBm) (no IR, radar detection)
                * 5680 MHz [136] (22.0 dBm) (no IR, radar detection)
                * 5700 MHz [140] (22.0 dBm) (no IR, radar detection)
...

To answer your question, I am assuming the network card is capable of connecting to the 5ghz network. Using the command line interface is flexible compared to using the network manager gui. The important thing is to get the ssid and bssid of the 5ghz network you want to connect to.

sudo systemctl restart wpa_supplicant
sudo wpa_cli -iwlp2s0 scan_results

This would list some values such as

bssid / frequency / signal level / flags / ssid
    54:a2:74:03:c3:a2   2437    -79 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS]  \x00
    54:a2:74:03:c3:a0   2437    -79 [WPA2-EAP-CCMP][ESS]    SOME WIFI
    00:42:68:15:f0:92   2437    -90 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS]  \x00
    d8:b1:90:3e:e4:62   2412    -79 [WPA-PSK-CCMP][WPA2-PSK-CCMP][ESS]  \x00
    d8:b1:90:3e:e4:6e   5700    -84 [WPA2-EAP-CCMP][ESS]    DESIRED SSID
    54:a2:74:03:c6:a1   2462    -90 [WPA2-EAP-CCMP][ESS]    eduroam
    2a:a3:c4:8d:32:85   2437    -71 [WPA2-PSK-CCMP][WPS][ESS][P2P]  Another SSid
    54:a2:74:03:c6:ae   5500    -89 [WPA2-EAP-CCMP][ESS]    eduroam
    54:a2:74:03:c3:a1   2437    -73 [WPA2-EAP-CCMP][ESS]    eduroam
    00:42:68:15:f0:91   2437    -88 [WPA2-EAP-CCMP][ESS]    eduroam
    d8:b1:90:3e:e4:61   2412    -74 [WPA2-EAP-CCMP][ESS]    eduroam

Look for your desired ssid and the corresponding frequency. Now look for the BSSID that matches the desired frequency and SSID.

Next, kill network-manager and wpa_supplicant:

sudo service network-manager stop && sudo killall wpa_supplicant

This may not be desirable for most people but for the purposes of your question.

Create a wpa_supplicant.conf:

sudo nano /etc/wpa_supplicant.conf

and paste the network specs of the network you are connecting to:

ctrl_interface=/var/run/wpa_supplicant

#settings for an AP using preshared keys, PSK
network={
        ssid="DESIRED SSID"
        scan_ssid=1 
        key_mgmt=WPA-PSK
        psk="PassworD"
        bssid=d8:b1:90:3e:e4:6e   #the important part
}

#settings for an open AP. if you use this then don't use the above settings
network={
        ssid="DESIRED SSID"
        key_mgmt=NONE
        bssid=d8:b1:90:3e:e4:6e
}

Replace bssid with the one of the network you are connecting to

Now start wpa_supplicant via that conf file:

sudo wpa_supplicant -iwlp2s0 -c/etc/wpa_supplicant.conf

After authentication flush any held ip addresses:

sudo dhclient -r

Request a dynamic ip (dhcp):

sudo dhclient wlp2s0

At this point you should be connected to the 5ghz network.

To check whether you are really connected to the 5ghz but not the 2ghz do iw dev and you should have a results like

Interface wlp2s0
    ifindex 2
    wdev 0x1
    addr b4:6d:83:15:9c:5d
    ssid DESIRED SSID
    type managed
    channel 140 (5700 MHz), width: 20 MHz (no HT), center1: 5700 MHz
    txpower 22.00 dBm

The whole procedure above works well but may not survive a reboot and is not useful if you would want to be switching between different kinds of networks.
To start initialize network manage:

sudo service network-manager restart

Then from the network tray icon connect to your DESIRED SSID. Never mind whether it is 2.4 or 5ghz. we would do that later.

Now do:

sudo wpa_cli -iwlp2s0 scan_results

To get the BSSID that matches the desired frequency and ssid

Next click the network manager tray icon > edit connections > double click on the DESIRED SSID to edit it as following

On wifi tab: SSID (DESIRED SSID), mode (Client), band (5), channel (enter the value you got from the scan results), bssid (enter desired bssid) device (wlp1s0), cloned mac (permanent), mtu (automatic)

Then disconnect and connect again and it should work.