From wikistone
Jump to: navigation, search
 
(2 intermediate revisions by the same user not shown)
Line 44: Line 44:
  
 
firewall-cmd --set-default-zone={zone}
 
firewall-cmd --set-default-zone={zone}
 +
 +
firewall-cmd --new-zone={zone} --permanent
  
 
firewall-cmd --zone={zone} --add-interface={ifname}
 
firewall-cmd --zone={zone} --add-interface={ifname}
Line 49: Line 51:
 
firewall-cmd --zone={zone} --remove-interface={ifname}
 
firewall-cmd --zone={zone} --remove-interface={ifname}
 
firewall-cmd --zone={zone} --query-interface={ifname}
 
firewall-cmd --zone={zone} --query-interface={ifname}
 +
 +
firewall-cmd --zone={zone} --add-source={a.b.c.d/cidr} --permanent
 
</pre>
 
</pre>
  
Line 91: Line 95:
 
Zones have one of 3 targets:
 
Zones have one of 3 targets:
 
* ACCEPT
 
* ACCEPT
−
* REJECT
+
* REJECT (default)
 
* DROP
 
* DROP
  

Latest revision as of 16:52, 6 December 2021

Quick Reference

Check State

firewall-cmd --state

or

systemctl status firewalld


Make Permanent

firewall-cmd --runtime-to-permanent

or

firewall-cmd --add-service=xxx --premanent

-note: Making a change with "permanent" is not immediately active.


Reset To Perm Rules

firewall-cmd --reload


List Stuff

firewall-cmd --list-all-zones
firewall-cmd --zone={zone} --list-all


Add / Remove Stuff

Add

firewall-cmd --add-service=
firewall-cmd --add-port= {n}/{tcp|udp}
firewall-cmd --add-protocol= {protocol name, eg: smb2}


Remove

firewall-cmd --remove ...


Zones

firewall-cmd --get-zones
firewall-cmd --get-active-zones

firewall-cmd --set-default-zone={zone}

firewall-cmd --new-zone={zone} --permanent

firewall-cmd --zone={zone} --add-interface={ifname}
firewall-cmd --zone={zone} --change-interface={ifname}
firewall-cmd --zone={zone} --remove-interface={ifname}
firewall-cmd --zone={zone} --query-interface={ifname}

firewall-cmd --zone={zone} --add-source={a.b.c.d/cidr} --permanent

Default Zone: If no zone is specified, the default zone is assumed.

To set a target zone for subsequent commands, declare a target zone:

firewall-cmd --set-target=DROP
firewalld-cmd --~blablabla~


Zones

From untrusted to trusted, the predefined zones are:

zone description
drop Packets dropped, no reply.
block Packets dropped, icmp-host-prohibited or icmp6-adm-prohibited sent.
public Only selected connections are accepted.
external Only selected connections are accepted.
dmz Only selected connections are accepted.
work Only selected connections are accepted.
home Only selected connections are accepted.
internal Only selected connections are accepted.
trusted All network connections are accepted.

Custom zones can be added. A default zone that's been customized becomes a custom zone. They will be defined here: /etc/firewalld/zones .


Zone Targets

Zones have one of 3 targets:

  • ACCEPT
  • REJECT (default)
  • DROP

Targets are used to accept, reject, or drop every packet that doesn’t match any rule (port, service, etc.).


Custom Services

Clone/add and edit here: /usr/lib/firewalld/services

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>SSH</short>
  <port protocol="tcp" port="22"/>
</service>


ICMP Inversion

What is blocked is allowed. What is allowed is blocked. Enable to allow all ICMP.

firewall-cmd --zone=drop --add-icmp-block-inversion --permanent


ICMP Stuff

firewall-cmd --get-icmptypes
firewall-cmd --info-icmptype=<icmptype>
firewall-cmd --query-icmp-block=<icmptype>
firewall-cmd --add-icmp-block=<icmptype>
firewall-cmd --remove-icmp-block=<icmptype>


ICMP Services

firewall-cmd --get-icmptypes

