Network Related Scripts

Awesome thanks for the confirmation. Looks like a keeper.

Now I guess I need to do the other problematic dual module ath10k driver.

2 Likes

Sorry I just have an old beater laptop for your test...
I knew there was no risk, considering the source. :smile:
Cheers

2 Likes

Tested and this on wired, not wifi.

[sudo] password for pop: 
Not enough information: "dev" argument is required.
rmmod: ERROR: missing module name.
insmod /lib/modules/5.3.0-1-MANJARO/kernel/net/rfkill/rfkill.ko.xz 
insmod /lib/modules/5.3.0-1-MANJARO/kernel/net/wireless/cfg80211.ko.xz 
insmod /lib/modules/5.3.0-1-MANJARO/kernel/drivers/net/wireless/intel/iwlwifi/iwlwifi.ko.xz swcrypto=1 11n_disable=8 bt_coex_active=0 power_save=0 d0i3_disable=1 uapsd_disable=1
[pop@Dec ~]$ 


Network got deactivated and reactivated. No issues.
ps: missing module name : probably 5.3 kernel modules are incomplete. not sure.

Good job. Thanks.

ps: still wondering why networking is a hit and miss thing.
No such problem say, 1 year ago maybe. Any ideas?

I am tailoring individual scripts to the drivers I want to target. That script is specifically for the Intel iwlwifi modules. So it will not accomplish 100% of what it is intended to do unless you are using an iwlwifi based Intel wifi adapter.

It will still stop Network Manager, lower your adapter, raise your adapter, and then restart Network Manager. Which is often enough to kickstart most failed network connections. Oftentimes the modules must also be reloaded for the really stubborn cases to be initialized correctly. The scripts also add extra driver options to correct common driver issues.

Regarding your questions Goh.

The Intel wifi and ethernet firmware has been having a lot of issues over the last year. It seems to slowly be getting corrected, but is still a problem.

The realtek r8168 driver has been also causing no end of problems over the last year. That is a big issue because it is by far the most commonly used Ethernet adapter in consumer oriented laptops and desktops. The r8168 driver problems are finally starting to taper off because Manjaro has switched all new ISO's to default to the more stable r8169 kernel module.

2 Likes

OK, here's the Atheros ath10k wifi network restart version.

Any volunteers for testing this with an ath10k based wifi adapter?

nmcli networking off; sleep 1; sudo systemctl stop NetworkManager; sleep 1; DEVICE=$(hwinfo --wlan | grep "Device File" | cut -d " " -f5); sudo ip link set $DEVICE down; sudo rmmod -v ath10k_pci ath10k_core mac80211 cfg80211; sleep 20; sudo modprobe -v ath10k_core; sudo modprobe -v ath10k_pci nohwcrypt=1 skip_otp=y; sleep 2; sudo systemctl start NetworkManager; sleep 2; nmcli networking on; sleep 2; nmcli r wifi off; sleep 1; nmcli r wifi on

I'm pretty sure I have the modules in the correct order to unload & reload. Either way it is not an issue as it will merely throw an error if it wasn't right. Changes only last till the system is rebooted regardless.

Please give this a try if you have an Atheros ath10k based wifi adapter.

Please post the full input and output of the commands.

1 Like

it works fine on bash, with zsh it output every directory in /home .

from bash:

~ >>> bash                                                                                                                                                                                                         
[dglt@dglt-aw ~]$ nmcli networking off; sleep 1; sudo systemctl stop NetworkManager; sleep 1; DEVICE=$(hwinfo --wlan | grep "Device File" | cut -d " " -f5); sudo ip link set $DEVICE down; sudo lsmod | grep -o -e ^iwlmvm -e ^iwldvm -e ^iwlwifi | xargs sudo rmmod -v; sleep 1; sudo modprobe -vr mac80211; sleep 20; sudo modprobe -v iwlwifi swcrypto=1 11n_disable=8 bt_coex_active=0 power_save=0 d0i3_disable=1 uapsd_disable=1; sleep 2; sudo systemctl start NetworkManager; sleep 2; nmcli networking on; sleep 2; nmcli r wifi off; sleep 1; nmcli r wifi on
rmmod mac80211
rmmod libarc4
rmmod cfg80211
insmod /lib/modules/5.3.5-1-MANJARO/kernel/net/wireless/cfg80211.ko.xz 
insmod /lib/modules/5.3.5-1-MANJARO/kernel/drivers/net/wireless/intel/iwlwifi/iwlwifi.ko.xz swcrypto=1 11n_disable=8 bt_coex_active=0 power_save=0 d0i3_disable=1 uapsd_disable=1
[dglt@dglt-aw ~]$ ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=59 time=16.0 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=59 time=15.5 ms
64 bytes from 1.1.1.1: icmp_seq=3 ttl=59 time=13.3 ms
64 bytes from 1.1.1.1: icmp_seq=4 ttl=59 time=12.8 ms

