Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Sv translation
languageen

CentOS 7

On CentOS 7, firewall-cmd is used to maintain the firewall.

List All Rules

Translations Ignore


Code Block
firewall-cmd --list-all


Allow a port

This example allows a TCP port through the firewall, for all network interfaces in the "public" zone:

Translations Ignore


Code Block
firewall-cmd --zone=public --add-port=3306/
tcp 
tcp --permanent
 



This example allows a UDP port through the firewall, for all network interfaces in the "public" zone:

Translations Ignore


Code Block
firewall-cmd --zone=public --add-port=20202/udp --permanent



Delete a rule
Translations Ignore


Code Block
firewall-cmd --zone=public --remove-port=3306/tcp --permanent


Reload the firewall

This makes the port changes active:

Translations Ignore


Code Block
firewall-cmd --reload

 



If port changes are specified without the --permanent flag, they will be active, but not permanent. The following command makes them permanent:

Translations Ignore


Code Block
firewall-cmd --runtime-to-permanent


CentOS 6

On CentOS 6, iptables is used to maintain the firewall.

Caution: iptables is cryptic and sometimes rather stupid. Especially: it will add multiple rules for the same port, and does not check if the port is already open.

List All Rules

Translations Ignore


Code Block
iptables -L -n


The -n option causes the ports to be listed numerically.
 


Alternatively:

Translations Ignore


Code Block
iptables-save > iptables_rules

less iptables_rules



This method is particularly useful for cleaning up duplicated rules.

Allow a port

This example allows a TCP port through the firewall:

Translations Ignore


Code Block
iptables -I INPUT 4 -p tcp -m tcp --dport 3306 -j ACCEPT

service iptables save




 

This example allows a UDP port through the firewall, for all network interfaces in the "public" zone:

Translations Ignore


Code Block
iptables -I INPUT 4 -p tcp -m udp --dport 20202 -j ACCEPT

service iptables save



Reload the firewall

This makes the port changes permanent:

Translations Ignore


Code Block
service iptables save


Delete a rule

The simplest way to delete rules in iptables, is to save and restore the configuration:

 


First, save the rules:

Translations Ignore


Code Block
iptables-save > iptables_rules

 



Now edit the rules:

Translations Ignore


Code Block
vi iptables_rules
 



Now restore the rules, with the changes made, and make them permanent:

Translations Ignore


Code Block
iptables-restore < iptables_rules


service iptables save



Sv translation
languagede

CentOS 7

Auf CentOS 7 wird firewall-cmd zur Wartung der Firewall verwendet.

Alle Regeln auflisten

firewall-cmd --list-all

Einen Port zulassen

Dieses Beispiel erlaubt einen TCP-Port durch die Firewall für alle Netzwerkschnittstellen in der "public" (öffentlichen) Zone:
firewall-cmd --zone=public --add-port=3306/tcp --permanent


Dieses Beispiel erlaubt einen UDP-Port durch die Firewall für alle Netzwerkschnittstellen in der "public" Zone:
firewall-cmd --zone=public --add-port=20202/udp --permanent

Löschen einer Regel

firewall-cmd --zone=public --remove-port=3306/tcp --permanent

Die Firewall neu laden

Dadurch werden die Portänderungen aktiv:

firewall-cmd --reload


Wenn Port-Änderungen ohne das Kennzeichen --permanent angegeben werden, sind sie aktiv, aber nicht dauerhaft. Der folgende Befehl macht sie permanent:

firewall-cmd --runtime-to-permanent

CentOS 6

Auf CentOS 6 wird iptables zur Wartung der Firewall verwendet.

Vorsicht: iptables ist kryptisch und manchmal etwas dumm. Besonders: es fügt mehrere Regeln für den gleichen Port hinzu und prüft nicht, ob der Port bereits offen ist..

Alle Regeln auflisten

iptables -L -n

Die Option -n bewirkt, dass die Ports numerisch aufgelistet werden.


Alternativ:

iptables-save > iptables_rules
less iptables_rules

Diese Methode ist besonders nützlich, um doppelte Regeln zu bereinigen.

Einen Port zulassen

Dieses Beispiel lässt einen TCP-Port durch die Firewall zu:
iptables -I INPUT 4 -p tcp -m tcp --dport 3306 -j ACCEPT
service iptables save


Dieses Beispiel erlaubt einen UDP-Port durch die Firewall für alle Netzwerkschnittstellen in der "public" Zone:
iptables -I INPUT 4 -p tcp -m udp --dport 20202 -j ACCEPT
service iptables save

Firewall neu laden

Dadurch werden die Portänderungen dauerhaft:

service iptables save

Löschen einer Regel

Der einfachste Weg, Regeln in iptables zu löschen, ist das Speichern und Wiederherstellen der Konfiguration:


Speichern Sie zunächst die Regeln:

iptables-save > iptables_rules


Bearbeiten Sie nun die Regeln:

vi iptables_rules


Stellen Sie nun die Regeln mit den vorgenommenen Änderungen wieder her und machen Sie sie dauerhaft:

iptables-restore < iptables_rules
service iptables save