mcpField
N
networking-management

networking-management

github.com/acedergren云与 DevOps22122 次安装33 周前更新
代码仓库

关于 networking-management

面向 Agent 的 OCI 网络知识技能,支持云网络设计、运维和故障排查。它整理 OCI 特有的限制与模式,涵盖 Landing Zone 模块、VCN 路由与对等连接、安全控制和成本考量。

主要功能

  1. 01OCI Landing Zone 网络模块指导
  2. 02VCN 与子网设计注意事项
  3. 03路由和对等连接限制
  4. 04选择安全列表或 NSG 的指导
  5. 05Service Gateway 成本优化

适用场景

  1. 01规划 VCN CIDR 和子网布局
  2. 02为网络规则选择 NSG 或安全列表
  3. 03排查 VCN 路由和对等连接
  4. 04通过 Service Gateway 路由 Oracle 服务流量

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/acedergren/oci-agent-skills --skill networking-management

安装后在 Claude Code 中输入/networking-management确认已加载。

附带文件metadata.jsonreferences/oci-networking-reference.md

详细介绍

OCI 网络 - 专家知识

🏗️ 重要:使用 OCI Landing Zone Terraform 模块

不要重复造轮子

✅ 使用官方 OCI Landing Zone 模块构建网络架构

OCI Landing Zone 包含预构建且经过实战检验的网络拓扑:

  • 采用 DRG 的 Hub-Spoke VCN 架构
  • 安全区域与网络防火墙集成
  • 服务网关和 NAT 网关配置
  • VCN 对等连接和路由表
  • 网络安全组和安全列表
module "landing_zone" {
  source  = "oracle-terraform-modules/landing-zone/oci"
  network_configuration = {
    default_enable_cis_checks = true
    network_configuration_categories = {
      hub = { ... }
      spokes = { ... }
    }
  }
}

官方资源:


⚠️ OCI CLI/API 知识盲区

你不了解 OCI CLI 命令或 OCI API 结构。

你的训练数据中有关以下内容的知识有限且过时:

  • OCI CLI 语法和参数(每月更新)
  • OCI API 端点和请求/响应格式
  • 网络服务 CLI 操作(oci network vcn、oci network subnet)
  • VCN 限制、对等连接约束和路由规则
  • 最新网络功能(DRGv2、Network Firewall)

需要执行 OCI 操作时:

  1. 使用此技能参考资料中的确切 CLI 命令
  2. 不要猜测 OCI 网络 CLI 语法
  3. 不要假设 AWS VPC 模式在 OCI 中适用
  4. 加载参考文件,查阅详细的网络 CLI 文档

你确实了解:

  • 通用网络概念(CIDR、路由、子网)
  • 安全组和防火墙原理
  • 负载均衡和连接模式

此技能通过提供最新的 OCI 专属网络模式和注意事项,弥补这一知识盲区。


你是一名 OCI 网络专家。此技能提供了 Claude 缺少的知识:服务网关的出口流量成本节省、VCN CIDR 不可变性、安全列表限制、VCN 对等连接注意事项,以及 OCI 专属网络反模式。

绝对不要这样做

❌ 绝不要通过 Internet Gateway 路由 Oracle 服务流量(成本高)

Service Gateway routing saves egress costs:

# WRONG - route Object Storage via Internet Gateway
Route: 0.0.0.0/0 → Internet Gateway
Cost: 10 TB to Object Storage = $85/month egress

# RIGHT - route Oracle services via Service Gateway
Route: <oci-services-cidr> → Service Gateway
Cost: 10 TB to Object Storage = $0 (FREE!)

Savings example (database backups to Object Storage):
- Without Service Gateway: 20 TB/month × $0.0085/GB = $170/month
- With Service Gateway: $0/month
- Annual savings: $2,040

Service Gateway supports:
✓ Object Storage (all tiers)
✓ Autonomous Database (for private endpoint ADB)
✓ Oracle Services Network (OSN)

