1

executing

iptables -F

is very dangerous if your default policy for one or all chains is DROP

I would like to use an alias in bashrc like

alias iptables -F="echo \
'WARNING: due to the DROP default rule, flushing all rules would lock you out'"

but this does not work.

2

This should not work because of the space in your alias name.

You could call a custom function instead, in .bash_aliases :

#!/bin/bash

function myiptables {
 if [ $@ == "-F" ]
 then
   echo "WARNING: due to the DROP default rule, flushing all rules would lock you out"
 else
   command iptables "$@"
 fi
}

alias iptables='myiptables'

This will print the warning message if iptables argument is -F.

Otherwise, it will execute the normal iptables command, including all parameters you may have passed to it ($@).


command will run the real iptables command, preveting calling back your own function :

# help command
...
Runs COMMAND with ARGS suppressing shell function lookup, or display
information about the specified COMMANDs. Can be used to invoke commands
on disk when a function with the same name exists.
...
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.