
Bir başka konumda temel Iptables kullanımı ile ilgili bilgi vermiştim. Iptables üzerinde çok işlem yapıyorsanız eğer, yeni IP adreslerine izin tanımlama farklı portlara izin tanımlama gibi, sürekli sürekli aynı komutları yazmak sıkıcı gelebilir. Aşağıdaki paylaştığım script ile bu işlemi kısa sürede halledebilirsiniz.
#!/bin/bash # Muhammed Niyazi ALPAY # https://niyazi.org function iptablesrules(){ echo "" echo "==========================================================" echo "" read -p "IP adreslerini aralarında virgül ile birlikte giriniz: " ipaddresses echo "" read -p "Port numaralarını aralarında virgül ile birlikte giriniz: " ports echo "" echo 0 > /proc/sys/net/ipv4/ip_forward iptables -A INPUT -p tcp -m multiport --dports $ports -s 127.0.0.1,$ipaddresses -j ACCEPT iptables -A INPUT -p udp -m multiport --dports $ports -s 127.0.0.1,$ipaddresses -j ACCEPT iptables -A INPUT -p tcp -m multiport --dports $ports -j DROP iptables -A INPUT -p udp -m multiport --dports $ports -j DROP echo 1 > /proc/sys/net/ipv4/ip_forward echo "" echo "==========================================================" echo "" echo "İşlem başarı ile tamamlandı." echo "" echo "==========================================================" echo "" } read -p "Önceki Iptables kuralları silinsin mi? (e ya da h) " removerule if [ ${removerule} == "e" ]; then echo "Iptables kuralları silindi" iptables --flush elif [ ${removerule} == "h" ]; then echo "" else echo "Lütfen e veya h olarak giriş yapın" fi iptablesrules condition_to_check="False" while [[ ${condition_to_check} == "False" ]]; do read -p "İşleme devam edilsin mi? (e ya da h) " query if [ ${query} == "h" ]; then condition_to_check="True" elif [ ${query} == "e" ]; then iptablesrules else echo "Lütfen e veya h olarak giriş yapın" fi done chkconfig iptables on service iptables save echo "" echo "===========