Requirements: Read IP addresses and port numbers from a file, open the IP and ports with Iptables
such as file content:
[email protected] huwei]# cat ip.txt192.168.66.20 22192.168.66.30 10050192.168.66.30 33
The manual action is:
[[email protected] huwei]# iptables-a input-s 192.168.66.20-i eth0-p tcp--dport 22-j ACCEPT
Overwrite the use of script to read the contents of the file, automatically add iptables firewall rules, the script is:
[email protected] huwei]# cat ip.sh#!/bin/shwan0= ' eth0 ' file= '/home/huwei/ip.txt ' while read idoa=$ (echo "$i" |awk-f " {print '} ') b=$ (echo "$i" |awk-f "{print $} ') #此处显示变量的值, you can omit echo" $a "echo" $b "iptables-a input-s $a-i $wan 0-p t CP--dport $b-j accept/etc/init.d/iptables savedone< $FILE
Soil approach, I think there should be a better way to achieve such a function
This article is from the "bottom 20,000" blog, please be sure to keep this source http://huwei555.blog.51cto.com/1347480/1787463
The shell gets the data from the file and assigns it to the variable