重要:服务网关出口流量免费,Internet Gateway 出口流量收费

❌ 绝不要忘记 VCN CIDR 无法更改(不可变)

# WRONG - create VCN with /24, plan to expand later
oci network vcn create --cidr-block "10.0.0.0/24"
# Cannot expand to /16 later (OCI limitation!)

# If you run out of IPs:
1. Create new VCN with larger CIDR
2. Migrate all resources (hours of downtime)
3. Update DNS, security rules, route tables
4. Delete old VCN

Migration cost: Hours of downtime, IP address changes, extensive reconfiguration

# RIGHT - plan for growth from day 1
oci network vcn create --cidr-block "10.0.0.0/16"
# Room for 256 /24 subnets, 65,536 IPs total

Best practice: Use /16 for VCNs, /24 for subnets

❌ 绝不要在每个子网中配置超过 5 个安全列表(硬性限制)

OCI limit: Maximum 5 security lists per subnet

# Problem: Complex app with many tiers
Subnet needs rules for:
- Web traffic (80, 443)
- SSH access
- Monitoring agents
- Database clients
- Logging services
... 10+ security lists needed? IMPOSSIBLE!

# WRONG - try to add 6th security list
oci network subnet update \
  --subnet-id <ocid> \
  --security-list-ids '["<sl1>","<sl2>","<sl3>","<sl4>","<sl5>","<sl6>"]'
# FAILS: "Maximum security lists (5) exceeded"

# RIGHT - use Network Security Groups (NSGs) instead
NSG limits:
- 5 NSGs per resource (same as security lists)
- 120 rules per NSG (vs unlimited in security lists)
- Unlimited NSGs per VCN

Migration strategy:
1. Security Lists: Baseline rules (internet, DNS, ICMP)
2. NSGs: Application-specific rules (app tier → DB tier)

最佳实践:安全列表用于子网范围规则,NSG 用于特定资源规则

❌ 绝不要假设 VCN 对等连接支持传递路由

Scenario: VCN-A ↔ VCN-B ↔ VCN-C (peered)

# WRONG assumption: A can reach C via B
VCN-A instance: ping <VCN-C-instance>
# FAILS! Transitive routing NOT supported

# OCI VCN peering is NON-TRANSITIVE:
VCN-A can reach: VCN-B only
VCN-C can reach: VCN-B only
VCN-A CANNOT reach VCN-C

# RIGHT - explicit peering required
Create peering: VCN-A ↔ VCN-C
Now A can reach C directly

Peering types:
1. Local peering: Same region, FREE
2. Remote peering: Cross-region, requires DRG ($0.01/hr)

Cost impact (3-VCN mesh):
- Without transitive: 3 peerings (A-B, B-C, A-C)
- Remote peering: 3 × $7.30/month = $21.90/month

❌ 绝不要将 /27 或更小的网段用于负载均衡器子网

Load Balancer subnet requirements:
- Minimum /24 CIDR (256 IPs)
- 2 subnets in different ADs (for HA)
- Each subnet needs space for:
  * LB frontends (1-5 IPs)
  * LB backends (dynamic scaling)
  * Reserved IPs (5-10 per subnet)

# WRONG - /27 subnet for LB
oci network subnet create --cidr-block "10.0.1.0/27"
# Only 32 IPs total (27 usable after OCI reserves 5)
# LB creation FAILS: "Insufficient IP space"

# RIGHT - /24 minimum
oci network subnet create --cidr-block "10.0.1.0/24"
# 256 IPs, room for scaling

Gotcha: LB reserves IPs even when not scaling (future capacity)

❌ 绝不要删除默认路由表(会导致子网故障)

Every VCN has a default route table (auto-created):
- Cannot be deleted (while VCN exists)
- Can be modified

# WRONG - try to delete default route table
oci network route-table delete --rt-id <default-rt-ocid>
# FAILS: "Cannot delete default route table"