a small section of errors from zsh:

grep: tmp: Is a directory
grep: Videos: Is a directory
grep: VirtualBox VMs: Is a directory
grep: WireGuard: Is a directory
rmmod: ERROR: Module Binary is not currently loaded
rmmod: ERROR: Module file is not currently loaded
rmmod: ERROR: Module 2019_08_11_120330_627x522_scrot is not currently loaded
rmmod: ERROR: Module matches is not currently loaded
rmmod: ERROR: Module Binary is not currently loaded
rmmod: ERROR: Module file is not currently loaded
rmmod: ERROR: Module 2019_10_05_095146_1920x1080_scrot is not currently loaded
rmmod: ERROR: Module matches is not currently loaded

it tries to unload directorie as if their modules :man_shrugging:

Maybe adding in the begining bash ; will suffice ?

i think it would have to be

bash -c "<command>"

aside from the not enough information "dev" error it seems to work fine from both bash and zsh if entered as this

~ >>> bash                                                                                                                                                                                                         
[dglt@dglt-aw ~]$ nmcli networking off; sleep 1; sudo systemctl stop NetworkManager; sleep 1; DEVICE=$(hwinfo --wlan | grep "Device File" | cut -d " " -f5); sudo ip link set $DEVICE down; sudo rmmod -v ath10k_pci ath10k_core mac80211 cfg80211; sleep 20; sudo modprobe -v ath10k_core; sudo modprobe -v ath10k_pci nohwcrypt=1 skip_otp=y; sleep 2; sudo systemctl start NetworkManager; sleep 2; nmcli networking on; sleep 2; nmcli r wifi off; sleep 1; nmcli r wifi on
rmmod: ERROR: Module mac80211 is in use by: iwlmvm
rmmod: ERROR: Module cfg80211 is in use by: iwlmvm ath iwlwifi mac80211
insmod /lib/modules/5.4.0-1-MANJARO/kernel/drivers/net/wireless/ath/ath10k/ath10k_core.ko.xz 
insmod /lib/modules/5.4.0-1-MANJARO/kernel/drivers/net/wireless/ath/ath10k/ath10k_pci.ko.xz nohwcrypt=1 skip_otp=y
[dglt@dglt-aw ~]$ exit
exit
~ >>> bash -c "nmcli networking off; sleep 1; sudo systemctl stop NetworkManager; sleep 1; DEVICE=$(hwinfo --wlan | grep "Device File" | cut -d " " -f5); sudo ip link set $DEVICE down; sudo rmmod -v ath10k_pci ath10k_core mac80211 cfg80211; sleep 20; sudo modprobe -v ath10k_core; sudo modprobe -v ath10k_pci nohwcrypt=1 skip_otp=y; sleep 2; sudo systemctl start NetworkManager; sleep 2; nmcli networking on; sleep 2; nmcli r wifi off; sleep 1; nmcli r wifi on"
Not enough information: "dev" argument is required.
rmmod: ERROR: Module mac80211 is in use by: iwlmvm
rmmod: ERROR: Module cfg80211 is in use by: iwlmvm ath iwlwifi mac80211
insmod /lib/modules/5.4.0-1-MANJARO/kernel/drivers/net/wireless/ath/ath10k/ath10k_core.ko.xz 
insmod /lib/modules/5.4.0-1-MANJARO/kernel/drivers/net/wireless/ath/ath10k/ath10k_pci.ko.xz nohwcrypt=1 skip_otp=y
~ >>>                                                                                                                                                                                                              
~ >>> bash                                                                                                                                                                                                         
[dglt@dglt-aw ~]$ bash -c "nmcli networking off; sleep 1; sudo systemctl stop NetworkManager; sleep 1; DEVICE=$(hwinfo --wlan | grep "Device File" | cut -d " " -f5); sudo ip link set $DEVICE down; sudo rmmod -v ath10k_pci ath10k_core mac80211 cfg80211; sleep 20; sudo modprobe -v ath10k_core; sudo modprobe -v ath10k_pci nohwcrypt=1 skip_otp=y; sleep 2; sudo systemctl start NetworkManager; sleep 2; nmcli networking on; sleep 2; nmcli r wifi off; sleep 1; nmcli r wifi on"
Not enough information: "dev" argument is required.
rmmod: ERROR: Module mac80211 is in use by: iwlmvm
rmmod: ERROR: Module cfg80211 is in use by: iwlmvm ath iwlwifi mac80211
insmod /lib/modules/5.4.0-1-MANJARO/kernel/drivers/net/wireless/ath/ath10k/ath10k_core.ko.xz 
insmod /lib/modules/5.4.0-1-MANJARO/kernel/drivers/net/wireless/ath/ath10k/ath10k_pci.ko.xz nohwcrypt=1 skip_otp=y
[dglt@dglt-aw ~]$ 
1 Like

