INFRASTRUCTURE LEARNINGINFRASTRUCTURE LEARNING
インフラ大全インフラ大全IT INFRASTRUCTURE / LEARNING
Infrastructure learning guide
Find a lesson or lab/

Esc to close · Search terms stay on your device

LEARNING日本語

Core lesson 16 of 18Topic: VPC: routing and traffic controls

Read EC2 security group rules: direction, ports and source scope

An EC2 security group (SG) contains allow rules for traffic reaching or leaving associated resources. Match direction, protocol, port and peer to the required connection. Even for SSH (Secure Shell), establish the connection method and actual source before considering a rule for port 22.

What you will learn

Explain what one SG rule permits and inspect its resource association, other associated groups and host-side conditions.

Prerequisite

Distinguish VPC routing from traffic controls. No real SG changes, IP submissions or private keys are needed.

Match four rule fields to the request

Read four fields using an SSH request
FieldQuestionIllustrative condition
DirectionIs this a new inbound or outbound request?SSH toward EC2 is inbound at its destination
ProtocolTCP, UDP or another protocol?Ordinary SSH uses TCP
PortWhich port does the destination listen on?22 if the configured SSH listener uses port 22
PeerInbound source or outbound destination?Limit it to the required management source

Read inbound and outbound relative to the resource associated with the SG. The same request is outbound at the source and inbound at the destination. The person using the console is not the reference point for direction.

Read the SG together with its actual resource association

Match the intended request to the groups associated with EC2
Match the intended request to the groups associated with EC21: Management source — Identify the required peer and traffic. — Inbound allow rule. 2: Inbound allow rule — Read the rules actually associated with the target resource. — EC2 network interface12Management sourceInbound allow ruleEC2 networkinterfaceMatch the intended request to the groups associated with EC21: Management source — Identify the required peer and traffic. — Inbound allow rule. 2: Inbound allow rule — Read the rules actually associated with the target resource. — EC2 network interface12ManagementsourceInbound allowruleEC2 networkinterface
  1. Management source → Inbound allow ruleIdentify the required peer and traffic.
  2. Inbound allow rule → EC2 network interfaceRead the rules actually associated with the target resource.
Management source
The connection method affects which peer the SG must match.
Inbound allow rule
Inspect direction, protocol, port and source.
EC2 network interface
Check SGs on the actual elastic network interface (ENI); OS listening and authentication are separate.

When several SGs are associated with the same resource, their rules are aggregated. Do not conclude “not allowed” after reading just one group. Conversely, narrowing one group may not achieve the intended restriction while another associated group still grants broad access.

Stateful responses do not allow every new request

SGs are stateful and handle responses to permitted traffic using connection state. That does not authorize arbitrary new requests. It also does not automatically satisfy network ACLs (NACLs), host firewalls, listeners or SSH authentication.

Limit the source and review the impact of changes

  1. Establish the connection method, destination, port and required source.
  2. Read all SGs associated with the target ENI and their allow rules.
  3. Before changing a shared group, inspect its other associated resources.
  4. Verify routing, NACLs and host behavior separately.

Choose an option to see the result and explanation.

SG A has no required allow rule, but SG B is on the same ENI. What next?
Read the answer and reason

Answer: Inspect the combined permissions, including B · Rules from associated groups are aggregated. Inspect every applicable SG rather than relying on a name or one configuration.

Do not diagnose an SSH timeout from SGs alone

After reading the relevant SG rules, investigate routes, NACLs, OS listeners, login identity and authentication method. The SSH troubleshooting lesson separates timeouts, refused connections and authentication errors to choose the next check.

Check, then explain in your own words

  1. Read direction, protocol, port and peer.
  2. Inspect every associated security group.
  3. Separate the SG condition from end-to-end SSH success.
Check your understanding: Should the first response to an SSH timeout be opening port 22 to everyone?

No. Establish the connection method and required source first.

Broad access does not replace diagnosis. Review the intended scope, other controls and the impact of a proposed change before acting.

Sources and conditions checked

The official references used in this lesson are collected here with their scope, conditions and corresponding sections. Independent expert review and live AWS comparison have not been performed.