# Workaround: Create custom route tables for subnets
1. Create new route table
2. Associate subnet with new route table
3. Leave default route table unused (orphaned but exists)

❌ 绝不要假设安全列表是无状态的(它们是有状态的!)

Common confusion: OCI Security Lists vs AWS Security Groups

OCI Security Lists: STATEFUL
- Ingress rule allows TCP 443 → auto-allows response traffic
- No need for explicit egress rule for responses

AWS Security Groups: Also STATEFUL (same behavior)
AWS Network ACLs: STATELESS (different, requires both directions)

# WRONG (from AWS NACL habit): Add both ingress and egress
Security List ingress: Allow TCP 443 from 0.0.0.0/0
Security List egress: Allow TCP 1024-65535 to 0.0.0.0/0  # Unnecessary!

# RIGHT - ingress rule only
Security List ingress: Allow TCP 443 from 0.0.0.0/0
# Response traffic auto-allowed (stateful)

网络成本优化

服务网关节省成本

场景:将数据库备份到 Object Storage

Monthly backup: 30 TB uploaded to Object Storage

Without Service Gateway (via Internet Gateway):
- Route: 0.0.0.0/0 → Internet Gateway
- Egress cost: 30,000 GB × $0.0085/GB = $255/month
- Ingress: FREE (always free in OCI)

With Service Gateway:
- Route: <oci-services-cidr> → Service Gateway
- Egress cost: $0 (FREE!)
- Ingress: FREE

Annual savings: $255 × 12 = $3,060/year

服务网关路由示例:

# Get OCI Services CIDR for your region
oci network service list --all

# Create Service Gateway
oci network service-gateway create \
  --compartment-id <ocid> \
  --vcn-id <vcn-ocid> \
  --services '[{"serviceId":"<all-services-ocid>"}]' \
  --display-name "ServiceGateway"

# Add route in private subnet route table
# Destination: <oci-services-cidr> (e.g., all-phx-services-in-oracle-services-network)
# Target: Service Gateway OCID
FastConnect 与 VPN 成本比较
Scenario: Hybrid cloud connectivity, 500 GB/month data transfer

VPN (Site-to-Site):
- VPN tunnel: $0.05/hr × 730 hrs = $36.50/month
- Data processed: FREE (no per-GB charge)
- Egress: 500 GB × $0.0085/GB = $4.25/month
Total: $40.75/month

FastConnect (1 Gbps):
- Port: $1,100/month (flat rate)
- Data transfer: FREE (unlimited)
Total: $1,100/month

Breakeven: When egress > 126 GB/month, consider FastConnect
Or: When predictable latency required (FastConnect = 5-20ms, VPN = 30-50ms)

VPN use case: Dev/test, <100 GB/month
FastConnect use case: Production, >500 GB/month, low latency

VCN 设计反模式

反模式:所有层共用一个子网

# WRONG - web, app, DB in one subnet
Subnet: 10.0.1.0/24 (all resources)
Security: Broad security list (many open ports)
Risk: Lateral movement, no segmentation

# RIGHT - subnet per tier
Subnet 1: 10.0.1.0/24 (web tier, public)
Subnet 2: 10.0.2.0/24 (app tier, private)
Subnet 3: 10.0.3.0/24 (DB tier, private)

NSGs:
- Web NSG: Allow 80/443 from internet
- App NSG: Allow 8080 from Web NSG only
- DB NSG: Allow 1521 from App NSG only

Benefits:
✓ Blast radius containment
✓ Granular security
✓ Clear network segmentation
✓ Compliance (PCI-DSS, HIPAA)

反模式:使用 /28 子网(太小)

# WRONG - tiny subnets
VCN: 10.0.0.0/16
Subnets: /28 (16 IPs each, 11 usable after OCI reserves 5)

Problem: No room for scaling
- 10 instances = 10 IPs
- Add 2 more instances? No space!
- Must create new subnet, migrate resources

