Я размещаю почтовый сервер (PostFix, PostFix Admin, Dovecot), сервер Minecraft и бот Discord, я пытаюсь создать брандмауэр с падением INPUT и OUTPUT, однако с этой конфигурацией все перестает работать, например, также с порт 143 открывает мой roundcube не может подключиться к серверу imap, то же самое для сервера minecraft, я загружаю порт 25565, но он останавливается на этом, и бот Discord не может подключиться к серверам Discord (должен быть http), а если я поставлю OUTPUT DROP просто остановите каждое соединение, а также мой ssh (настраиваемый порт 2233). Любая помощь?
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:imap2
ACCEPT udp -- anywhere anywhere udp dpt:1988
ACCEPT tcp -- anywhere anywhere tcp dpt:1988
ACCEPT tcp -- anywhere anywhere tcp dpt:http-alt
ACCEPT udp -- anywhere anywhere udp dpt:http-alt
ACCEPT tcp -- anywhere anywhere tcp dpt:8192
ACCEPT udp -- anywhere anywhere udp dpt:8192
f2b-sshd tcp -- anywhere anywhere multiport dports ssh
bungee tcp -- anywhere anywhere tcp dpt:25562
bungee tcp -- anywhere anywhere tcp dpt:25579
bungee tcp -- anywhere anywhere tcp dpt:25569
bungee tcp -- anywhere anywhere tcp dpt:25563
bungee tcp -- anywhere anywhere tcp dpt:25567
bungee tcp -- anywhere anywhere tcp dpt:41310
bungee tcp -- anywhere anywhere tcp dpt:41311
bungee tcp -- anywhere anywhere tcp dpt:41312
bungee tcp -- anywhere anywhere tcp dpt:25999
bungee tcp -- anywhere anywhere tcp dpt:25564
bungee tcp -- anywhere anywhere tcp dpt:30801
bungee tcp -- anywhere anywhere tcp dpt:30802
bungee tcp -- anywhere anywhere tcp dpt:30803
bungee tcp -- anywhere anywhere tcp dpt:30810
bungee tcp -- anywhere anywhere tcp dpt:25342
ACCEPT udp -- anywhere anywhere udp dpt:8183
ACCEPT udp -- anywhere anywhere udp dpt:8182
ACCEPT udp -- anywhere anywhere udp dpt:8181
ACCEPT udp -- anywhere anywhere udp dpt:8191
ACCEPT udp -- anywhere anywhere udp dpt:587
ACCEPT udp -- anywhere anywhere udp dpt:465
ACCEPT udp -- anywhere anywhere udp dpt:2233
ACCEPT udp -- anywhere anywhere udp dpt:25
ACCEPT udp -- anywhere anywhere udp dpt:143
ACCEPT udp -- anywhere anywhere udp dpt:993
ACCEPT tcp -- anywhere anywhere tcp dpt:imaps
ACCEPT tcp -- anywhere anywhere tcp dpt:imap2
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT tcp -- anywhere anywhere tcp dpt:http-alt
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:25565
ACCEPT tcp -- anywhere anywhere tcp dpt:submission
ACCEPT tcp -- anywhere anywhere tcp dpt:urd
ACCEPT tcp -- anywhere anywhere tcp dpt:8191
ACCEPT tcp -- anywhere anywhere tcp dpt:8183
ACCEPT tcp -- anywhere anywhere tcp dpt:8182
ACCEPT tcp -- anywhere anywhere tcp dpt:8181
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp
ACCEPT tcp -- anywhere anywhere tcp dpt:2233
ACCEPT tcp -- anywhere anywhere tcp dpt:imap2
ACCEPT tcp -- anywhere anywhere tcp dpt:8443
ACCEPT tcp -- anywhere anywhere tcp dpt:http-alt
ACCEPT tcp -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:2233
ACCEPT udp -- anywhere anywhere udp dpt:2233
ACCEPT udp -- anywhere anywhere udp dpt:25
ACCEPT udp -- anywhere anywhere udp dpt:143
ACCEPT tcp -- anywhere anywhere tcp dpt:imap2
ACCEPT tcp -- anywhere anywhere tcp dpt:25565
ACCEPT tcp -- anywhere anywhere tcp dpt:imaps
ACCEPT udp -- anywhere anywhere udp dpt:993
ACCEPT udp -- anywhere anywhere udp dpt:25565
ACCEPT tcp -- anywhere anywhere tcp dpt:urd
ACCEPT udp -- anywhere anywhere udp dpt:465
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:imap2 state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:imaps state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:urd state NEW,ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp dpt:submission state NEW,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:8183
ACCEPT udp -- anywhere anywhere udp dpt:8182
ACCEPT udp -- anywhere anywhere udp dpt:8181
ACCEPT udp -- anywhere anywhere udp dpt:8191
ACCEPT tcp -- anywhere anywhere tcp dpt:8191
ACCEPT tcp -- anywhere anywhere tcp dpt:8183
ACCEPT tcp -- anywhere anywhere tcp dpt:8182
ACCEPT tcp -- anywhere anywhere tcp dpt:8181
ACCEPT tcp -- anywhere anywhere tcp dpt:25565
ACCEPT udp -- anywhere anywhere udp dpt:25565
ACCEPT udp -- anywhere anywhere udp dpt:465
ACCEPT tcp -- anywhere anywhere tcp dpt:urd
ACCEPT tcp -- anywhere anywhere tcp dpt:imap2
ACCEPT udp -- anywhere anywhere udp dpt:143
ACCEPT udp -- anywhere anywhere udp dpt:993
ACCEPT tcp -- anywhere anywhere tcp dpt:imaps
ACCEPT tcp -- anywhere anywhere tcp dpt:2233
ACCEPT tcp -- anywhere anywhere tcp dpt:http-alt
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere tcp dpt:https
ACCEPT tcp -- anywhere anywhere tcp dpt:smtp
ACCEPT udp -- anywhere anywhere udp dpt:25
ACCEPT udp -- anywhere anywhere udp dpt:443
ACCEPT udp -- anywhere anywhere udp dpt:http-alt
ACCEPT udp -- anywhere anywhere udp dpt:80
ACCEPT udp -- anywhere anywhere udp dpt:2233
ACCEPT tcp -- anywhere anywhere tcp spt:smtp state ESTABLISHED
ACCEPT tcp -- anywhere anywhere tcp spt:imap2 state ESTABLISHED
Chain bungee (15 references)
target prot opt source destination
ACCEPT all -- vmi294204.contaboserver.net anywhere
ACCEPT all -- localhost anywhere
DROP all -- anywhere anywhere
Chain f2b-sshd (1 references)
target prot opt source destination
RETURN all -- anywhere anywhere
Вам не хватает некоторых стандартных правил брандмауэра, которые есть почти в каждом наборе правил:
iptables -I INPUT 1 -i lo -j ACCEPT
iptables -I INPUT 2 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
Вы, безусловно, хотите разрешить всю связь через устройство обратной связи (оно исходит от самого сервера) и разрешить каждое установленное соединение (вы уже принимали его один раз). Эти правила обычно применяются впервые по соображениям производительности.
В твоем OUTPUT
цепочка у вас все порты в неправильном направлении (--dport
вместо того --sport
).
это очень необычно установить DROP
так как OUTPUT
политики, и это требует хорошего знания того, как работают ваши службы и система.
Вы уже заметили пропавший ACCEPT
правило для ssh[*] и вы, вероятно, захотите добавить аналогичные правила в OUTPUT
как однажды я отдал за INPUT
. Однако вы не думали о разрешение имени:
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
и DHCP (если вы его используете). более того ICMP
почти обязательно:
iptables -A INPUT -p icmp -j ACCEPT
iptables -A OUTPUT -p icmp -j ACCEPT
поскольку он используется не только ping
, но дает важную диагностическую информацию, например «Нет маршрута к хосту». Без них ваши службы будут ждать до истечения тайм-аута каждый раз при возникновении сетевой ошибки.
PS: использовать multiport
и comment
модули, чтобы сделать ваши правила более читаемыми, например:
iptables -A INPUT -m multiport --dports smtp,465,submission -m comment --comment postfix -j ACCEPT
TL; DR: Переключение вашего OUTPUT
политика к DROP
не очень полезен и требует хорошего знания того, как работает каждый сервис, который вы используете.
[*] Перечитав вопрос, вы запускаете ssh на другом порту, и вы думали о разрешении пакетов возврата ssh, но вы использовали --dport
как и во всех остальных правилах. Я не понимаю, почему у вас fail2ban тюрьма для ssh на порту 22
если там ничего не слушает.