cn:ccr:formazione:centos7:2018-11:firewalld
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
cn:ccr:formazione:centos7:2018-11:firewalld [2018/11/29 10:40] – carbone@infn.it | cn:ccr:formazione:centos7:2018-11:firewalld [2018/11/29 10:41] (current) – [cpnfigure a zone to reject/drop a service] carbone@infn.it | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== firewalld ====== | ||
+ | suggested exercises. some suggestions are bare suggestions - no explanation at all 8-) | ||
+ | |||
+ | |||
+ | ==== change default zone ==== | ||
+ | ---- | ||
+ | |||
+ | |||
+ | ==== add/remove a service from a zone ==== | ||
+ | ---- | ||
+ | |||
+ | |||
+ | ==== create/ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | |||
+ | ==== configure a zone to reject/drop a service ==== | ||
+ | |||
+ | <code bash> | ||
+ | # firewall-cmd --zone=trusted --add-rich-rule=' | ||
+ | </ | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --add-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># cat / | ||
+ | <file xml> | ||
+ | <?xml version=" | ||
+ | < | ||
+ | < | ||
+ | <service name=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | |||
+ | ==== remove service reject/drop from a zone ==== | ||
+ | |||
+ | <code bash> | ||
+ | # firewall-cmd --zone=trusted --remove-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --remove-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># cat / | ||
+ | <file xml><? | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | |||
+ | ==== reject/drop an ip address ==== | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --add-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --add-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># cat / | ||
+ | <file xml><? | ||
+ | < | ||
+ | <rule family=" | ||
+ | <source address=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <code bash>$ iperf3 -c virtone.hmib.infn.it </ | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --remove-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --remove-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --add-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --add-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># cat / | ||
+ | <file xml>< | ||
+ | <rule family=" | ||
+ | <source address=" | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | <code bash>$ iperf3 -c virtone.hmib.infn.it </ | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --remove-rich-rule=' | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --zone=trusted --remove-rich-rule=' | ||
+ | < | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | ==== create an ipset ==== | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | ==== reject/drop globally a single ip address; defining a global black list ==== | ||
+ | |||
+ | <code bash> | ||
+ | # firewall-cmd --get-ipset-types </ | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --new-ipset=whitelist --type=hash: | ||
+ | < | ||
+ | Option can be used only with --permanent.</ | ||
+ | |||
+ | <code bash># firewall-cmd --permanent --new-ipset=blacklist --type=hash: | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --permanent --info-ipset=blacklist</ | ||
+ | < | ||
+ | type: hash:ip | ||
+ | options: family=inet | ||
+ | entries: </ | ||
+ | |||
+ | <code bash># firewall-cmd --permanent --ipset=blacklist --add-entry=192.168.100.70</ | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd --permanent --info-ipset=blacklist</ | ||
+ | < | ||
+ | type: hash:ip | ||
+ | options: family=inet | ||
+ | entries: 192.168.100.70</ | ||
+ | |||
+ | <code bash># firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 1 -m set --match-set blacklist src -j REJECT</ | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd | ||
+ | < | ||
+ | ipv4 filter INPUT 0 -p tcp -m multiport --dports ssh -m set --match-set fail2ban-sshd src -j REJECT --reject-with icmp-port-unreachable | ||
+ | ipv6 filter INPUT 1 -m tcp -p tcp --source 2001: | ||
+ | |||
+ | <code bash># firewall-cmd --reload</ | ||
+ | < | ||
+ | |||
+ | <code bash># firewall-cmd | ||
+ | < | ||
+ | ipv4 filter INPUT 2 -m set --match-set blacklist src -j REJECT | ||
+ | ipv4 filter INPUT 0 -p tcp -m multiport --dports ssh -m set --match-set fail2ban-sshd src -j REJECT --reject-with icmp-port-unreachable | ||
+ | ipv6 filter INPUT 1 -m tcp -p tcp --source 2001: | ||
+ | |||
+ | <code bash># iptables -t filter -L INPUT_direct</ | ||
+ | < | ||
+ | target | ||
+ | REJECT | ||
+ | ACCEPT | ||
+ | REJECT | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== defining a blacklist binding an ipset as a source to a zone ==== | ||
+ | |||
+ | < | ||
+ | # firewall-cmd --zone=block --add-source=ipset: | ||
+ | success | ||
+ | |||
+ | # firewall-cmd --info-zone=block (active) | ||
+ | target: %%REJECT%% | ||
+ | icmp-block-inversion: | ||
+ | interfaces: | ||
+ | sources: ipset: | ||
+ | services: | ||
+ | ports: | ||
+ | protocols: | ||
+ | masquerade: no | ||
+ | forward-ports: | ||
+ | source-ports: | ||
+ | icmp-blocks: | ||
+ | rich rules: | ||
+ | |||
+ | # firewall-cmd --ipset=blacklist --add-entry=192.168.100.70 | ||
+ | success | ||
+ | |||
+ | # firewall-cmd --info-ipset=blacklist | ||
+ | blacklist | ||
+ | type: hash:ip | ||
+ | options: family=inet | ||
+ | entries: 192.168.100.70 | ||
+ | |||
+ | # firewall-cmd --get-active-zones | ||
+ | trusted | ||
+ | interfaces: em2 | ||
+ | work | ||
+ | interfaces: em1 | ||
+ | netperf | ||
+ | sources: 212.189.204.0/ | ||
+ | block | ||
+ | sources: ipset: | ||
+ | mgmt | ||
+ | sources: 193.206.156.10/ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== reject/drop globally a network ==== | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== define a network global black list ==== | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | |||
+ | ==== create a firewall configuration ==== | ||
+ | requirements | ||
+ | * a management zone with access restricted to a few hosts | ||
+ | * a zone providing auth services (ldap, kerberos) to a list of hosts/ | ||
+ | * a public zone providing http/https services | ||
+ | * a global blacklist | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ==== create a masquerading firewall ==== | ||
+ | ---- | ||
+ | |||
+ | ==== blacklist a port (or a host) in the trusted zone ==== | ||
+ | ---- |