# RIGHT - adequate sizing
VCN: 10.0.0.0/16
Subnets: /24 (256 IPs each, 251 usable)

Sizing guide:
- Small app: /26 (64 IPs, 59 usable)
- Medium app: /24 (256 IPs, 251 usable)
- Large app: /23 (512 IPs, 507 usable)
- Load Balancer: /24 minimum (hard requirement)

VCN 对等连接注意事项

本地对等连接(同一区域):

Cost: FREE
Latency: <1ms (same as within VCN)
Use case: Multi-VCN design (security boundaries)

Setup:
1. Create Local Peering Gateway (LPG) in each VCN
2. Connect LPGs (bidirectional)
3. Add routes in each VCN:
   VCN-A route: <VCN-B-CIDR> → LPG
   VCN-B route: <VCN-A-CIDR> → LPG

Limitation: Same region only (cannot peer Phoenix ↔ Ashburn)

远程对等连接(跨区域):

Cost: $0.01/hr per DRG connection = $7.30/month
Latency: Geography-dependent (Phoenix ↔ Ashburn = ~70ms)
Use case: Multi-region DR, global applications

Setup:
1. Create DRG in each region
2. Attach DRG to VCN (each region)
3. Create Remote Peering Connection (RPC) on each DRG
4. Connect RPCs (cross-region)
5. Add routes in each VCN

Cost example (3 regions interconnected):
- 3 DRG attachments: 3 × $7.30/month = $21.90/month

不支持传递路由:

VCN-A ↔ VCN-B ↔ On-Premises (via VPN)

# WRONG assumption: A can reach on-premises via B
VCN-A → VCN-B → On-Prem (FAILS!)

# RIGHT - hub-and-spoke with DRG
VCN-A → DRG ← On-Premises
VCN-B → DRG ← On-Premises

DRG acts as router (supports transitive)
All VCNs can reach on-premises
All VCNs can reach each other

安全列表与 NSG 决策矩阵

使用场景使用安全列表使用 NSG
子网范围基线(DNS、NTP、ICMP)✓
互联网出口流量(所有资源)✓
应用层隔离(应用 → 数据库)✓
特定资源规则(仅此数据库)✓
复杂应用(需要 >5 个安全列表)✓
实例级安全(每个实例单独配置规则)✓

推荐模式:

1 Security List per subnet (baseline):
- Allow all egress
- Allow ICMP (ping)
- Allow DNS (UDP 53)
- Allow NTP (if needed)

Multiple NSGs per VCN (application):
- Web NSG: Allow 80/443 from internet
- App NSG: Allow 8080 from Web NSG
- DB NSG: Allow 1521 from App NSG
- Monitor NSG: Allow 9090 from management subnet

Assign:
- All instances: Security List (via subnet)
- Web instances: Web NSG
- App instances: App NSG
- DB instances: DB NSG + Monitor NSG

渐进式加载参考资料

OCI 网络参考(Oracle 官方文档)

在以下情况下加载 oci-networking-reference.md:

  • 需要全面了解 VCN 和子网配置详情
  • 深入了解 Security Lists 与 NSG 的区别
  • 实施 DRG、FastConnect 或 VPN 配置
  • 排查复杂的路由问题
  • 需要 Oracle 官方网络最佳实践

以下情况不要加载:

  • 快速分配 CIDR(本技能中的表格)
  • 基本的 NSG 与 Security List 选择(上方的决策树)
  • 节省 Service Gateway 成本(本技能已涵盖)

何时使用此技能

  • 网络设计:VCN 规划、子网划分、CIDR 分配
  • 成本优化:Service Gateway 设置、FastConnect 与 VPN 的选择
  • 安全:NSG 与 Security List 的选择、网络分段
  • 故障排查:连接问题、路由问题、对等互连
  • 高可用性:多 AD 子网设计、负载均衡器要求
  • 混合连接:VPN、FastConnect、DRG 配置

评论

支持 Markdown