[iptables] 设置固定IP 断网

#! /bin/bash

#
# drop some packets to simulate network traffic jam
# Zhang junpu, 12 09 2021
# 

ip_arr=($@)

# restore iptable rules
function clean_up()
{
    for i in ${ip_arr[*]}; do
        echo "[INFO] $i will be accpted"
        iptables -D OUTPUT -d $i -j DROP
    done
    echo "[INFO] main will quit"
    exit
}

function set_rules()
{
    for i in ${ip_arr[*]}; do
        echo "[INFO] $i will be droped"
        iptables -I OUTPUT -d $i -j DROP
    done
}

# user can use `ctrl-c' to exit the loop
trap clean_up SIGHUP SIGINT SIGTERM

set_rules

j=35
for ((i=1; i<=j; i++))
do
    sleep 1
    echo "[INFO] sleep for $i,$j"
done

clean_up

 

posted @ 2021-12-10 15:17  张浦  阅读(244)  评论(0编辑  收藏  举报