Commands for stopping and starting networking are :
sudo /etc/init.d/networking { stop | start }
sudo nmcli { networking | radio } { on | off }
Or for just one particular network interface :
sudo ifdown ethX
sudo ifup ethX
The last one may have a problem if your router is not in
/etc/sysconfig/network-scripts/route-ethX
, then it may not be completely deleted/added by the ifup/ifdown scripts.
For example, to delete you may also need to use :
route del default ethX
After launching firefox, to wait for it to finish you can use the
wait command
with or without parameters.
This is the script which worked for the poster :
nmcli radio wifi on
sleep 2
firefox
nmcli radio wifi off
Sleep is done with the number of seconds to wait before the network stabilizes,
empirically tested.
You should also ensure that the network is disabled after boot.
1Simplest way: write a script that wraps calling of X, adjusts networking before calling it, monitors X for termination, and adjusts networking back. Call script instead of X. Doesn't work if you plan to use several instances of X simultaneously. In case this is an XY question: If you want to give Firefox a different networking environment, you can also call it inside a network namespace that's properly set up. – dirkt – 2018-05-17T12:41:59.253
Thank you very much @dirkt! If you could write an example of script code as an answer, that would be it for me. I am using elementary OS, so my base is Ubuntu – ed0 – 2018-05-17T14:37:36.830