Sunday, March 7, 2021

ssh keeps disconnecting from the Ubuntu server(in the same LAN) which is on USB WIFI adapter

Symptom:

I use Macbook to ssh to an Ubuntu server(in the same LAN) which is on USB WiFi adapter.

  1. The ssh connection keeps disconnecting after being idle for random time.
  2. Pinging to that Ubuntu Server will timeout.  After a while, the connection will recover itself.
  3. Even though both Macbook and Ubuntu Server are in the same LAN, "ping" response time is normally more than 100+ ms. 
  4. On Macbook, the ARP cache for Ubuntu server may disappear or being "Incomplete" meaning no reply to that ARP request.
  5. On Ubuntu server, the /var/log/syslog prints lot of logs saying going into power saving mode:
RTW: rtw_set_ps_mode(wlx000000000000) Enter 802.11 power save - WIFI-TRAFFIC_IDLE

I have tried below methods which may help in some degree but none of them completely resolved the issue:

  • a. Use static ARP cache on Macbook. (arp -s <Ubuntu IP> <Ubuntu Mac>)
  • b. Change Router to assign static IP address for Mac and Ubuntu server.
  • c. On Ubuntu server, create a cronjob to ping some websites periodically.
  • d. On Ubuntu server, create a cronjob to use Unsolicited ARP mode to update neighbours' ARP caches. (arping -U ...)

Env:

Ubuntu 18.04

WIFI adapter using Realtek RTL88x2BU driver

Solution:

Eventually found this discussion and tried the suggested method out.

In above discussion, they were using RTL8192eu driver but the parameters are the same for RTL88x2BU driver. We just need to make sure the file name and content is correct based on the driver name.

1. Double confirm the driver name

$  lsusb -t |grep -i rtl
|__ Port x: Dev x, If 0, Class=Vendor Specific Class, Driver=rtl88x2bu, 480M

And also below command can double confirm the module name and driver name match:

modinfo 88x2bu

Of course, when you were installing this driver, you should use some command as below which also confirms the driver name and version:

sudo dkms install -m rtl88x2bu -v x.y.z

2.  Create(if not exsit) the module configuration file /etc/modprobe.d/88x2bu.conf with below content.

options 88x2bu rtw_power_mgnt=0 rtw_enusbss=0 rtw_ips_mode=0 rtw_drv_log_level=2

Now let's try to understand those parameters by using the github source code which is provided by the WIFI adapter vendor. But you can easily search the different versions of the source code for RTL88x2BU driver because at least the parameters are the same.

  • rtw_power_mgnt=0: Disable power management mode.
  • rtw_enusbss=0: Disable USB auto-suspend.
  • rtw_ips_mode=0: Disable IPC mode.
  • rtw_drv_log_level=2: Log level is set to ERROR which can reduce the /var/log/syslog pressure.

3. Reboot Ubuntu Server

4. Check the connection and let Ubuntu server be idle

I kept pinging Ubuntu server for more than 1 hour,  and no any "ping" timeout.

And the ping response time is now reduced at 5 ms level.

Further more, not many /var/log/syslog entries are generated by the driver.


 

 

No comments:

Post a Comment

Popular Posts