iptables Regel Fehler

L

Lightstorm

Foren As
Ich habe einen Script womit ich die Firewall Regeln einstelle (nutze Debian):

Code:
#!/bin/sh

echo "Initalisiere Firewall ..."

iptables -F
iptables -X
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

iptables -Z

#Eigene Chains erstellen
iptables -N MYDROP
iptables -N MYACCEPT

# Lokale Kommunikation erlauben
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# Stateful Inspection aktivieren
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state INVALID -j MYDROP
iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT

# Eigene Chains MYDROP und MYACCEPT konfigurieren
iptables -A MYDROP -j LOG --log-prefix "FW-DROP: "
iptables -A MYDROP -j DROP
iptables -A MYACCEPT -j LOG --log-prefix "FW-ACCEPT: "
iptables -A MYACCEPT -j ACCEPT 

# SSH Zugang erlauben
iptables -A INPUT -p tcp --dport 22 -j MYACCEPT

# ICMP erlauben
iptables -A INPUT -p icmp -j MYACCEPT
iptables -A OUTPUT -p icmp -j MYACCEPT


# DNS
iptables -A INPUT -p udp --dport 53 MYACCEPT
iptables -A INPUT -p tcp --dport 53 MYACCEPT
iptables -A OUTPUT -p udp --dport 53 MYACCEPT
iptables -A OUTPUT -p tcp --dport 53 MYACCEPT

# WWW
iptables -A INPUT -p tcp --dport 80 -j MYACCEPT
iptables -A OUTPUT -p tcp --dport 80 -j MYACCEPT

#DHCP
iptables -A INPUT -p udp --dport 67 -j MYACCEPT

echo "Firewall ist konfiguriert und aktiv"

Ich habe es aus einem Lehrbuch, ich habe es auch einigermaßen verstanden und nicht nur blind abgeschrieben, bin aber halt noch am lernen.

Nachdem ausführen bekomme ich einige Fehlermeldungen:
Initalisiere Firewall ...
iptables: No chain/target/match by that name
iptables: No chain/target/match by that name
Bad argument `MYACCEPT'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `MYACCEPT'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `MYACCEPT'
Try `iptables -h' or 'iptables --help' for more information.
Bad argument `MYACCEPT'
Try `iptables -h' or 'iptables --help' for more information.
Firewall ist konfiguriert und aktiv

Das bedeutet das er mit den selbst erstellten Cahins MYDROP und MYACCEPT nicht klar kommt oder? Oder stimmt nur was mit MYACCEPT nicht?

Da weiß ich jetzt auch nicht weiter, so ist auch die Syntax aus dem Buch, sind die eigenen Chains falsch konfiguriert oder Syntaxfehler?
 
Super wäre es, wenn du uns sagen würdest, wo diese Fehlermeldung kommt. Dann müssen wir nicht raten, welcher der 30 Befehle kaputt ist. Starte das Skript einmal mit bash -x (kannst auch oben reinschreiben #!/bin/bash -x)
 
Ach so, ich habs gefunden. Merke dir den bash -x Tipp bitte generell. Der ist immer gut für Fehleranalyse in Skripten. Dein Fehler ist, dass du das -j vor MYACCEPT bei den DNS Regeln vergessen hast.
 
Danke, jetzt geht es :) Hab aber noch die iptables: No chain/target/match by that name Meldungen:

iptables -A MYDROP -j LOG --log-prefix "FW-DROP: "
iptables: No chain/target/match by that name
...
iptables -A MYACCEPT -j LOG --log-prefix "FW-ACCEPT: "
iptables: No chain/target/match by that name
 
Funktioniert hier:
Code:
root@mediacenter:~# echo "Initalisiere Firewall ..."
Initalisiere Firewall ...
root@mediacenter:~# 
root@mediacenter:~# iptables -F
root@mediacenter:~# iptables -X
root@mediacenter:~# iptables -P INPUT DROP
root@mediacenter:~# iptables -P OUTPUT DROP
root@mediacenter:~# iptables -P FORWARD DROP
root@mediacenter:~# 
root@mediacenter:~# iptables -Z
root@mediacenter:~# 
root@mediacenter:~# #Eigene Chains erstellen
root@mediacenter:~# iptables -N MYDROP
root@mediacenter:~# iptables -N MYACCEPT
root@mediacenter:~# 
root@mediacenter:~# # Lokale Kommunikation erlauben
root@mediacenter:~# iptables -A INPUT -i lo -j ACCEPT
root@mediacenter:~# iptables -A OUTPUT -o lo -j ACCEPT
root@mediacenter:~# 
root@mediacenter:~# # Stateful Inspection aktivieren
root@mediacenter:~# iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
root@mediacenter:~# iptables -A INPUT -m state --state INVALID -j MYDROP
root@mediacenter:~# iptables -A OUTPUT -m state --state ESTABLISHED -j ACCEPT
root@mediacenter:~# 
root@mediacenter:~# # Eigene Chains MYDROP und MYACCEPT konfigurieren
root@mediacenter:~# iptables -A MYDROP -j LOG --log-prefix "FW-DROP: "
root@mediacenter:~# iptables -A MYDROP -j DROP
root@mediacenter:~# iptables -A MYACCEPT -j LOG --log-prefix "FW-ACCEPT: "
root@mediacenter:~# iptables -A MYACCEPT -j ACCEPT 
root@mediacenter:~# iptables -L -v -n
Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
    0     0 MYDROP     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID 

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state ESTABLISHED 

Chain MYACCEPT (0 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           LOG flags 0 level 4 prefix `FW-ACCEPT: ' 
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain MYDROP (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           LOG flags 0 level 4 prefix `FW-DROP: ' 
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0

Prüfe vielleicht einmal mit iptables -L ob die neuen Chains angelegt wurden. Ggf. ist bei deinem Kernel das Log-Target nicht aktiviert? Kannst du in INPUT eine Regel mit Ziel LOG angeben?
 
Ich habe keinen Zugriff auf die Kernel Konfiguration. Soweit ich das gelesen habe liegt es daran das es ein vServer ist. Ich habe deswegen das loggen entfernt und MYACCEPT und MYDROP durch ACCEPT und DROP ersetzt, jetzt geht es ohne Fehlermeldung.
 

Ähnliche Themen

Port Forwarding mit iptables

ip6tables Problem

iptables verständniss frage, xrdp nicht erreichbar.

[SOLVED][CentOS 7] Samba server nicht erreichbar trotz firewall regeln.

iptables blocke nur von bestimmter ip

Zurück
Oben