Linux Firewalld usage and case


Dynamic firewall management tools
defining area and the security level interfaces
and runtime separate items permanently configured
two-layer structure
of the core layer and the back-end processing arrangement, such as iptables, ip6tables, ebtables, ipset and the loader module
top D-Bus configuration change and create a firewall Main way. All firewalld use this interface provides online tools
schematics


Firewalld with iptables contrast
firewalld is iptables front-end controller
iptables firewall static either policy changes need to reload all policies, loss of existing links
firewalld a dynamic firewall policy change does not require any reload all policies will change some iptables to save, not lose any existing link
firewalld a daemon service and use of the underlying iptables
based Netfilter kernel
configuration
firewall-config GUI
firewall-cmd command line tool
directly modify the configuration file
/ lib / firewalld alternate configuration for the default and
/ etc / firewalld for the user to create and custom configuration file override the default configuration
/etc/firewalld/firewall.conf global configuration
configuration and runtime permanently configured
firewall-cmd -zone = = smtp configured when run public -add-service, restart failure
firewall-cmd -permanent -zone = public -add-service = smtp permanent configuration, does not affect the current connection, to take effect after the restart
configuration is saved permanently configured firewall-cmd -runtime-to-permanent runtime
Zone
-Fi credible level, to many, a region a corresponding plurality of connecting
drop.xml repellent All connections
block.xml reject all connections
public.xml allow only specified connection * default region
external.xml allow only specified connection
dmz.xml allow only specified connection
work.xml allow only specified connection
home.xml allow only specified connection
internal.xml allow only specified connection
trusted.xml allows all connections
/ lib / firewalld / zones and a spare area default configuration
/ etc / firewalld / zones to create and customize a user profile overrides the default configuration area
<? xml version = "1.0 "encoding =" UTF-8 "?>
<Zone>
<Short> public </ Short>
<the Description> the For use in public Areas. by You do not Trust at The OTHER Computers ON Networks to not HARM YO
UR Computer. Only the Selected incoming Connections accepted are. </ Description>
<-Service name = "SSH" />
<-Service name = "Client-DHCPv6" />
</ Zone>
1
2
3
4
5
6
7
8
version="string" 版本
target="ACCEPT|%%REJECT%%|DROP" 默认REJECT 策略
short 名称
description 描述
interface 接口
name="string"
source 源地址
address="address[/mask]"
mac="MAC"
ipset="ipset"
service 服务
name="string"
port 端口
port="portid[-portid]"
protocol="tcp|udp"
protocol 协议
value="string"
icmp-block
name="string"
icmp-block-inversion
masquerade
forward-port
port="portid[-portid]"
protocol="tcp|udp"
to-port="portid[-portid]"
to-addr="address"
source-port
port="portid[-portid]"
protocol="tcp|udp"
rule
<rule [family="ipv4|ipv6"]>
[ <source address="address[/mask]" [invert="True"]/> ]
[ <destination address="address[/mask]" [invert="True"]/> ]
[
<service name="string"/> |
<port port="portid[-portid]" protocol="tcp|udp"/> |
<protocol value="protocol"/> |
<icmp-block name="icmptype"/> |
<masquerade/> |
<forward-port port="portid[-portid]" protocol="tcp|udp" [to-port="portid[-portid]"] [to-addr="address"]/> |
<source-port port="portid[-portid]" protocol="tcp|udp"/> |
]
[ <log [prefix="prefixtext"] [level="emerg|alert|crit|err|warn|notice|info|debug"]/> [<limit value="rate/duration"/>] </log> ]
[ <audit> [<limit value="rate/duration"/>] </audit> ]
[
<accept> [<limit value="rate/duration"/>] </accept> |
<reject [type="rejecttype"]> [<limit value="rate/duration"/>] </reject> |
<drop> [<limit value="rate/duration"/>] </drop> |
<mark set="mark[/mask]"> [<limit value="rate/duration"/>] </mark>
]
</rule>

