其实我是故意不写删除的部分的,因为管理的服务器只会加端口不会关。


=====================

#!bin/bash
while :
do

clear
echo "Detect open ports:"
echo -e "\033[33m`cat /etc/sysconfig/iptables | grep "dport" | cut -d ' ' -f 12`\033[0m"
echo "---------------------"
echo "Plase enter new port(Ctrl+c to Exit):"
read inport
#echo "---------------------"
#echo "Enter to Finish,Ctrl+c to Exit."
ilink=`grep -n "dport" /etc/sysconfig/iptables | tail -1 | cut -d ':' -f 1 `
#echo $ilink
#((ilink++))
t1="-A INPUT -m state --state NEW -m tcp -p tcp --dport"
t2="-j ACCEPT"
sed -i "${ilink}a ${t1} ${inport} ${t2}" /etc/sysconfig/iptables

done


===================================


后记:有空整理整理应该能够更合理一点,不过目前理解的就这么多了。