Jump to content

[SOLVED] Iptables


jaymc

Recommended Posts

I want to add a rule that applies to a list of IP addresses, for instance

 

-A INPUT -p tcp -m tcp -s "90.12.13.101,77.97.124.91" --dport 3306 -j ACCEPT

 

Comma separated values to define certain IP's would be good. Using the range feature is useless as these are internet IP addresses

 

Can this be done without adding the same rule for each IP address

 

Thanks

Link to comment
Share on other sites

Unforunately iptables will not accept a coma seperated list. If your using bash as your shell you could use an array.

 

ips=(90.12.13.101 77.97.124.91)
for index in $(seq 0 $((${#ips[@]} - 1))) ; do
  -A INPUT -p tcp -m tcp -s ${ips[$index]} --dport 3306 -j ACCEPT
done

Link to comment
Share on other sites

Im just editing /etc/sysconfig/iptables via SSH

 

Sorry, that file is distro specific. Has'nt ever existed on any of my systems (Debain / Gentoo).

 

Im assuming your example above will just generate the lines as in, in the raw conf file there will still be a line for each IP rule?

 

I think you'll find that raw config file is actually a shell script. Does it have a shebang at the top?

 

If it is (which it should be) you can write any shell scripting within it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.