Как видно в консоли, при попытке установить iptables, пишет, что уже установлено, хотя ни в /etc, ни в /etc/init.d нет ничего, что принадлежало бы iptables. Как можно его установить? Зараннее спасибо
[console]# service iptables status
iptables: unrecognized service[/console]
[console]# apt-get install iptables
Reading package lists... Done
Building dependency tree
Reading state information... Done
iptables is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.[/console]
Либо в секцию up интерфейса - прописать iptables-restore, соответственно в секцию down - iptables-save.
Где эти секции - man interfaces.
Если хочется init скрипт - то никто не запрещает - принцип построения можно подсмотреть в гугле.
Вот как пример привожу:
#Catch portscanners
einfo "Creating portscan detection chain"
$IPTABLES -N check-flags
$IPTABLES -F check-flags
$IPTABLES -A check-flags -p tcp --tcp-flags ALL FIN,URG,PSH -m limit --limit 5/minute -j LOG --log-level alert --log-prefix "NMAP-XMAS:"
$IPTABLES -A check-flags -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
$IPTABLES -A check-flags -p tcp --tcp-flags ALL ALL -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "XMAS:"
$IPTABLES -A check-flags -p tcp --tcp-flags ALL ALL -j DROP
$IPTABLES -A check-flags -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "XMAS-PSH:"
$IPTABLES -A check-flags -p tcp --tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP
$IPTABLES -A check-flags -p tcp --tcp-flags ALL NONE -m limit --limit 5/minute -j LOG --log-level 1 --log-prefix "NULL_SCAN:"
$IPTABLES -A check-flags -p tcp --tcp-flags ALL NONE -j DROP
$IPTABLES -A check-flags -p tcp --tcp-flags SYN,RST SYN,RST -m limit --limit 5/minute -j LOG --log-level 5 --log-prefix "SYN/RST:"
$IPTABLES -A check-flags -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
$IPTABLES -A check-flags -p tcp --tcp-flags SYN,FIN SYN,FIN -m limit --limit 5/minute -j LOG --log-level 5 --log-prefix "SYN/FIN:"
$IPTABLES -A check-flags -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
# Apply and add invalid states to the chains
einfo "Applying chains to INPUT"
$IPTABLES -A INPUT -m state --state INVALID -j DROP
$IPTABLES -A INPUT -j icmp_allowed
$IPTABLES -A INPUT -j check-flags
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A INPUT -j allow-ssh-traffic-in
$IPTABLES -A INPUT -j allow-www-traffic-in
$IPTABLES -A INPUT -j allow-ftp-traffic-in
$IPTABLES -A INPUT -j allow-smb-traffic-in
$IPTABLES -A INPUT -j allow-time-traffic-in
$IPTABLES -A INPUT -j allowed-connection
einfo "Applying chains to FORWARD"
$IPTABLES -A FORWARD -m state --state INVALID -j DROP
$IPTABLES -A FORWARD -j icmp_allowed
$IPTABLES -A FORWARD -j check-flags
$IPTABLES -A FORWARD -o lo -j ACCEPT
# $IPTABLES -A FORWARD -j allow-ssh-traffic-in
# $IPTABLES -A FORWARD -j allow-time-traffic-in
# $IPTABLES -A FORWARD -j allow-ftp-traffic-in
# $IPTABLES -A FORWARD -j allow-www-traffic-in
# $IPTABLES -A FORWARD -j allow-www-traffic-out
$IPTABLES -A FORWARD -j allowed-connection
einfo "Applying chains to OUTPUT"
$IPTABLES -A OUTPUT -m state --state INVALID -j DROP
$IPTABLES -A OUTPUT -j icmp_allowed
$IPTABLES -A OUTPUT -j check-flags
$IPTABLES -A OUTPUT -o lo -j ACCEPT
$IPTABLES -A OUTPUT -j allow-ssh-traffic-out
$IPTABLES -A OUTPUT -j allow-dns-traffic-out
$IPTABLES -A OUTPUT -j allow-www-traffic-out
$IPTABLES -A OUTPUT -j allow-mail-traffic-out
$IPTABLES -A OUTPUT -j allow-ftp-traffic-out
$IPTABLES -A OUTPUT -j allow-smb-traffic-out
$IPTABLES -A OUTPUT -j allow-krab-term-traffic-out
$IPTABLES -A OUTPUT -j allow-time-traffic-out
$IPTABLES -A OUTPUT -j allowed-connection
#Allow client to route through via NAT (Network Address Translation)
$IPTABLES -t nat -A POSTROUTING -o $IINTERFACE -j MASQUERADE
eend $?
}
start() {
ebegin "Starting firewall"
if [ -e "$" ]; then
restore
else
einfo "$ does not exists. Using default rules."
rules
fi
eend $?
}
showoptions() {
echo "Usage: $0 "
echo "start) will restore setting if exists else force rules"
echo "stop) delete all rules and set all to accept"
echo "rules) force settings of new rules"
echo "save) will store settings in $"
echo "restore) will restore settings from $"
echo "showstatus) Shows the status"
}
4fun, в дебиан нет конструкции # service iptables status
Остальное написано в предидущем сообщении.
Вот пример с iptables-save/restore
/etc/network/interfaces
text
auto eth0
iface eth0 inet static
address 192.168.0.1
netmask 255.255.255.0
network 192.168.0.0
broadcast 192.168.0.255
up iptables-restore
down iptables-save
# Также можно:
pre-up <command>
post-up <command>
При поднятии интерфейса правила восстанавливаются, при опускании - сохраняются.
Ну и стандартно - просто скрипт с правилами, который выполняется при загрузке - имхо самый распостраненный вариант, можно положить в каталог например if-up.