Due to business needs, need to limit the server's outbound download, only in 00-17 points this time period in order to download resources, other times do not run out of the network download. So decided to use iptables to do a limit, this is the most simple prescription, nonsense not much to say, look at the script. #!/bin/bash re_log () { time=$ (date "+%Y%m%d %T") echo -e "[$Time] $1" >>/tmp/change_iptables.log } change_iptables () { from=$1 to=$2 echo "copy $from to $to ..." cp /etc/sysconfig/iptables /etc/sysconfig/iptables.bak cp -rf $from $to if [ $? -ge 1 ];then re_log "Copy $from to $to. failed. " else re_log "copy $from to $to. success. " fi # service iptables status | | service iptables start service iptables restart }limit () { change_iptables /root/ Workspace/iptables_drop /etc/sysconfig/iptables}open () { change_iptables /root/workspace/iptables /etc/sysconfig/iptables}case $1 in --limit|limit) limit ;; --open|open) open ;; *) echo "Usage: $0 limit|open" echo "Ex: $0 open" exit ;; Esac add_crond () { sed -i '/\/root\/workspace\/ iptables.sh/d ' /etc/crontab echo -e ' */5 18-23 * * * root /root/workspace/iptables.sh limit &>/dev/null " >>/etc/crontab echo -e "*/5 00-17 * * * root /root/workspace/iptables.sh open &>/dev/null " > >/etc/crontab }&Nbsp;add_crond
This article from "Born for Technology" blog, reproduced please contact the author!
Customizing server out-of-network updates