Iptables - как заблокировать порт

Материал из Wiki - Iphoster - the best ever hosting and support. 2005 - 2023
Версия от 09:13, 12 сентября 2019; Admin iph (обсуждение | вклад) (Новая страница: « Пример для CentOS 6 - как заблокировать 25 порт на сервере: # iptables -A INPUT -p tcp --dport 25 -j DROP # iptables -A …»)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к:навигация, поиск


Пример для CentOS 6 - как заблокировать 25 порт на сервере:

# iptables -A INPUT -p tcp --dport 25 -j DROP
# iptables -A OUTPUT -p tcp --dport 25 -j DROP
# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]


В таблице видим:

# iptables -L
Chain INPUT (policy ACCEPT)
DROP       tcp  --  anywhere             anywhere            tcp dpt:smtp
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
DROP       tcp  --  anywhere             anywhere            tcp dpt:smtp


Одной строкой для CentOS 6:

iptables -A INPUT -p tcp --dport 25 -j DROP &&  iptables -A OUTPUT -p tcp --dport 25 -j DROP && iptables -A INPUT -p tcp --dport 465 -j DROP  && iptables -A OUTPUT -p tcp --dport 465 -j DROP && service iptables save

А также IPv6:

ip6tables -A INPUT -p tcp --dport 25 -j DROP && ip6tables -A OUTPUT -p tcp --dport 25 -j DROP && service iptables save


Для Debian/Ubuntu:

# iptables -A INPUT -p tcp --dport 25 -j DROP &&  iptables -A OUTPUT -p tcp --dport 25 -j DROP && iptables -A INPUT -p tcp --dport 465 -j DROP  && iptables -A OUTPUT -p tcp --dport 465 -j DROP && iptables-save > /etc/network/iptables.save
# vi /etc/rc.local
F="/etc/network/iptables.save"
test -f "$F" && /sbin/iptables-restore < $F