http://www.opennet.ru/tips/2926_iptables_firewalld_centos_rhel.shtml
Использование применяемой по умолчанию в RHEL/CentOS 7 надстройки Firewalld не всегда очевидно, поэтому бывает удобнее вернуться к классическим скриптам работы с пакетным фильтром.
Установим классические сервисы для работы с iptables:
yum install -y iptables-services
Настраиваем правила фильтрации в файлах /etc/sysconfig/iptables и /etc/sysconfig/iptables-config, например, можно сохранить текущие правила firewalld:
iptables-save > /etc/sysconfig/iptables
Завершаем работу firewalld и запускаем сервисы iptables:
systemctl stop firewalld && systemctl start iptables
Проверяем, что используются новые правила:
iptables -S
iptables -L
Для восстановления резервной копии типовых правил с другой машины можно воспользоваться командой iptables-restore:
cat iptables.backup| iptables-restore -t
service iptables save (или /usr/libexec/iptables/iptables.init save)
для возвращения настроек из /etc/sysconfig/iptables:
systemctl reload iptables
Если всё нормально — убираем активацию Firewalld при загрузке и запрещаем ручной запуск:
systemctl disable firewalld
systemctl mask firewalld
Активируем включение сервисов iptables при загрузке:
systemctl enable iptables
Комментарии
imen
#cid91172
Ответить
Очень характерно и показательно, что при этом не предлагается просто удалить ненужную надстройку.
imen
#cid92080
Ответить
Ещё характернее во-1) отсутствие демонстрации знания предмета (сколько таблиц ипстолов, из загружаемых НЯП 14 (!) сможет назвать автор статьи самостоятельно, не обращаясь к коллективному Разуму) и во-2) пропуск актуальной реализации пакетного фильтра (nftables, к декабрю 2015 года — уже достаточно актуальное решение).
imen
#cid92102
Ответить
Сравним умолчательное содержание упомянутого конфига (/etc/sysconfig/iptables, где он мне попадался, был вполне аналогичен):
$ cat /etc/sysconfig/iptables-config
# Load additional iptables modules (nat helpers)
# Default: -none-
# Space separated list of nat helpers (e.g. 'ip_nat_ftp ip_nat_irc'), which
# are loaded after the firewall rules are applied. Options for the helpers are
# stored in /etc/modprobe.conf.
IPTABLES_MODULES=""
# Unload modules on restart and stop
# Value: yes|no, default: yes
# This option has to be 'yes' to get to a sane state for a firewall
# restart or stop. Only set to 'no' if there are problems unloading netfilter
# modules.
IPTABLES_MODULES_UNLOAD="yes"
# Save current firewall rules on stop.
# Value: yes|no, default: no
# Saves all firewall rules to /etc/sysconfig/iptables if firewall gets stopped
# (e.g. on system shutdown).
IPTABLES_SAVE_ON_STOP="no"
# Save current firewall rules on restart.
# Value: yes|no, default: no
# Saves all firewall rules to /etc/sysconfig/iptables if firewall gets
# restarted.
IPTABLES_SAVE_ON_RESTART="no"
# Save (and restore) rule and chain counter.
# Value: yes|no, default: no
# Save counters for rules and chains to /etc/sysconfig/iptables if
# 'service iptables save' is called or on stop or restart if SAVE_ON_STOP or
# SAVE_ON_RESTART is enabled.
IPTABLES_SAVE_COUNTER="no"
# Numeric status output
# Value: yes|no, default: yes
# Print IP addresses and port numbers in numeric format in the status output.
IPTABLES_STATUS_NUMERIC="yes"
# Verbose status output
# Value: yes|no, default: yes
# Print info about the number of packets and bytes plus the "input-" and
# "outputdevice" in the status output.
IPTABLES_STATUS_VERBOSE="no"
# Status output with numbered lines
# Value: yes|no, default: yes
# Print a counter/number for every rule in the status output.
IPTABLES_STATUS_LINENUMBERS="yes"
# Reload sysctl settings on start and restart
# Default: -none-
# Space separated list of sysctl items which are to be reloaded on start.
# List items will be matched by fgrep.
#IPTABLES_SYSCTL_LOAD_LIST=".nf_conntrack .bridge-nf"
# Set wait option for iptables-restore calls in seconds
# Default: 600
# Set to 0 to deactivate the wait.
#IPTABLES_RESTORE_WAIT=600
# Set wait interval option for iptables-restore calls in microseconds
# Default: 1000000
# Set to 100000 to try to get the lock every 100000 microseconds, 10 times a
# second.
# Only usable with IPTABLES_RESTORE_WAIT > 0
#IPTABLES_RESTORE_WAIT_INTERVAL=1000000
И сравним с форматом его же, но использованного для хранения реальных правил:
$ cat /etc/sysconfig/iptables
# Generated by iptables-save v1.4.21 on Thu Oct 4 10:59:43 2018
*filter
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -s 192.168.100.0/24 -p icmp -j ACCEPT
-A INPUT -s 192.168.0.0/16 -p icmp -m limit --limit 4/sec -j ACCEPT
-A INPUT -s 192.168.100.0/24 -j ACCEPT
-A INPUT -s 192.168.100.0/24 -d 192.168.100.255/32 -p udp -m multiport --dports 137:139,445 -j DROP
-A INPUT -d 255.255.255.255/32 -p udp -m udp --sport 68 --dport 67 -j DROP
-A INPUT -j LOG --log-prefix "iptables "
-A INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
# Completed on Thu Oct 4 10:59:43 2018
Но самое здесь смешное то, что оно работает ☺