Skip to content
Tutorials Center
My learning

Topics

Lesson 15 of 38 ยท Network and Data Protection

Cloud Network Segmentation and Security Groups

Design secure cloud networks: virtual networks, public and private subnets, security groups versus network ACLs, private endpoints and egress control, with runnable CIDR and rule checkers.

Identity is the new perimeter, but networks still matter. Good network design makes sure that a compromised web server cannot talk to your database administration port, that internal services are not reachable from the internet, and that data leaving your environment is limited. In the cloud you build these networks with software, in minutes, so the design is a set of configuration choices rather than cables.

Virtual networks and subnets

A virtual network (often called a VPC or VNet) is your private address space inside a provider's cloud. You divide it into subnets using CIDR notation such as 10.0.0.0/16 (65,536 addresses) split into /24 blocks of 256.

  • Public subnet. Has a route to the internet through an internet gateway. Resources here can have public addresses. Put only what must be public: load balancers, NAT gateways, bastion alternatives.
  • Private subnet. No direct route from the internet. Application servers and databases live here. They reach the internet, if they must, through a NAT gateway (outbound only).
  • Isolated subnet. No internet route at all, for databases and sensitive back ends.
flowchart TB
    Internet --> LB["Load balancer<br/>public subnet"]
    LB --> App["App servers<br/>private subnet"]
    App --> DB[("Database<br/>isolated subnet")]
    App -->|"outbound only"| NAT["NAT gateway"]
    NAT --> Internet

Tiers in separate subnets: the database has no route to or from the internet.

Security groups and network ACLs

Two kinds of virtual firewall appear on most platforms:

Security group Network ACL
Applies to One resource or interface A whole subnet
State Stateful (replies allowed automatically) Usually stateless (both directions need rules)
Rules Allow only Allow and deny, evaluated in order
Typical use Main control: who may reach this service Coarse subnet guardrail

Good security group habits:

  1. Allow only what is needed, by port and protocol. Nothing is allowed by default.
  2. Reference other security groups instead of addresses. "The database accepts port 5432 from members of the app group" survives IP changes and scaling.
  3. Never open admin ports to the world. Use private access methods: a managed session service, a VPN or a private connectivity path.
  4. Separate tiers (web, app, data), each with its own group.
  5. Restrict outbound traffic too (egress), not only inbound. Many compromised servers call home to attacker infrastructure.
  6. Name and tag every rule with a reason so reviews are possible.

Network design checklist

Tiers Web, app, data in own subnets
Few doors Only load balancers are public
Tight rules Port and source specific
Control egress Block calls to unknown hosts

Flat networks turn one compromise into many.

1 / 2

Private connectivity to cloud services

By default, calls to a managed service such as storage go over the provider's public endpoint. Two alternatives keep traffic off the internet:

  • Private endpoints / interface endpoints give the service a private address inside your network, so you can block public access entirely.
  • Gateway or service endpoints route traffic to the provider service over the provider's backbone, and let you add policies such as "only this bucket".

Between networks, use VPC peering or a transit gateway carefully: peering lets one network reach another, so check that it is not creating a flat network by accident. To connect your office or data center, use an IPsec VPN or a dedicated private link.

Runnable example: CIDR planning

The Python ipaddress module is perfect for checking address plans. This program carves subnets from a virtual network and detects overlaps, a common problem when you later connect networks.

Python Plan subnets and detect overlaps

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Plan address ranges that never overlap with other networks you may connect, including future ones.

Runnable example: a security group checker

Next, a small model of stateful security groups. It checks whether a connection is allowed and reports rules that are too wide. Groups can reference other groups, as real platforms allow.

Python Evaluate security group rules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The result matches the intended layering: only the app tier reaches the database, the web tier cannot skip a layer, and the checker flags the SSH rule that is open to the world.

Extra controls worth knowing

  • Flow logs record accepted and rejected connections between resources. Turn them on for sensitive networks and send them to central storage (monitoring chapter).
  • Network firewalls and inspection inspect traffic centrally at the edge or between networks, covered in Firewalls, WAF and DDoS Protection.
  • DNS controls block known-bad domains and keep private names private.
  • Microsegmentation applies per-workload rules, often by identity or label, so even servers in the same subnet cannot talk freely. It is the network side of zero trust.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where should a production database normally live?

    Databases do not need direct internet access; limit them to the tiers that use them.
  2. 2. What does 'stateful' mean for a security group?

    A stateful firewall tracks connections, so you do not need a separate rule for return traffic.
  3. 3. Why reference a security group instead of an IP address in a rule?

    Group references follow membership, so new instances are covered without editing rules.
  4. 4. What is the benefit of private endpoints for storage?

    A private address inside your network lets you disable the public path to the service.

Summary

  • Split networks into public, private and isolated subnets and place each tier in its own security group.
  • Security groups are stateful allow-lists on resources; network ACLs are coarse, ordered rules on subnets.
  • Reference groups, never open admin ports to the world, and restrict egress as well as ingress.
  • Use private endpoints, plan non-overlapping CIDR ranges and enable flow logs.

Next: Firewalls, WAF and DDoS Protection