используя firewalld и firewall-cmd, как добавить правило к основной цепочке INPUT, а не INPUT_direct

5048
Chris

поэтому, прочитав man-страницу firewalld и документацию fedora, я пришел к выводу, что для добавления настраиваемого правила в firewall с конкретными аргументами мне нужно использовать структуру

 firewall-cmd [--permanent] --direct --add-rule { ipv4 | ipv6 | eb } <table> <chain> <priority> <args> 

я специально пытаюсь создать собственное правило с сопоставлением геоипов, чтобы заблокировать все страны, которые не происходят из США. Прежде чем я сделаю это, мне нужно сначала добавить соответствующее правило, которое разрешает доступ из моей локальной сети, так как я управляю сервером через ssh в локальной частной сети, поэтому я добавляю правило примерно так

 firewall-cmd --direct --add-rule ipv4 filter INPUT 0 -s 192.168.0.0/24 -j ACCEPT 

Затем я добавляю второе правило так

 firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -m geoip ! --src-cc US -j DROP 

они добавляют в цепочку ввода, но добавляют в под-цепочку INPUT_direct, эта подцепь указана в общем списке неизмененных правил INPUT как 3-й и быстрый

 iptables -L INPUT 

показывает цепочку ввода как это

 Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere INPUT_direct all -- anywhere anywhere INPUT_ZONES_SOURCE all -- anywhere anywhere INPUT_ZONES all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere DROP all -- anywhere anywhere ctstate INVALID REJECT all -- anywhere anywhere reject-with icmp-host-prohibited 

и INPUT_direct как

 Chain INPUT_direct (1 references) target prot opt source destination ACCEPT all -- 192.168.0.0/24 anywhere DROP all -- anywhere anywhere -m geoip ! --source-country US 

это может работать для некоторых, но если я бегу

 ping france.fr 

Я получаю в результате

 PING france.fr (46.18.192.148) 56(84) bytes of data. 64 bytes from ns1-sgg.produhost.net (46.18.192.148): icmp_seq=1 ttl=52 time=136 ms 64 bytes from ns1-sgg.produhost.net (46.18.192.148): icmp_seq=2 ttl=52 time=135 ms 64 bytes from ns1-sgg.produhost.net (46.18.192.148): icmp_seq=3 ttl=52 time=136 ms 

это более чем вероятно из-за правила INPUT # 1

 iptables -L INPUT 1  ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED 

Я понимаю, что могу просто применить тот же пользовательский набор правил к цепочке OUTPUT и заблокировать ping-запрос к france.fr или к чему-то внешнему по отношению к США, но как я могу добавить этот набор правил в базовую цепочку INPUT, чтобы

 iptables -L INPUT 

показывает это вместо

 Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- 192.168.0.0/24 anywhere DROP all -- anywhere anywhere -m geoip ! --source-country US ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED ACCEPT all -- anywhere anywhere INPUT_direct all -- anywhere anywhere INPUT_ZONES_SOURCE all -- anywhere anywhere INPUT_ZONES all -- anywhere anywhere ACCEPT icmp -- anywhere anywhere DROP all -- anywhere anywhere ctstate INVALID REJECT all -- anywhere anywhere reject-with icmp-host-prohibited 

Я спрашиваю об этом, потому что чувствую, что хочу, а не то, что результат firewall-cmd немного более безопасен, я не прав? Я бы хотел, чтобы межсетевой экран контролировался firewalld, а не сбрасывал firewalld и возвращался к iptables для лучшей интеграции в будущем и возможных проблем с устареванием, поэтому возможно ли это даже с firewalld, или я буду вынужден запустить собственный сценарий в загрузиться, что включает в себя

 iptables -I INPUT 1 -s 192.168.0.0/24 -j ACCEPT iptables -I INPUT 2 -m geoip ! --src-cc US -j DROP 

и если это вариант, где я могу разместить этот скрипт?

1

1 ответ на вопрос

0
Chris

at the moment the best way to effectuate this is to just do exactly what i had proposed which is to not only add the incoming drop rule but also add the outgoing drop so the commands would be

 firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 0 -s 192.168.0.0/24 -j ACCEPT firewall-cmd --permanent --direct --add-rule ipv4 filter INPUT 1 -m geoip ! --src-cc US -j DROP firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT 0 -d 192.168.0.0/24 -j ACCEPT firewall-cmd --permanent --direct --add-rule ipv4 filter OUTPUT 1 -m geoip ! --dst-cc US -j DROP 

currently there is no other way to add the rule directly to the INPUT or OUTPUT chain through firewall-cmd

I only set out to do this like this because i felt that if some sort of worm or malware got inside my server its outgoing connection to whatever country would be considered RELATED, ASSURED, or ESTABLISHED, but this method by just adding to the delegate_output chain seems to be working to block all outgoing connections so I am satisfied

I am more than sure someone could better this answer by explaining how i could put the command in some init script or systemd script, but i think i would be more happy if fedora would just figure out an option that would add it directly to the primary chain, but maybe this is bad practice

Похожие вопросы