Are you running this ^^^ command with an Atheros ath10k based adapter. Please post details (inxi -n).

Well that is rather bizarre. As I do not use zsh, I have no idea why that would be happening (if you are using the adapter driver the command is targeted for and the modules are installed).

I guess if you're encountering errors and you are running the proper adapter and module combination the commands are targeting (and receiving errors) that might be required.

I must say though that I have used these long multi commands for troubleshooting wifi in the past without errors before. However, in the past I was not using a variable to detect and raise/lower the wifi adapter.

It is not a big deal to preface "bash -c" as you suggest, and it may eliminate errors from alternate shells. I always forget about the alternate shells as I only use bash.

Very nice catch @dglt.

Thank you for your time to test this out.

2 Likes

no, iwlwifi

~ >>> inxi -n                                                                                           
Network:   Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet driver: r8169 
           IF: enp4s0 state: down mac: 20:47:47:72:37:62 
           Device-2: Intel Wireless 8265 / 8275 driver: iwlwifi 
           IF: wlp5s0 state: up mac: 20:16:b9:85:ec:33 

i remember running into small differences in how some grep commands behave differently on zsh than they do on bash. :man_shrugging:

1 Like

The error:

Not enough information: "dev" argument is required.

Is not returned on my system when using a root terminal .


OK, I figured out how to run the command so that the adapter is lowered/raised properly (without errors) when using a non-root terminal:

$ su -c 'nmcli networking off; sleep 1; systemctl stop NetworkManager; sleep 1; DEVICE=$(hwinfo --wlan | grep "Device File" | cut -d " " -f5) ; ip link set $DEVICE down; sleep 1; modprobe -vr 8812au; sleep 10; modprobe -v 8812au; sleep 2; ip link set $DEVICE up; sleep 2; systemctl start NetworkManager; sleep 2; nmcli networking on; sleep 1; nmcli r wifi off; sleep 1; nmcli r wifi on'
Password: 
rmmod 8812au
rmmod cfg80211
insmod /lib/modules/4.9.186-1-MANJARO/kernel/net/wireless/cfg80211.ko.gz cfg80211_disable_40mhz_24ghz=0 
insmod /lib/modules/4.9.186-1-MANJARO/kernel/drivers/net/wireless/8812au.ko.gz rtw_country_code=CA 

The question is how do I launch as root and ensure that bash is used as the shell. This seems to be non trivial?

1 Like

All fixed now.

Realtek 8812au:

su -c '/usr/bin/env bash -c echo "unloading network"; nmcli networking off; sleep 2; systemctl stop NetworkManager; sleep 2; DEVICE=$(hwinfo --wlan | grep "Device File" | cut -d " " -f5) ; ip link set $DEVICE down; echo -e "\n--- unloading network ---\n"; sleep 3; modprobe -vr 8812au; echo -e "\n--- restarting network ---\n"; sleep 5; modprobe -v 8812au; sleep 2; ip link set $DEVICE up; sleep 2; systemctl start NetworkManager; sleep 2; nmcli networking on; sleep 2; nmcli r wifi off; sleep 2; nmcli r wifi on; echo -e "\n--- operation completed ---\n"'
Password: 


--- unloading network ---

rmmod 8812au
rmmod cfg80211

--- restarting network ---

insmod /lib/modules/4.9.186-1-MANJARO/kernel/net/wireless/cfg80211.ko.gz cfg80211_disable_40mhz_24ghz=0 
insmod /lib/modules/4.9.186-1-MANJARO/kernel/drivers/net/wireless/8812au.ko.gz rtw_country_code=CA 

--- task completed ---

 htpc@htpc1 ~ 
4 Likes

I just completed the version for restarting an Intel iwlwifi based adapter. Anyone running an Intel wifi adapter using the iwlwifi driver please feel free to test this script and report on its results.

I do not own an iwlwifi based adapter, so I could not fully test this script. However, it is 100% safe as the changes are only of a temporary nature.

The script will restart your network, and will temporarily reset your iwlwifi driver options and may help improve your connectivity. The driver options are only temporary and they will be erased on a reboot (so there is no risk in running the command).

