How to force the use of 5G band Wi-Fi on Mac

Author: gc (at) sysin.org, Home: www.sysin.org

Please visit the original link: < https://sysin.org/article/use-5ghz-wifi/> to view the latest version .

Scenes

In public Wi-Fi, the SSID is single (ie a network name), and there are multiple 2.4 Ghz and 5 Ghz BSSIDs (MAC address of an access point). If the 2.4Ghz signal is better, the Mac will actively connect to 2.4 On the Ghz network, the network freezes abnormally, possibly because there are a large number of public Wi-Fi devices that can only support the 2.4Ghz frequency band.

Apple rules: macOS will always default to the 5 GHz band instead of the 2.4 GHz band. The prerequisite is that the RSSI of the 5 GHz network is -68 dBm or better.

However, public Wi-Fi signals may not meet the requirements, which may result in preferential use of the 2.4 Ghz frequency band with a slightly stronger signal.

Use airporttools

The airport is located in the following path by default (currently 10.15 applies):

/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport

Create link:

# sudo mkdir -p /usr/local/bin
ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport

Note: You can also use alias and write environment variables.

aiprot command parameters

LEGACY COMMANDS:
Supported arguments:
 -c[<arg>] --channel=[<arg>]    Set arbitrary channel on the card
 -z        --disassociate       Disassociate from any network
 -I        --getinfo            Print current wireless status, e.g. signal info, BSSID, port type etc.
 -s[<arg>] --scan=[<arg>]       Perform a wireless broadcast scan.
                   Will perform a directed scan if the optional <arg> is provided
 -x        --xml                Print info as XML
 -P        --psk                Create PSK from specified pass phrase and SSID.
                   The following additional arguments must be specified with this command:
                                  --password=<arg>  Specify a WPA password
                                  --ssid=<arg>      Specify SSID when creating a PSK
 -h        --help               Show this help

As you can see, these commands have been identified by Apple as LEGACY COMMANDS (old version commands) and can be executed in the latest version of macOS.

In versions before OS X 10.6, you can directly use the airport command to connect to the specified BSSID:
airport --associate=XXX --bssid=YYY
where XXX is the SSID (network name), and YYY is the BSSID (MAC address).
This parameter is obsolete in OS X 10.6 and above.

solution

1. Scan the wireless network scan

$ airport -s
                            SSID BSSID             RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
                           aWiFi 80:f6:2e:b1:ca:85 -92  161,-1  Y  CN NONE
                        ChinaNet 80:f6:2e:b1:ca:80 -92  161,-1  Y  CN NONE
                       sysin.org a8:bd:27:75:b5:d0 -91  149     Y  CN NONE
                           aWiFi 80:f6:2e:d7:3f:c5 -90  161,-1  Y  CN NONE
                       sysin.org a8:bd:27:75:b7:50 -90  52      Y  CN NONE
                           aWiFi 80:f6:2e:b1:d4:85 -89  161,-1  Y  CN NONE
                        ChinaNet 80:f6:2e:b1:d4:80 -89  161,-1  Y  CN NONE
                        ChinaNet 80:f6:2e:d7:3f:c0 -89  161,-1  Y  CN NONE
                            TP5G b0:95:8e:af:d6:44 -88  149     Y  CN WPA(PSK/AES/AES) WPA2(PSK/AES/AES)
                       sysin.org a8:bd:27:75:ba:30 -87  52      Y  CN NONE
                       sysin.org a8:bd:27:75:d9:50 -84  36      Y  CN NONE
......

You can see the CHANNEL of multiple BSSIDs with the same SSID, the value greater than or equal to 36 is 5Ghz CHANNEL, record a 5Ghz CHANNEL number with the smallest RSSI.

You can use software such as WiFi Explorer Pro to view it more intuitively.

2. Turn off Wi-Fi

3. Set up CHANNEL

$ sudo airport --channel=36
# or
$ sudo airport -c=36

The frequency band bandwidth can be checked through third-party tools. The values ​​are usually: 20Mhz, 40Mhz (Wi-Fi 4), 80Mhz (Wi-Fi 5), 160Mhz (Wi-Fi 6)

You can add additional frequency band bandwidth parameters, for example, the frequency band is 44 and the frequency band bandwidth is 80Mhz, as follows:

$ sudo airport --channel=44,80
# or
$ sudo airport -c=44,80

Using Airtool to set Channel has the same effect as Chanel Width.

4. Turn on Wi-Fi and reconnect to the SSID

5. Check if the specified CHANNEL has been connected

Press the Alt key while clicking the Wi-Fi icon or execute the command:

$ airport -I

6. Turn off roaming

Apple rules: macOS clients will monitor and maintain the current BSSID connection until the RSSI crosses the -75 dBm threshold. When the RSSI crosses the threshold, macOS will scan the current ESSID to see if there are candidate roaming BSSIDs.

In an environment where the RSSI exceeds -75 dBm, consider turning off roaming to maintain a stable Wi-Fi connection.

$ sudo defaults write /Library/Preferences/com.apple.airport.opproam disabled -bool true

The plist file still exists in the current system version (10.15), but unfortunately, the relevant information shows that the plist file is only called by the 10.10 or 10.11 version system.

So the problem arises. If the current RSSI crosses the -75 dBm threshold, macOS may reconnect to the 2.4G band after scanning the network, and enter the endless loop of network instability. This is the author’s real experience, so this Article.

in conclusion

When the RSSI of macOS on the 5 GHz network is -68 dBm or better, the 5 GHz frequency band is always connected first by default, and the current BSSID RSSI does not exceed the -75 dBm threshold. The client will maintain a stable connection and no roaming will occur.

If the above conditions are not met, the airporttool cannot solve the problem.

There are two possible solutions at this time: one is to disable the 2.4Ghz frequency band of the wireless network card (it seems that there is no way to achieve it at the moment), and the other is to block the MAC address of the 2.4Ghz network locally (which can be achieved through iptables in Linux, and the one in BSD pf is realized by Tagging Ethernet Frames , macOS's pf cannot be directly applied, it is for further study).

Appendix: Explanation of terms

SSID : short for Service Set Identifier, service set identifier. SSID technology can divide a wireless local area network into several sub-networks that require different authentication. Each sub-network requires independent authentication. Only users who pass the authentication can enter the corresponding sub-network to prevent unauthorized users Enter this network. When we use computers and mobile phones to search for accessible networks, the network name displayed is the SSID.

BSSID : Basic Service Set Identifier (Basic Service Set Identifier) ​​refers to the MAC address of the station. The default BSSID is the MAC address of the corresponding network card (base MAC address). If an AP can support multiple SSIDs at the same time, the AP will assign different BSSIDs to correspond to these SSIDs. At this time, the BSSID is generated based on the base MAC address.

RSSI : RSSI (Received Signal Strength Indicator) is the strength indicator of the received signal. The most ideal situation is that the RSSI is 0 dBm (dBm: represents the absolute value of power, a ratio based on 1 mW power). But in actual situations, as long as the RSSI is greater than -50 dBm, the signal is very good; once the RSSI is less than -75 dBm, it may cause unstable transmission.

Guess you like

Origin blog.51cto.com/250823/2539793