Firewalld and Iptables Flashcards
ip-table chains
Assume we have 2 if-s: eth0, eth1 on the PC
INPUT Chain: from outside to eth0
OUTPUT Chain: from eth0 outside
from eth0 to eth1 and visa versa: FORWARD
Add an entry into iptable to allow outgoing ssh traffic
iptables -I/A CHAIN [-i/o ifname] [-s/d ip-address] -p udp/tcp --dport/sport nn -j LOG/ACCEPT/DROP/REJECT A-append i/o -network card (eth0 or eth1) s-source address d-destination address dport/sport -dest port sport- source port nn -port number
iptables -A OUTPUT -p tcp –dport 22 -j ACCEPT
List iptables entries
iptables -L
Add policy into iptables
iptables -P INPUT DROP
iptables -P OUTPUT DROP
-P -policy OUTPUT
Add an entry into iptable to allow incoming traffic, when ssh connection was established with remote server
iptables -A INPUT -m state –state established,related -j ACCEPT
-m match
Firewalld
Zone: a collection of network cards to which rules can be assigned
Interfaces: individual network cards, always assigned to zones
Services: xml-based conf that specified ports to be opened and modules that should be used
Forward ports: used to send traffic coming in on specific port to another port, which may be on another machine
Masquerading: provides NAT
Reach rules: extension to firewalld to make more complex conf possible
Firewalld:
Show current conf
Show services of current zone (subset of –list-all command)
Get available services
firewall-cmd –list-all
firewall-cmd –list-services
firewall-cmd –get-services
Add service to run-time level rules
Remove service permanently
firewall-cmd -add-service=service
firewall-cmd –remove-service=service
firewall-cmd –add-service=https –permanent
Add GUI for firewalld
yum install firewall-config
Restart firewalld to pick up permanent rules
firewall-cmd –reload
Get zones
Get default zone
Get setting for home zone
firewall-cmd –get-zones
firewall-cmd –get-default-zone
firewall-cmd –zone=home –list-all
Get help for firewall
firewall-cmd –help
Add ip-range 192.168.0.0/24 to zone=home
firewall-cmd –zone=home –add-source 192.168.0.0/24
firewall-cmd –zone=home –add-source 192.168.0.0/24 –permanently
Run-time rules vs permanent rules
- Adding rules to run-time level does not survive reboot, but apply immediately
- Adding rules to permanent level requires reload of firewall-cmd to apply. Survive reboot
Enable firewall rules to get access to apache server
firewall-cmd –zone=public –add-port 80/tcp
firewall-cmd –zone=public –add-port 80/tcp –permanent