rich rule
<rule [family="ipv4|ipv6"]>
<source address="address[/mask]" [invert="True"]/>
[ <log [prefix="prefixtext"] [level="emerg|alert|crit|err|warn|notice|info|debug"]/> [<limit value="rate/duration"/>] </log> ]
[ <audit> [<limit value="rate/duration"/>] </audit> ]
<accept> [<limit value="rate/duration"/>] </accept> |
<reject [type="rejecttype"]> [<limit value="rate/duration"/>] </reject> |
<drop> [<limit value="rate/duration"/>] </drop>
</rule>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
services
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>MySQL</short>
<description>MySQL Database Server</description>
<port protocol="tcp" port="3306"/>
</service>
1
2
3
4
5
6
version="string"
short
description
port
port="string"
protocol="string"
protocol
value="string"
source-port
port="string"
protocol="string"
module
name="string"
destination
ipv4="address[/mask]"
ipv6="address[/mask]"system is not IPSET default configuration file, the configuration file need to manually create IPSETIPSET configuration16151413 is12 is. 1110. 9. 8. 7. 6. 5. 4. 32
. 1

















mkdir -p /etc/firewalld/ipsets/mytest.xml mytest name is ipset
configuration templates provided by the official manual
<? xml Version = "1.0" encoding = "UTF-8"?>
<ipset of the type = "hash: NET" >
<Short> White-List </ Short>
<entry> 192.168.1.1 </ entry>
<entry> 192.168.1.2 </ entry>
<entry> 192.168.1.3 </ entry>
</ IPSET>
entry needs to be added is the IP address of the
firewall-cmd --get-ipsets display the current IPSET
Firewall-cmd --permanent --add-Rich-rule 'rule Family = "IPv4" Source IPSET = "mytest" = Port 80 Port Protocol TCP = Accept'Ipset applied to the policy
. 1
2
. 3
. 4
. 5
. 6
. 7
. 8
. 9
10
. 11
12 is
13 is
the service manager
yum -y install firewalld firewall-config # mounting firewalld
systemctl enable | disable firewalld # boot
systemctl start | stop | restart firewalld # start, stop, restart firewalld
If you want to use iptables to configure firewall rules, you must install iptables and disable firewalld
yum -y install iptables-install Services # iptables
systemctl enable iptables # boot
systemctl start | stop | restart iptables # start, stop, restart iptables
firewall-cmd commonly used commands
firewall-cmd --version View firewalld version
firewall-cmd --help to view the usage of firewall-cmd
man firewall-cmd
1
2
3
Firewall -cmd --state # View firewalld state
systemctl status firewalld # View firewalld state in detail
1
2
firewall-cmd --reload reload the firewall configuration, without interrupting the current connection
firewall-cmd --complete-reload reloads firewall configuration, the current connection is lost
1
2
firewall-cmd --get-services lists all the default service
firewall-cmd --list-services list the current service
firewall-cmd --permanent --zone = public --add -service = smtp service is enabled
firewall-cmd - -permanent --zone public --remove-service = smtp service disabled =
. 1
2
. 3
. 4
Firewall-cmd = --zone the ports public --list-
Firewall-cmd = --permanent --zone public --add-Port = 8080 / tcp port enabled
firewall-cmd --permanent --zone = public --remove -port = 8080 / tcp port disable
firewall-cmd --zone = "public" --add-forward-port = port = 80: proto = tcp: toport = 12345 server with port forwarding to forward port 80 to port 12345
firewall-cmd --zone = different server port forwarding public --add-masquerade, first opened Masquerade
firewall-cmd --zone = "public" - add-forward-port = port = 80: proto = tcp: toport = 8080: toaddr = 192.168.1.1 different server port forwarding, to 192.168.1.1 port 8080
. 1
2
. 3
. 4
. 5
. 6
Firewall-cmd --get-Zones view all available areas
firewall-cmd --get-active-zones currently active view region, and is currently assigned to them is provided with a list of interfaces
firewall-cmd --list -all-zones in all regions listed all configuration
firewall-cmd --zone = work --list- all list of all the specified domain configuration
firewall-cmd --get-default-zone area to view the default
firewall-cmd --set -default-zone = public default setting region
. 1
2
. 3
. 4
. 5
. 6
Firewall-cmd --get-zone-of-interface = eno222
Firewall-cmd [--zone = <zone>] --add-interface = <interface > add a network interface
firewall-cmd [--zone = <zone >] --change-interface = <interface> changes of network interface
firewall-cmd [--zone = <zone >] --remove-interface = <interface> delete Network Interface
firewall-cmd [--zone = <zone >] --query-interface = <interface> Network Interface Query
. 1
2
. 3
. 4
. 5
Firewall-cmd = Internal --permanent --zone --add-Source = 192.168.122.0 / 24 is provided to the network address of the designated area
firewall-cmd --permanent --zone = internal --remove -source = 192.168.122.0 / 24 network address deletion of the specified area
. 1
2
Firewall-cmd --get-icmptypes
. 1
the Rich rules
Firewall-cmd-Rich--list the rules all the rules listed in
firewall-cmd [-zone = zone] -query-rich-rule = 'rule' rule to check whether there is a
firewall-cmd [-zone = zone] -remove -rich-rule = 'rule' rule to remove a
firewall-cmd [-zone = zone] -add -rich-rule = 'rule' add a
complex rule configuration Examples
firewall-cmd --zone = public --add- rich-rule 'rule family = "ipv4" source address = 192.168.0.14 accept' allow all traffic from IPv4 hosts 192.168.0.14 of
firewall-cmd --zone = public - add-rich-rule 'rule family = "ipv4" source address = "192.168.1.10" port port = 22 protocol = tcp reject' reject from the IPv4 host 22 to 192.168.1.10 port TCP traffic
firewall-cmd --zone = public --add-rich-rule 'rule family = ipv4 source address = 10.1.0.3 forward-port port = 80 protocol = tcp to-port = 6532' Xu TCP traffic from IPv4 host 10.1.0.3 to 80 ports, and 6532 forwards the traffic to the port
firewall-cmd --zone = public --add- rich-rule 'rule family = ipv4 forward-port port = 80 protocol = tcp to-port = 8080 to-addr = 172.31.4.2' will 80 IPv4 host 172.31.4.2 traffic on port 8080 is forwarded to the port (on the area needs to be activated masquerade)
Firewall-cmd --add-Rich-rule = 'rule Family = "IPv4"source address = "192.168.122.0" accept 'allows all connections host 192.168.122.0/24
firewall-cmd --add-rich-rule = 'rule service name = ftp limit value = 2 / m accept' every two minutes to allow the new connection to access the ftp server
firewall-cmd --add-rich-rule = 'rule service name = ftp log limit value = "1 / m" audit accept ' agree to the new connection IPv4 and IPv6 FTP, and use the audit log every minute
firewall-cmd --add-rich-rule =' rule family = "ipv4" source address = "192.168.122.0/24" service name = ssh log prefix = "ssh" level = "notice" limit value = "3 / m" accept ' to allow new IPv4 address from 1192.168.122.0/24 TFTP connection service, and recording time per minute
firewall-cmd --permanent --add-rich- rule = 'rule protocol value = icmp drop' icmp packet discard all
firewall-cmd --add-rich-rule = 'rule family = ipv4 source address = 192.168 .122.0 / 24 reject '--timeout = 10 when using the specified source and destination addresses must be specified parameter family ipv4 or ipv6. If you specify a timeout, the rule will be activated within a specified number of seconds, and then be automatically removed
firewall-cmd --add-rich-rule = 'rule family = ipv6 source address = "2001: db8 :: / 64" service name = "dns" audit limit value = "1 / h" reject' --timeout = 300 reject all from 2001: host access dns service db8 :: / 64 subnet, and audit records only once per hour log
firewall-cmd --permanent --add-rich- rule = 'rule family = ipv4 source address = 192.168 .122.0 / 24 service name = ftp accept ' ftp service allows a host to access the network segment 192.168.122.0/24
firewall-cmd --add-rich-rule =' rule family = "ipv6" source address = "1: 2: 3: 4: 6 :: "forward -portto-addr =" 1 :: 2: 3: 4: 7 "to-port =" 4012 "protocol =" tcp "port =" 4011 " ' from the forwarding address 1 ipv6: 2: 3: 4: 6 :: TCP port 4011, to 1: 2: 3: 4:7 TCP port 4012
. 1
2
. 3
. 4
. 5
. 6
7
. 8
. 9
10
. 11
12 is
13 is
Direct Rules
firewall-cmd -direct -add-rule ipv4 filter IN_public_allow 0 -p tcp -dport 80 -j ACCEPT add rules
firewall-cmd -direct -remove-rule ipv4 filter IN_public_allow 10 -p tcp -dport 80 -j ACCEPT delete rules
firewall- cmd -direct -get-all-rules lists the rules
---------------------

Guess you like

Origin www.cnblogs.com/kcxg/p/11058668.html