2

Я пытаюсь настроить iptables (используя iptables-restore) для нового сервера и искал документы по безопасности от Linode, поэтому в основном использовал их шаблоны для IPv4 и IPv6. Они оба терпят неудачу в сообщении COMMIT, но я предполагаю, что ошибка в другом месте.

alessio@scw-272444:~$ sudo iptables-restore < /tmp/v4
iptables-restore: line 37 failed

IPv4:

*filter

# Allow all loopback (lo0) traffic and reject traffic
# to localhost that does not originate from lo0.
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -s 127.0.0.0/8 -j REJECT

# Allow ping and traceroute.
-A INPUT -p icmp --icmp-type 3 -j ACCEPT
-A INPUT -p icmp --icmp-type 8 -j ACCEPT
-A INPUT -p icmp --icmp-type 11 -j ACCEPT

# Allow SSH connections.
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

# Allow HTTP and HTTPS connections from anywhere
# (the normal ports for web servers).
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

# Accept inbound traffic from established connections.
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Log what was incoming but denied (optional but useful).
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables_INPUT_denied: " --log-level 7

# Reject all other inbound.
-A INPUT -j REJECT

# Log any traffic which was sent to you
# for forwarding (optional but useful).
-A FORWARD -m limit --limit 5/min -j LOG --log-prefix "iptables_FORWARD_denied: " --log-level 7

# Reject all traffic forwarding.
-A FORWARD -j REJECT

COMMIT

IPv6:

*filter

# Allow all loopback (lo0) traffic and reject traffic
# to localhost that does not originate from lo0.
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -s ::1/128 -j REJECT

# Allow ICMP
-A INPUT  -p icmpv6 -j ACCEPT

# Allow HTTP and HTTPS connections from anywhere
# (the normal ports for web servers).
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT

# Accept inbound traffic from established connections.
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Log what was incoming but denied (optional but useful).
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "ip6tables_INPUT_denied: " --log-level 7

# Reject all other inbound.
-A INPUT -j REJECT

# Log any traffic which was sent to you
# for forwarding (optional but useful).
-A FORWARD -m limit --limit 5/min -j LOG --log-prefix "ip6tables_FORWARD_denied: " --log-level 7

# Reject all traffic forwarding.
-A FORWARD -j REJECT

COMMIT

1 ответ1

0

Ошибка строки COMMIT, потому что, возможно, перед этой строкой есть ошибки. Пожалуйста, проверьте каждую строку в вашей конфигурации (вставьте ее как аргументы для iptables).

Или вы можете преобразовать свою конфигурацию iptables как скрипт bash и запустить bash -x для просмотра неверной конфигурации:


#!/bin/bash
#
# this file is: iptables_v4.sh

# Allow all loopback (lo0) traffic and reject traffic
# to localhost that does not originate from lo0.
iptables -A  INPUT -i lo -j ACCEPT
iptables -A  INPUT ! -i lo -s 127.0.0.0/8 -j REJECT

# Allow ping and traceroute.
iptables -A  INPUT -p icmp --icmp-type 3 -j ACCEPT
iptables -A  INPUT -p icmp --icmp-type 8 -j ACCEPT
iptables -A  INPUT -p icmp --icmp-type 11 -j ACCEPT

# Allow SSH connections.
iptables -A  INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT

# Allow HTTP and HTTPS connections from anywhere
# (the normal ports for web servers).
iptables -A  INPUT -p tcp --dport 80 -j ACCEPT
iptables -A  INPUT -p tcp --dport 443 -j ACCEPT

# Accept inbound traffic from established connections.
iptables -A  INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Log what was incoming but denied (optional but useful).
iptables -A  INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables_INPUT_denied: " --log-level 7

# Reject all other inbound.
iptables -A  INPUT -j REJECT

# Log any traffic which was sent to you
# for forwarding (optional but useful).
iptables -A  FORWARD -m limit --limit 5/min -j LOG --log-prefix "iptables_FORWARD_denied: " --log-level 7

# Reject all traffic forwarding.
iptables -A  FORWARD -j REJECT

Отладить:

root$bash -x iptables_v4.sh

Всё ещё ищете ответ? Посмотрите другие вопросы с метками .