3
I'd like to write a bash/shell script that "turns off" the machine's ability to communicate over it's network card, effectively shutting down all networking. From the command line:
# To turn all networking off
sh networking.sh OFF
# Then to turn it back on
sh networking.sh ON
The only way I can think of doing this would be at the port-level via IPTABLES
, but having never experimented with that before, I'm not sure if I'm even heading down the right avenue or if I'm way off base. Thanks in advance.
1If you have aq simply setup then this would bring all ethernet devices down.
for n in ifconfig -a | grep eth | cut -d ' ' -f 1
; do bringing down echo $n ; ifconfig $a down ; done (ifconfig -a showing all devices. Grep filters down to lines containing eth. Cut first field (separated by spaces). And for to loop through all the answers. Kludgy, but works. – Hennes – 2012-12-23T22:12:56.760Thanks @Hennes (+1) - can you explain what "aq" is? Also this would work for ethernet devices, but what if the machine has a Wifi adaptor? Is there a solution that works for both wired/wireless?!? I would imagine that both use ports, which is why I had started looking into
IPTABLES
. Thanks again! – pnongrata – 2012-12-23T22:15:23.443On GNU/Linux all Ethernet devices seem to be named to ethX (with X starting at 0 for the first, 1 for the second device, 3 for the third, ...). I think that this includes wireless. However note that this is only to bring things down via ifconfig. Ifconfig is used on almost all unices but Linux seems to be moving away from it to a 'new' tool called 'ip'. Also not that while it will work for bringing the network DOWN you want a better answer to bring things up again. – Hennes – 2012-12-23T22:17:49.913
s/aq/a (I need to explain that it was a typo so my text is 15 char or longer) – Hennes – 2012-12-23T22:18:41.990
Thanks again @Hennes - how about trickle? It looks like I could just run
– pnongrata – 2012-12-23T22:27:58.220trickled
(trickle daemon) with up/download bandwidths set to0
. My only question is: how do I restore the up/download bandwidths when I want to bring the network back "up"?!?All ethernet device on linux are not named
ethx
. Wifi connections arewlanx
for example, dsl (or pppoe) arepppx
, bridged nics arebrx
and so on. Anyways, there are command specific to manage networking that are more practical ;) – laurent – 2012-12-23T22:44:34.613