Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm commanding a customarily built linux machine so not all linux commands are available. I execute network related commands so I need to set a default gateway right before I run my command, then remove that gateway. To do that I run all my commands in one line:

/sbin/route add default gw 10.10.10.10;my command;/sbin/route del default gw 10.10.10.10;

The problem is, for some reason I once found 2 default gateways on the same machine which caused all my commands to fail because even if I set my default gateway before running my test, its still messed up and can't run my test.

So is there a way to remove ALL default gateways in one command ? I have a large amount of machines that are increasing and it won't be practical to plant a script on every machine. I need a command as simple as the following:

/sbin/route del all default;set my default gw;mycommand;/sbin/route del all default;

I'll I have found so far is a command to remove a default gateway but not all of them /sbin/route del default which won't work for me.

/sbin/route help displays the following

/sbin/route --help

Usage: route [{add|del|delete}]

Edit the kernel's routing tables

Options:
        -n      Dont resolve names
        -e      Display other/more information
        -A inet Select address family

Thank you.

share|improve this question
3  
Stop using route, and use ip. BTW, how are they getting the default gateway. It seems silly to delete it, when you could simply fix the configuration and never set it in the first place. –  Zoredache Dec 20 '12 at 19:47
    
More than one default gw is configured to the same machine to test different networks. I followed your advice and I think this is the best solution so far. Using ip forces only one default gw to be configured and using the same command to delete the default gw without specifying it removes what's supposed to be the only gw. Thanks a lot. I'll consider this an answer if you post it as one. –  Muhammad Gelbana Dec 20 '12 at 20:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.