вторник, 16 декабря 2014 г.

CentOS 7 и новый firewall

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Security_Guide/sec-Using_Firewalls.html#sec-Introduction_to_firewalld

По сути, это тот же iptables, но несколько в другом виде, в чём-то более логичном.
Из основных фич - релоад не рвёт соединения, хотя при аккуратной работе с iptables этого тоже можно было избежать. Но софт типа shorewall ТАК не умел, что в организациях на 200+ машин работало уныло. Теперь недоадминам, внедряющим такие поделки в большие сети, будет проще.

Пример разрешения http
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --reload

--permanent нужен, чтобы правила сохранялись после перезагрузки
--zone задаёт тип ограничений, может быть

drop
Any incoming network packets are dropped, there is no reply. Only outgoing network connections are possible.
block
Any incoming network connections are rejected with an icmp-host-prohibited message for IPv4 and icmp6-adm-prohibited for IPv6. Only network connections initiated from within the system are possible.
public
For use in public areas. You do not trust the other computers on the network to not harm your computer. Only selected incoming connections are accepted.
external
For use on external networks with masquerading enabled especially for routers. You do not trust the other computers on the network to not harm your computer. Only selected incoming connections are accepted.
dmz
For computers in your demilitarized zone that are publicly-accessible with limited access to your internal network. Only selected incoming connections are accepted.
work
For use in work areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.
home
For use in home areas. You mostly trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.
internal
For use on internal networks. You mostly trust the other computers on the networks to not harm your computer. Only selected incoming connections are accepted.
trusted
All network connections are accepted.

Также полезно заглянуть в
/usr/lib/firewalld/services
и найти там примеры уже готовых правил, класть в /etc/firewalld/services/

Ещё примеры полезных команд
# firewall-cmd --state
# firewall-cmd --list-all
# firewall-cmd --list-all-zones
# firewall-cmd --list-interfaces
# firewall-cmd --get-service
# firewall-cmd --query-service service_name
# firewall-cmd --add-port=8080/tcp
# firewall-cmd --permanent --get-services
#  firewall-cmd --permanent [--zone=<zone>] --add-forward-port=port=<port>[-<port>]:proto=<protocol> { :toport=<port>[-<port>] | :toaddr=<address> | :toport=<port>[-<port>]:toaddr=<address> }

Обращаю внимание: пока не сделан --reload, все эти list-all, state и проч -- показывают ТЕКУЩЕЕ состояние.

Поскольку это всё тот же iptables, там так же есть и модули. Текущие модули можно посмотреть тут:
/proc/net/ip_tables_matches 
Но как их использовать, пока непонятно. Вероятнее всего, надо писать своё правило в /etc/firewalld/services, а также посмотреть в сторону direct режима.

Примеры модулей

При желании заменить firewalld на iptables:
# systemctl disable firewalld
# systemctl stop firewalld
# yum install iptables-services
# systemctl start iptables
# systemctl start ip6tables
# systemctl enable iptables
# systemctl enable ip6tables

UPD: А ещё он иногда падает, открывая все порты в мир, и самостоятельно перезапускаться не способен никак.
Точную ошибку не помню, давно это было, но такое поведение было неприятным сюрпризом. Причём подобные случаи тогда гуглилились, сейчас не удалось найти.

И ещё линки

Комментариев нет:

Отправить комментарий