> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://helpdesk.ggcircuit.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# 🔥 تكوين iptables لوظائف ggRock

يوفر هذا الدليل تكوينًا مرجعيًا لإعداد جدار حماية `iptables` للسماح بالعمل الصحيح لخادم وعميل ggRock.

> 📝 **ملاحظة:**  
> استبدل أي نطاقات عناوين IP الفراغة (على سبيل المثال، `X.X.X.X/X`، `Y.Y.Y.Y/Y`) بعناوين IP بصيغة **CIDR** المناسبة لبيئتك.

---

## 🔄 إعادة تعيين جدار الحماية إلى حالة نظيفة

```
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -X
iptables -F
```

---

## 🚫 تعطيل إعادة توجيه عناوين IP (التوجيه)

```
iptables -P FORWARD DROP
```

---

## ✅ السماح بحركة البيانات الواردة المتوقعة

```
# Drop malformed/invalid traffic
iptables -A INPUT -m conntrack --ctstate INVALID -j DROP
# Allow already established or related connections
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Allow localhost (loopback)
iptables -A INPUT -i lo -j ACCEPT
```

---

## 📦 السماح بـ DHCP الواردة (لـ PXE Boot)

```
iptables -A INPUT -p udp --dport 67:68 --sport 67:68 -j ACCEPT
```

---

## 🛠️ الوصول إلى الإدارة البعيدة (على سبيل المثال، واجهة ggRock الويب، HTTPS)

```
iptables -A INPUT -p tcp -s X.X.X.X/X --dport 9090 -j ACCEPT
iptables -A INPUT -p tcp -s X.X.X.X/X --dport 443 -j ACCEPT
iptables -A INPUT -p udp -s X.X.X.X/X --dport 443 -j ACCEPT
```

---

## 🖥️ السماح بالوصول من شبكة عميل ggRock

```
iptables -A INPUT -p icmp -s Y.Y.Y.Y/Y -j ACCEPT
iptables -A INPUT -p tcp -s Y.Y.Y.Y/Y -j ACCEPT
iptables -A INPUT -p udp -s Y.Y.Y.Y/Y -j ACCEPT
```

---

## 🔐 السماحيات الخاصة بـ VPN في ggCircuit

```
# Region 1
iptables -A INPUT -p tcp -s 34.255.111.148/25 --dport 9090 -j ACCEPT
iptables -A INPUT -p tcp -s 34.255.111.148/25 --dport 443 -j ACCEPT
iptables -A INPUT -p udp -s 34.255.111.148/25 --dport 443 -j ACCEPT
# Region 2
iptables -A INPUT -p tcp -s 54.228.150.30/25 --dport 9090 -j ACCEPT
iptables -A INPUT -p tcp -s 54.228.150.30/25 --dport 443 -j ACCEPT
iptables -A INPUT -p udp -s 54.228.150.30/25 --dport 443 -j ACCEPT
```

---

## 🚫 حظر جميع حركة البيانات الواردة الأخرى

```
# Optional: log dropped input traffic
# iptables -A INPUT -j LOG
iptables -P INPUT DROP
```

---

## 📤 السماح بحركة البيانات الصادرة المتوقعة

```
# Allow responses to connections
iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
# Allow localhost
iptables -A OUTPUT -o lo -j ACCEPT
# Allow ICMP (ping, etc.)
iptables -A OUTPUT -p icmp -j ACCEPT
# DHCP
iptables -A OUTPUT -p udp --dport 67 --sport 68 -j ACCEPT
# DNS
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
# NTP (time sync)
iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 123 -j ACCEPT
# HTTP/S for updates and web access
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -p udp --dport 443 -j ACCEPT
```

---

## 🌐 السماح بجميع حركة البيانات الصادرة الأخرى

```
# Optional: log outgoing traffic
# iptables -A OUTPUT -j LOG
iptables -P OUTPUT ACCEPT
```

---

> ⚠️ **مهم:**  
> قبل تشغيل هذا النص البرمجي، **استبدل** نطاقات عناوين IP الفراغة (`X.X.X.X/X`، `Y.Y.Y.Y/Y`) بالقيم الفعلية لبيئتك.

