|
1. Überprüfen Sie den Status des iptables-Dienstes Beginnen Sie damit, den Status des iptables-Dienstes zu überprüfen [mw_shl_code=bash, wahr] [root@woxplife ~]# Service iptables Status
iptables: Firewall is not running.[/mw_shl_code] Der iptables-Dienst ist installiert, aber der Dienst wird nicht gestartet. Wenn du es nicht hast, kannst du es direkt installieren [mw_shl_code=bash,true]yum install -y iptables[/mw_shl_code] Start-iptables [mw_shl_code=bash, wahr] [root@woxplife ~]# Service iptables starten
iptables: Applying firewall rules: [ OK ][/mw_shl_code] Schauen Sie sich die aktuelle Konfiguration von iptables an [mw_shl_code=bash, wahr] [root@woxplife ~]# iptables -L -n[/mw_shl_code] 2. Die Standard-Firewall-Regeln löschen[mw_shl_code=bash,true]#首先在清除前要将policy INPUT wird auf ACCEPT geändert, was anzeigt, dass alle Anfragen akzeptiert werden. #这个一定要先做, sonst könnte es nach dem Entleeren tragisch sein iptables -P EINGABE AKZEPTIERT
#清空默认所有规则 iptables -F
#清空自定义的所有规则 iptables -X
#计数器置0 iptables -Z[/mw_shl_code]
3. Konfigurationsregeln [mw_shl_code=bash, wahr]#允许来自于lo接口的数据包 #如果没有此规则 können Sie über 127.0.0.1, wie z. B. Ping 127.0.0.1, keine lokalen Dienste nutzen iptables -A INPUT -i lo -j ACCEPT
#ssh端口22 iptables -A INPUT -p tcp --dport 22 -j AKZEPTIEREN
#FTP端口21 iptables -A INPUT -p tcp --dport 21 -j AKZEPTIEREN
#web服务端口80 iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#tomcat iptables -A INPUT -p tcp --dport xxxx -j AKZEPTIEREN
#mysql iptables -A INPUT -p tcp --dport xxxx -j AKZEPTIEREN
#允许icmp包通过, das heißt, Ping zuzulassen iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
#允许所有对外请求的返回包 #本机对外请求相当于OUTPUT muss das Rücksendungspaket empfangen werden, was dem INPUT entspricht iptables -A INPUT -m Zustand --Zustand ESTABLISHED -j ACCEPT
#如果要添加内网ip信任 (alle TCP-Anfragen akzeptieren) iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT
#过滤所有非以上规则的请求 iptables -P INPUT DROP[/mw_shl_code]
4. ErhaltungZuerst iptables -L -n, um zu sehen, ob die Konfiguration korrekt ist. Wenn du kein Problem hast, solltest du nicht überstürzen und speichern, denn wenn du nicht speicherst, gilt es nur vorerst und wirkt nach dem Neustart nicht mehr, sodass du im Hintergrund den Server zwingen kannst, die Einstellungen neu zu starten.
Eröffne eine weitere SSH-Verbindung, um sicherzustellen, dass du dich anmelden kannst. Speichern Sie es später unbedingt [mw_shl_code=bash, wahr]#保存 [root@woxplife ~]# Service iptables speichern
#添加到自启动chkconfig [root@woxplife ~]# chkconfig iptables auf[/mw_shl_code]
|