IP masquerading and port forwarding
Firewalld supports two types of network address translation
-
IP address camouflage (masquerade)
- LAN can achieve multiple addresses share a single public Internet address
- IP address masquerading only supports IPv4, IPv6 is not supported
- Address masquerading is enabled by default external area
- Port Forwarding (Forward-port)
- Also known as the destination address or port mapping
- Through port forwarding, specify the IP address and port traffic to be forwarded to a different port on the same computer, or transferred to a different port on the computer
Configuring address masquerading
- Add address masquerading as a designated area
firewall-cmd [--permanent] [--zone= zone] --add-masquerade [--timeout seconds]
//--timeout=seconds:在一段时间后自动删除该功能
- Delete address masquerading as a designated area
firewall-cmd [--permanent] [--zone= zone] --remove-masquerade
- Query whether to open a designated area address masquerading
firewall-cmd [--permanent] [--zone=zone] --query-masquerade
Port forwarding configuration
- Lists the port forwarding configuration
firewall-cmd [--permanent] [--zone=zone] --list-forward-ports
- Add port forwarding rules
firewall-cmd [--permanent] [--zone=zone] --add-forward-port=port=portid[-portid]:proto=protocol[:toport-portid[-portid]][:toaddr-address[/mask]][--timeout=seconds]
- Delete a port forwarding rule
firewall-cmd [--permanent] [--zone=zone] --remove-forward-port=port=portid[-portid]:proto=protocol[:toport=portid[-portid]][:toaddr=address[/mask]]
- Queries port forwarding rule
firewall-cmd [--permanent] [--zone=zone] --query-forward-port-port-portid[-portid]:proto=protocol[:toport-portid[-portid]][:toaddr=address[/mask]]
Firewalld direct rule
Direct rule (direct interface)
- It allows administrators to manually write iptables, ip6tables ebtables rules and inserted into Firewalld management area
- Achieved through firewall-cmd command --direct options
- In addition to the display means other than the insertion, priority matching rule directly
Custom rule chains
- Firewalld automatically configure the "rules of the area to create a custom rule chains
- IN area name deny: refuse storage statements, in preference to "IN area name rules _allow" of
- IN area name allow: storage permit statement
Allows TCP / 9000 inbound ports
irewall-cmd --direct --add-rule ipv4 filter IN work_ allow 0 -p tcp --dport 9000 j ACCEPT
- IN work_ allow: the chain rule matching work area
- 0: represents the highest priority rule, the rule is placed in front
- --Permanent option means you can increase the permanent configuration
Direct all inquiries rules
firewall-cmd --direct --get-all-rules
ipv4 filter IN_ work _allow 0 -p tcp --dport 9000 -j ACCEPT
- Can increase --permanent view option indicates that permanent configuration
Firewalld rich language rules
Rich language (rich language)
- Expressive configuration language, without knowing the syntax for iptables
- Essential for expression of allow / deny rules, configuration records (and for the auditd syslog), port forwarding, and rate limiting masquerading
rule [family="<rule family>"]
[ source address="<address>" [invert "True"] ]
[ destination address="<address>" [invert="True"] ]
[ <element> ]
[ log [prefix="<prefix text>"] [level="<log level>"] [limit value="rate/duration"] ]
[ audit ]
[ acceptlrejectldrop ]
Understand the rich command language rules
- firewall-cmd rich language processing rules commonly used options
Options | Explanation |
---|---|
-add-rich-rule= 'RULE' | RULE added to the designated area, if the area is not specified, or the default region |
--remove-rich-rule= 'RULE' | RULE deleted from the designated area, if the area is not specified, or the default region |
--query-rich-rule= 'RULE' | RULE whether the query has been added to the designated area, if the area is not specified, the default zone. <br/> rule exists, returns 0, otherwise 1 |
--list-rich-rules | All the rich rule specified area, if the area is not specified, the default zone |
Configured rich display language rules
- firewall-cmd --list-all
- firewall-cmd --list-all-zones
- --list-rich-rules
Rich language specific syntax rules
- source、destination、 element、 service、 port、 protocol、icmp-block、masquerade、 forward-port、 log、 audit、acceptlreject|drop
Reject all the traffic from 192.168.8.101
firewall-cmd --permanent --zone=work --add-rich-rule='rule family=ipv4 source address=192.168.8.101/32 reject'
- ddress options to the source or destination, must be family = ipv4 | ipv6
Fan set to accept 192.168.1.0/24 subnet port of TCP traffic 8000-9000
firewall-cmd --permanent --one=work --add-rich-rule='rule family=ipv4 source address=192.168.1.0/24 port port=8000-9000 protocol=tcp accept'
Discard all icmp packets
firewall-cmd --permanent --add-rich-rule='rule protocol value=icmp drop'
To accept traffic from http 192.168.8.1 and log
firewall-cmd --add-rich-rule='rule family=ipv4 source address=192.168.8.1/32 service name="http" log level=notice prefix= "NEW HTTP”limit value "3/s" accept'
- 192.168.8.1 to access the http, and watch / var / log / messages
Apr 16 17:09:55 Server kernel: NEW HTTP IN=ens33 OUT=
MAC=00:0c:29:69:01:c4:00:50:56:c0:00:08:08:00 SRC=192.168.8.1 DST=192.168.8.131
LEN=52 TOS=0xOO PREC=0x00 TTL =64 ID=20582 DF PROTO=TCP SPT=65289 DPT=80
WINDOW=8192 RES=0x00 SYN URGP=0
Apr 16 17:09:55 Server kernel: NEW HTTP IN=ens33 OUT=
MAC=00:0c:29:69:01:c4:00:50:56:c0:00:08:08:00 SRC=192.168.8.1 DST=192.168.8.131
LEN=52 TOS=0x0O PREC=0x0O TTL =64 ID=20590 DF PROTO=TCP SPT=65291 DPT=80
WINDOW=8192 RES=0x00 SYN URGP=0
Apr 16 17:09:55 Server kernel: NEW HTTP IN=ens33 OUT=
MAC=00:0c:29:69:01:c4:00:50:56:c0:00:08:08:00 SRC=192.168.8.1 DST=192.168.8.131
LEN=52 TOS=0x0O PREC=0x0O TTL =64 ID=20602 DF PROTO=TCP SPT=65292 DPT=80
WINDOW=8192 RES=0x00 SYN URGP=0