通过sed -i ,通过准备好的sh脚本,来设置linux iptable白名单
通过准备好的sh脚本,来设置linux iptable白名单
特定字符串的行前插入新行
sed -i '/特定字符串/i 新行字符串' file
#!/bin/bash del_stdin_buf() { read -d '' -t 0.1 } echo "Setting https enabled for remote access...." https_port=`grep 'dport 443' /etc/sysconfig/iptables | wc -l` if [ $https_port -eq 0 ] then sed -i "/-A INPUT -j REJECT --reject-with icmp-host-prohibited/i -A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT" /etc/sysconfig/iptables fi http_port=`grep 'dport 80' /etc/sysconfig/iptables | wc -l` if [ $http_port -eq 0 ] then sed -i "/-A INPUT -j REJECT --reject-with icmp-host-prohibited/i -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT" /etc/sysconfig/iptables fi
service iptables restart echo "Done."