```
#!/bin/bash
# ggRock iptables Firewall Configuration Script
# Replace X.X.X.X/X and Y.Y.Y.Y/Y with actual CIDR blocks before running!
echo "⚙️ Applying iptables rules for ggRock..."
# === Reset existing rules ===
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
iptables -F
iptables -X
# === Allow expected incoming traffic ===
# Drop invalid packets
iptables -A INPUT -m conntrack --ctstate INVALID -j DROP
# Allow established and related traffic
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Allow loopback
iptables -A INPUT -i lo -j ACCEPT
# Allow DHCP (PXE boot)
iptables -A INPUT -p udp --dport 67:68 --sport 67:68 -j ACCEPT
# Remote management (Web UI)
iptables -A INPUT -p tcp -s X.X.X.X/X --dport 9090 -j ACCEPT
iptables -A INPUT -p tcp -s X.X.X.X/X --dport 443 -j ACCEPT
iptables -A INPUT -p udp -s X.X.X.X/X --dport 443 -j ACCEPT
# Allow all traffic from ggRock PC subnet
iptables -A INPUT -p icmp -s Y.Y.Y.Y/Y -j ACCEPT
iptables -A INPUT -p tcp -s Y.Y.Y.Y/Y -j ACCEPT
iptables -A INPUT -p udp -s Y.Y.Y.Y/Y -j ACCEPT
# ggCircuit VPN IPs
iptables -A INPUT -p tcp -s 34.255.111.148/25 --dport 9090 -j ACCEPT
iptables -A INPUT -p tcp -s 34.255.111.148/25 --dport 443 -j ACCEPT
iptables -A INPUT -p udp -s 34.255.111.148/25 --dport 443 -j ACCEPT
iptables -A INPUT -p tcp -s 54.228.150.30/25 --dport 9090 -j ACCEPT
iptables -A INPUT -p tcp -s 54.228.150.30/25 --dport 443 -j ACCEPT
iptables -A INPUT -p udp -s 54.228.150.30/25 --dport 443 -j ACCEPT
# Drop all other incoming traffic
# Uncomment to enable logging:
# iptables -A INPUT -j LOG
iptables -P INPUT DROP
# === Allow expected outgoing traffic ===
# Allow related outbound traffic
iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
# Allow loopback
iptables -A OUTPUT -o lo -j ACCEPT
# Allow ICMP (ping)
iptables -A OUTPUT -p icmp -j ACCEPT
# DHCP
iptables -A OUTPUT -p udp --dport 67 --sport 68 -j ACCEPT
# DNS
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 53 -j ACCEPT
# NTP
iptables -A OUTPUT -p udp --dport 123 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 123 -j ACCEPT
# HTTP/S
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -p udp --dport 443 -j ACCEPT
# Allow all other outbound traffic
# Uncomment to enable logging:
# iptables -A OUTPUT -j LOG
iptables -P OUTPUT ACCEPT
echo "✅ iptables rules applied successfully!"
```

---

### 🔐 لاستخدام هذا النص:

1. احفظ هذا النص باسم `configure-iptables.sh`
2. اجعله قابلاً للتنفيذ:

```
   chmod +x configure-iptables.sh
```
3. قم بتشغيله كـ root (أو باستخدام sudo):

```
   sudo ./configure-iptables.sh
```

---

### اختياري:

لجعل قواعد `iptables` **محفوظة عبر إعادة التشغيل**:

---

## 🧊 الخطوة 1: تثبيت أدوات الاستمرارية

قم بتشغيل هذا الأمر لتثبيت الحزمة المطلوبة:

```
sudo apt-get update && sudo apt-get install -y iptables-persistent
```

أثناء التثبيت، سيطلب منك **حفظ القواعد الحالية** — قل **نعم** عند الطلب.
 
---

## 💾 الخطوة 2: احفظ قواعد iptables الحالية

بعد تشغيل نصك `configure-iptables.sh`، احفظ القواعس النشطة بهذه الطريقة:

```
sudo netfilter-persistent save
```

هذا يحفظ قواعد IPv4 و IPv6 إلى:

* `/etc/iptables/rules.v4`
* `/etc/iptables/rules.v6`

> إذا كنت تستخدم IPv4 فقط، فلا بأس بذلك — يمكن أن يبقى ملف IPv6 فارغًا.

---

## 🔁 الخطوة 3: تحميل تلقائي عند بدء التشغيل

خدمة `netfilter-persistent` تتولى تحميل القواعد عند التشغيل تلقائيًا. يمكنك التحقق من تمكينها باستخدام:

```
sudo systemctl is-enabled netfilter-persistent
```

إذا لم تكن مفعلة، يمكنك تفعيلها:

```
sudo systemctl enable netfilter-persistent
```

---

## 🧪 اختياري: إعادة التحميل بدون إعادة تشغيل

لتطبيق القواعد المحفوظة بدون إعادة تشغيل:

```
sudo netfilter-persistent reload
```

---

✅ هذا كل شيء! سيتم الآن الحفاظ على تكوين `iptables` المخصص لديك عبر إعادة تشغيل النظام.