How Add Multiplle IP's to IPset?

sharingsunshine
sharingsunshine used Ask the Experts™
on
I had this question after viewing How Remove IP from IPset?.

How do I add a list of ip's to the ALLOW ipset?  Presently, they are in a text file single spaced separated by a return.  Here is a screenshot

https://gyazo.com/3ca73fc465513f6b9b09aa9104907d30

I have a similar list for ipv4's too.  Can both of them reside in the ALLOW subset?  If not, please tell me how to create one for ipv6.

Thanks,

Randal
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
nociSoftware Engineer
Distinguished Expert 2018

Commented:
an ipset is either IPv4 or IPv6 not both...
There are set for ip addresses (hash:ip) or networks (ip address or ipaddresses with netmasks,, hash:net).

ipset add SETNAME ipaddress
ipset add SETNAME ipaddress
etc.

Author

Commented:
so is there not a way to add a batch of ip's at one time?  Following your example will take a long time for 100's of ip numbers.
Software Engineer
Distinguished Expert 2018
Commented:
Like i said... if the hash:net is used you can add whole networks at once like:

ipset add SETNAME 192.168.1.0/23  # (for adding 192.168.0.0 - 192.168.1.255)....

if hash:ip has been chosen then yep you need 100 calls to add 100 addresses.

you could use a script that loads a file of ip address at one....   lets name it setbunch

#!/bin/bash
while read IP rem 
do
   ipset add SETNAME $IP
done

Open in new window


This could be called like:      bash setbunch <list-of-ip-addresses

Author

Commented:
thanks for the help

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial