一,保存到文件
1,创建集合:
[root@blog ~]# ipset create myset hash:ip
添加ip:
[root@blog ~]# ipset add myset 192.168.1.100
[root@blog ~]# ipset add myset 192.168.1.101
[root@blog ~]# ipset add myset 192.168.1.102
查看集合信息:
[root@blog ~]# ipset list myset
Name: myset
Type: hash:ip
Revision: 4
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 264
References: 0
Number of entries: 3
Members:
192.168.1.100
192.168.1.102
192.168.1.101
2, 保存到文件:
[root@blog ~]# ipset save myset -f /root/ipset.myset.txt
查看文件内容:
[root@blog ~]# more /root/ipset.myset.txt
create myset hash:ip family inet hashsize 1024 maxelem 65536
add myset 192.168.1.100
add myset 192.168.1.102
add myset 192.168.1.101
二,从文件导入(集合不存在时)
1,删除集合:
[root@blog ~]# ipset destroy myset
查看集合信息:
[root@blog ~]# ipset list myset
ipset v7.1: The set with the given name does not exist
2,集合不存在时导入
[root@blog ~]# ipset restore -f /root/ipset.myset.txt
查看导入后的集合信息:
[root@blog ~]# ipset list myset
Name: myset
Type: hash:ip
Revision: 4
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 264
References: 0
Number of entries: 3
Members:
192.168.1.102
192.168.1.100
192.168.1.101
三,从文件导入(集合存在时)
1,清空集合
清空
[root@blog ~]# ipset flush myset
查看集合信息:
[root@blog ~]# ipset list myset
Name: myset
Type: hash:ip
Revision: 4
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 120
References: 0
Number of entries: 0
Members:
2,集合存在时导入:用-exist指明集合存在
[root@blog ~]# ipset restore -f /root/ipset.myset.txt -exist
查看导入后集合的信息:
[root@blog ~]# ipset list myset
Name: myset
Type: hash:ip
Revision: 4
Header: family inet hashsize 1024 maxelem 65536
Size in memory: 264
References: 0
Number of entries: 3
Members:
192.168.1.102
192.168.1.100
192.168.1.101
标签:ipset,myset,保存,192.168,blog,集合,root From: https://www.cnblogs.com/architectforest/p/18379506