su -c '/usr/bin/env bash -c echo "unloading network"; nmcli networking off; sleep 1; systemctl stop NetworkManager; sleep 2; DEVICE=$(hwinfo --wlan | grep "Device File" | cut -d " " -f5); sudo ip link set $DEVICE down; echo -e "\n--- unloading network ---\n"; sleep 3; lsmod | grep -o -e ^iwlmvm -e ^iwldvm -e ^iwlwifi | xargs sudo rmmod; sleep 3; echo -e "\n--- restarting network ---\n"; sleep 3; modprobe -v iwlwifi swcrypto=1 11n_disable=8; sleep 3; ip link set $DEVICE up; sleep 2; systemctl start NetworkManager; sleep 2; nmcli networking on; sleep 2; nmcli r wifi off; sleep 2; nmcli r wifi on; echo -e "\n--- process completed ---\n"'

Please post your input, and output from the command.

1 Like

Have you thought of making the one-liners more readable with backslashes?

What a breakthrough!! :laughing:

I could do a ton of things to add extra features or make the process more understandable for those reading it. That's not what I'm looking for with the one liners though.

The one liners are for complete newbs that require lengthy explanations on how to create a script and make it executable. Scripting is just a pain to explain to newbs and it generally just drags out the entire troubleshooting process.

I don't need newbs to be able to read and understand the one liners. On the contrary, it's actually better that they don't see every thing contained in the script laid out in an easy to read format.

That only leads to newbs questioning the contents (as they get nervous when they see a bunch of stuff they don't understand). Again, this simply drags out the troubleshooting procedure.

A one liner that is mostly hidden from view is the quickest and easiest way to force feed commands to a newb that doesn't understand scripting.

For people that actually understand the commands, a script is far preferable. I could easily script things and add comments to make it all far more understandable. For troubleshooting purposes that's just not what I'm looking for though. I want something quick, that requires no user effort to create and has the least possibility of the user messing it up.

You've asked similar questions before with regards to my systemd units not using external scripts. The reason is to simplify everything for newbies as scripting is just a little over most Windows users heads.

I would love to explain it all on help threads, but then the process might be extended from hours to troubleshoot, into days. Quick and easy is what I want on newbie help threads.

3 Likes

That says it all!!
:rofl: ! :+1:

2 Likes

So I got confirmation from @dglt that the above iwlwifi restart script was fully functional. It does indeed properly load the extra driver options that may help some with connectivity issues.

I have also modified the network restart script with modified driver options for the ath10k based adapters as well.

Atheros ath10k restart script with improved connectivity options:

su -c '/usr/bin/env bash -c echo "unloading network"; nmcli networking off; sleep 1; systemctl stop NetworkManager; sleep 2; DEVICE=$(hwinfo --wlan | grep "Device File" | cut -d " " -f5) ; ip link set $DEVICE down; echo -e "\n--- unloading network ---\n"; sleep 2; rmmod -v ath10k_pci ath10k_core; echo -e "\n--- restarting network ---\n"; sleep 5; modprobe -v ath10k_core; sleep 2; modprobe -v ath10k_pci; sleep 2; ip link set $DEVICE up; sleep 2; systemctl start NetworkManager; sleep 2; nmcli networking on; sleep 2; nmcli r wifi off; sleep 2; nmcli r wifi on; echo -e "\n--- task completed ---\n"'

Any volunteers for testing this with an ath10k based Atheros wifi adapter?

Please post your input, and output from that command if you test it on the appropriate Atheros wifi card.

1 Like

Network Manager's MAC Address Randomization feature can often interfere with wifi connectivity. There is an easy one line command that can automatically create the required file in etc/NetworkManager/conf.d that will disable that feature.

Enter the following command in the terminal to automatically generate the required configuration file:

echo -e "[device]\nwifi.scan-rand-mac-address=no" | sudo tee /etc/NetworkManager/conf.d/disable-random-mac.conf

After creating the new conf file, reboot both your router and your computer.

The caveat on the one line commands is that they tend to grow if/when you add some checks, for example check an already existing file name in path,

[ ! -f /etc/NetworkManager/conf.d/disable-random-mac.conf ] && \
echo -e "[device]\nwifi.scan-rand-mac-address=no" | \
sudo tee /etc/NetworkManager/conf.d/disable-random-mac.conf

or check existing name=value, to change it.
:rofl: Sorry, I 've been affected by the dangerous bash-bash virus!! :face_with_thermometer:

You can add the append (-a) option if you are modifying a conf file that may contain other important settings. In this case the conf file has a rather unique name and a check should not be required.

If I'm modifying a file that may contain pre-existing options I will always use the append flag just to be sure I'm not wiping other important settings.

1 Like

Forum kindly sponsored by