<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    I cannot take credit. <br>
    <br>
    My thanks to Anthony, Thomas, and Jiri
    on this list for their help.<br>
    <br>
    I just worked out the kinks for my particular use.<br>
    <br>
    Here are what I use:<br>
    <blockquote>/etc/firewalld/direct.xml (from Anthony)<br>
      <blockquote>&lt;!-- /etc/firewalld/direct.xml --&gt;<br>
        &lt;direct&gt;<br>
          &lt;!-- IPset Blacklisting --&gt;<br>
          &lt;chain ipv="ipv4" table="raw"
        chain="PREROUTING_blacklist"/&gt;<br>
          &lt;passthrough ipv="ipv4"&gt;-t raw -A PREROUTING_blacklist
        -m limit --limit 3/min -j LOG --log-prefix BLACKLIST_DROP:
        --log-level 6&lt;/passthrough&gt;<br>
          &lt;passthrough ipv="ipv4"&gt;-t raw -A PREROUTING_blacklist
        -j DROP&lt;/passthrough&gt;<br>
          &lt;passthrough ipv="ipv4"&gt;-t raw -A PREROUTING -m set
        --match-set blacklist src -j
        PREROUTING_blacklist&lt;/passthrough&gt;<br>
          &lt;chain ipv="ipv6" table="raw"
        chain="PREROUTING_blacklist"/&gt;<br>
          &lt;passthrough ipv="ipv6"&gt;-t raw -A PREROUTING_blacklist
        -m limit --limit 3/min -j LOG --log-prefix BLACKLIST_DROP:
        --log-level 6&lt;/passthrough&gt;<br>
          &lt;passthrough ipv="ipv6"&gt;-t raw -A PREROUTING_blacklist
        -j DROP&lt;/passthrough&gt;<br>
          &lt;passthrough ipv="ipv6"&gt;-t raw -A PREROUTING -m set
        --match-set blacklist src -j
        PREROUTING_blacklist&lt;/passthrough&gt;<br>
        &lt;/direct&gt;<br>
      </blockquote>
      /etc/systemd/system/ipset.service (from Anthony)<br>
      <blockquote>Description=ipset - IP set restore &amp; save<br>
        Documentation=<a class="moz-txt-link-freetext" href="man:ipset(8)">man:ipset(8)</a><br>
        Before=network.target firewalld.service iptables.service
        ip6tables.service<br>
        ConditionFileNotEmpty=/etc/sysconfig/ipset.save<br>
        <br>
        [Service]<br>
        Type=oneshot<br>
        ExecStart=/usr/sbin/ipset -exist -file /etc/sysconfig/ipset.save
        restore<br>
        ExecStop=/usr/sbin/ipset -file /etc/sysconfig/ipset.save save<br>
        RemainAfterExit=yes<br>
        StandardOutput=journal+console<br>
        UMask=0177<br>
        <br>
        [Install]<br>
        WantedBy=basic.target<br>
      </blockquote>
      This is from the email from Anthony:<br>
      <blockquote>
        <pre wrap="">The way I did this was to create a minimal ipset configuration and execute
'/usr/sbin/ipset -file /etc/sysconfig/ipset.save save' -- so the rules are 
stored in /etc/sysconfig/ipset.save prior to enabling ipset.service

My initial ipset.save without any ip addresses added looks like:

create blacklist_ipv6 hash:net family inet6 hashsize 1024 maxelem 65536 
create blacklist_ipv4 hash:net family inet hashsize 1024 maxelem 65536 
create blacklist list:set size 8 
add blacklist blacklist_ipv4
add blacklist blacklist_ipv6

Then do 'systemctl enable ipset &amp;&amp; systemctl start ipset'

Together, the additions to the direct.xml configuration and the ipset.service 
have allowed me to add or remove ip addresses from the blacklist without the 
worry of what happens upon restart, etc.
</pre>
      </blockquote>
    </blockquote>
    My own ipset save file is a bit more complex:<br>
    <blockquote>create blacklist_ipv4_permanent hash:ip family inet
      hashsize 4096 maxelem 65536 <br>
      create blacklist_ipv4_semipermanent hash:ip family inet hashsize
      4096 maxelem 65536 <br>
      create blacklist_ipv4_current hash:ip family inet hashsize 4096
      maxelem 65536 <br>
      create blacklist_ipv6_permanent hash:ip family inet6 hashsize 4096
      maxelem 65536 <br>
      create blacklist_ipv6_semipermanent hash:ip family inet6 hashsize
      4096 maxelem 65536 <br>
      create blacklist_ipv6_current hash:ip family inet6 hashsize 4096
      maxelem 65536 <br>
      create blacklist list:set size 8 <br>
      add blacklist blacklist_ipv4_permanent<br>
      add blacklist blacklist_ipv4_semipermanent<br>
      add blacklist blacklist_ipv4_current<br>
      add blacklist blacklist_ipv6_permanent<br>
      add blacklist blacklist_ipv6_semipermanent<br>
      add blacklist blacklist_ipv6_current<br>
    </blockquote>
    It is up to you how you want to add IPs to the ipsets.<br>
    <br>
    I have another script that runs periodically to parse various log
    files to determine IPs to blacklist and add them to
    blacklist_ipv4_current. Once a day, the script reads IPs that are in
    the current list and which have been in historical lists of
    'current' IPs and adds them to semipermanent or discards them if
    not. Does the same for historical semipermanent and adds them to
    permanent. It keeps the firewall up to date with 'bad guys.' That
    script is pretty complex and I'd rather not post it. I am not
    working with IPv6 to any extent yet.<br>
    <br>
    I currently have 8616 IPs in my blacklist.<br>
    <br>
    Nathanael, Hope this helps you and others.<br>
    <br>
    John<br>
    <br>
    <div class="moz-cite-prefix">On 07/16/2014 01:46 PM, Nathanael d.
      Noblet wrote:<br>
    </div>
    <blockquote cite="mid:1405532761.3052.2.camel@mobile.noblet.ca"
      type="cite">
      <pre wrap="">Hello John,

  Once you have this working, would you mind posting your config/scripts
for others to benefit from? I'd like to use ipsets as well but haven't
had a chance to look deeply into them. Your setup sounds like it would
be a great start.

</pre>
    </blockquote>
    <br>
  </body>
</html>