执行
iptables -F
是非常危险的,如果您的一个或所有链条的默认政策是DROP
alias iptables -F="echo \ 'WARNING: due to the DROP default rule, flushing all rules would lock you out'"
但是这不起作用。
这不应该因为别名的空间而起作用。
您可以调用一个自定义函数,在.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'
如果iptables参数是-F这将打印警告消息。
否则,它将执行正常的iptables命令,包括可能传递给它的所有参数( $@ )。
command将运行真正的iptables命令,预先呼叫回自己的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. ...