address-unreachable bad-header communication-prohibited destination-unreachable echo-reply echo-request fragmentation-needed host-precedence-violation host-prohibited host-redirect host-unknown host-unreachable ip-header-bad neighbour-advertisement neighbour-solicitation network-prohibited network-redirect network-unknown network-unreachable no-route packet-too-big parameter-problem port-unreachable precedence-cutoff protocol-unreachable redirect required-option-missing router-advertisement router-solicitation source-quench source-route-failed time-exceeded timestamp-reply timestamp-request tos-host-redirect tos-host-unreachable tos-network-redirect tos-network-unreachable ttl-zero-during-reassembly ttl-zero-during-transit unknown-header-type unknown-option


Masquerade & Forwarding

Forwarding requires masquerading being turned on!

Masquerading

firewall-cmd --add-masquerade
firewall-cmd --remove-masquerade
firewall-cmd --zone {zone} --query-masquerade


Port Forwarding

firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=12345 (-–permanent)


Port Forwarding To Other IP

firewall-cmd --zone=external --add-forward-port=port=22:proto=tcp:toport=10.1.2.3:12345 (--permanent)


Lockdown

Lockdown prevents changes to the firewall by services.

firewall-cmd --lockdown=on

Allowing services individually...

firewall-cmd --add-lockdown-whitelist-command='/usr/bin/python -Es /usr/bin/firewall-cmd*' (--permanent)


IP Sets

Files:

  • /usr/etc/firewalld/ipsets/ipset.xml
  • /usr/lib/firewalld/ipsets/ipset.xml

Example:

<?xml version="1.0" encoding="utf-8"?>
<ipset type="hash:ip">
  <short>My Ipset</short>
  <description>description</description>
  <entry>1.2.3.4</entry>
  <entry>1.2.3.5</entry>
  <entry>1.2.3.6</entry>
</ipset>
  • ipset : The mandatory ipset start and end tag defines the ipset. This tag can only be used once in a ipset configuration file. There is one mandatory and also optional attributes for ipsets:
    • type="string" : The mandatory type of the ipset. To get the list of supported types, use firewall-cmd --get-ipset-types.
    • version="string" : To give the ipset a version.
  • short : Is an optional start and end tag and is used to give an ipset a more readable name.
    • description : Is an optional start and end tag to have a description for a ipset.
  • option : Is an optional empty-element tag and can be used several times to have more than one option. Mostly all attributes of an option entry are mandatory:
    • name="string" : The mandatory option name string.
    • value="string" : The optional value of the option.
    • The supported options are:
      • family: "inet"|"inet6"
      • timeout: integer
      • hashsize: integer
      • maxelem: integer
  • entry : Is an optional start and end tag and can be used several times to have more than one entry entry. An entry entry does not have attributes.

Apply to a zone:

firewall-cmd --permanent --zone=drop --add-source=ipset:test


Shellness:

firewall-cmd --permanent --get-ipsets
firewall-cmd --permanent --new-ipset=test --type=hash:net
firewall-cmd --permanent --info-ipset=test
firewall-cmd --permanent --ipset=test --add-entry=192.168.0.1
firewall-cmd --permanent --ipset=test --add-entries-from-file=iplist.txt
firewall-cmd --permanent --ipset=test --remove-entries-from-file=iplist.txt


CONFIG

/etc/firewalld/firewalld.conf

DefaultZone=dmz


/etc/sysconfig/network-scripts/ifcfg-xxx

ZONE=public


Important Notes

firewalld does not depend on NetworkManager, but the use is recommended. If NetworkManager is not used, there are some limitations: firewalld will not get notified about network device renames. If firewalld gets started after the network is already up, the connections and manually created interfaces are not bound to a zone. They will have to be added manually.

Logging

Add logging rules right before reject and drop rules in the INPUT, FORWARD and OUTPUT chains for the default rules and also final reject and drop rules in zones. Possible values are: all, unicast, broadcast, multicast and off. Configure this in firewalld.conf with LogDenied=.