Chapter 1: Networking Fundamentals
1.3 Ports
In short: A port is a 16-bit number used by a transport protocol such as TCP or UDP. The protocol, IP address and port help identify the service endpoint.
Now the packet has reached the right machine – but which program on that machine will answer? Look, that is the job of the port. On a single EC2 of Mauli Dairy, Nginx (80), SSH (22) and MySQL (3306) can all run at the same time, because each one listens on a different port.
आता पॅकेट बरोबर मशीनपर्यंत पोहोचला, पण त्या मशीनवर कोणता प्रोग्राम उत्तर देईल? बघा, हे काम पोर्टचं आहे. Mauli Dairy च्या एकाच EC2 वर Nginx (80), SSH (22) आणि MySQL (3306) एकाच वेळी चालू शकतात, कारण प्रत्येक जण वेगळ्या पोर्टवर ऐकतो.
अब पैकेट सही मशीन तक पहुँच गया, लेकिन उस मशीन पर कौन सा प्रोग्राम जवाब देगा? देखो, ये काम पोर्ट का है. Mauli Dairy के एक ही EC2 पर Nginx (80), SSH (22) और MySQL (3306) एक साथ चल सकते हैं, क्योंकि हर एक अलग पोर्ट पर सुनता है.
A port is a 16-bit number (0–65535) that identifies a specific process/service on a host. One server with one IP can run a web server (port 80), SSH (port 22) and MySQL (port 3306) at the same time because each listens on a different port. An address and port, such as 203.0.113.20:443 in this documentation example, identify a local or remote endpoint for the chosen transport. A program uses a socket to listen or communicate.
| Range | Name | Meaning |
|---|---|---|
| 0 – 1023 | Well-known ports | IANA system ports. Linux may require a capability below its configured unprivileged port threshold. |
| 1024 – 49151 | Registered ports | Used by applications (MySQL, MongoDB, dev servers) |
| 49152 – 65535 | Dynamic / ephemeral | IANA dynamic or private range. Operating systems may use a different configured range for temporary client ports. |
Common ports you must remember
| Port | Protocol | Service | Where you will see it |
|---|---|---|---|
| 20, 21 | TCP | FTP, with control on 21 and default server data port 20 in active mode | Legacy file transfer (avoid; insecure) |
| 22 | TCP | SSH / SCP / SFTP | Logging in to EC2, copying files |
| 23 | TCP | Telnet | Legacy, insecure — never open |
| 25 | TCP | SMTP | Sending e-mail (AWS throttles port 25 by default) |
| 53 | UDP/TCP | DNS | Domain name lookups |
| 67, 68 | UDP | DHCP | Automatic IP assignment |
| 80 | TCP | HTTP | Websites (unencrypted) |
| 110 / 143 | TCP | POP3 / IMAP | Receiving e-mail |
| 443 | TCP | HTTPS | Websites using HTTPS over TLS |
| 3000 | TCP | Node.js / React dev server | Express apps, npm start |
| 3306 | TCP | MySQL / MariaDB | Database |
| 3389 | TCP | RDP | Windows Remote Desktop |
| 4200 | TCP | Angular dev server | ng serve |
| 5000 | TCP | Flask dev server | flask run |
| 5432 | TCP | PostgreSQL | Database |
| 6379 | TCP | Redis | Cache |
| 8000 | TCP | Gunicorn / Django dev server | Python apps |
| 8080 | TCP | Alternate HTTP / Tomcat / Jenkins | Java apps, proxies |
| 27017 | TCP | MongoDB | NoSQL database |
Security rule of thumb
For the public website in this lab, open 80 and 443 when those services are configured. For administration from your own device, scope SSH on port 22 to your current public IP. On other deployments, allow only the ports and sources your design actually needs. Application ports (3000, 5000, 8080) should sit behind a reverse proxy (Nginx/Apache), and database ports (3306, 27017) should never be open to 0.0.0.0/0.
Ravindra Bagale's Tip
Many students run their app on port 3000 or 5000 and then open 3000 to everyone in the security group. Don't do this! Keep the app on 127.0.0.1, put Nginx in front on 80/443, and in the security group allow only 22 (My IP), 80 and 443. And never open the database's 3306 to 0.0.0.0/0.
Ravindra Bagale's Tip – मराठी
बरेच students app 3000 किंवा 5000 port वर चालवतात आणि मग security group मध्ये 3000 सगळ्यांसाठी उघडा ठेवतात. असं करू नका! App 127.0.0.1 वर ठेवा, समोर Nginx 80/443 वर ठेवा, आणि security group मध्ये फक्त 22 (My IP), 80 आणि 443. Database चा 3306 तर कधीच 0.0.0.0/0 ला नाही.
Ravindra Bagale's Tip – हिंदी
बहुत से students app को 3000 या 5000 port पर चलाते हैं और फिर security group में 3000 सबके लिए खोल देते हैं. ऐसा मत करो! App को 127.0.0.1 पर रखो, सामने Nginx को 80/443 पर रखो, और security group में सिर्फ़ 22 (My IP), 80 और 443. Database का 3306 तो कभी भी 0.0.0.0/0 के लिए नहीं.
Lab
Chala, tumchya Linux machine var sudo ss -tlnp chalva aani konte ports listen hot aahet te liha. Pratyek port samor service che naav liha – varchya table madhun (22 SSH, 80 HTTP ...) match kara. Kontahi port table madhe nasel tar ss chya shevatchya column madhe process che naav bagha.
Give each service its own endpoint on a shared machine
Imagine a dairy’s training instance with an order website, an administrator’s SSH service, and a small inventory database. One computer hosts all three. When a browser asks to display the order page, the operating system needs a practical way to deliver that request to the web program. If a database client arrives next, its data belongs to a different program. The network address gets traffic toward the computer, and the transport protocol and port help the operating system deliver it to the right receiver.
Use three entries in the class notebook. The public order website accepts HTTPS at its front door. The administration service accepts an approved SSH connection. The inventory database accepts an approved connection from the application. A default port is a convention clients and servers can share. It helps a browser choose the expected destination without the visitor typing a number. The program still has to be configured to listen where the client expects, and the allowed network path has to match that configuration.
The phrase “the port is open” can be ambiguous during a lab. A network rule might allow traffic to TCP 443. A process might also be listening on TCP 443. One can be true while the other is false. Name your observation precisely: the source is permitted by a particular inbound rule, the socket is listening on a particular address or the authorized client actually received a response. Those statements become independent checkpoints rather than guesses about the whole website.
Write the destination as address, transport, port. It could be 127.0.0.1, TCP, and 8000 for a local practice app. A connection also has a client address and port. A configured endpoint can be shown as 127.0.0.1:8000. The operating system’s socket is the communication endpoint the program uses, and it can represent different states, such as a TCP listener or one established connection. A single port number does not name a unique application across all computers and protocols.
Choose an example change before thinking about security rules. The dairy runs a Python application listening on local port 5000, and a reverse proxy listens for customer HTTPS. The customer needs the proxy’s port. The proxy needs the app’s local port. If the admin changes the backend to 5001, update the proxy’s destination in the planned release and verify both sides. Visitors can keep using the same public URL while the backend port changes.
Read the source and destination ports in both directions
Use the paper endpoint 203.0.113.20:443 for the dairy site. The address is reserved for documentation. Suppose Asha’s laptop initiates a TCP connection from its local address 192.168.40.18 and a temporary port 51521. The request is aimed at TCP destination port 443. When the service replies on that exchange, its source is the service’s port and its destination is the client’s temporary port at the point where you observe it.
The client’s temporary source port is often called an ephemeral port. The operating system typically selects one from its configured range when the application asks it to connect without choosing its own local port. That setting differs across systems. If NAT translates the source address and port on an outgoing connection, a public server can see the translated values, not the original laptop’s local values. In a drawing, write the connection as it appears before and after the boundary instead of trying to use one port label for every observation.
Now give two customers different source connections to the same site. Asha might approach from 198.51.100.10:62001 and Ravi from 198.51.100.11:62001. The server can keep both apart because the complete connection addresses differ. Two customers can also share one outward IPv4 behind a translating router while its translated source ports distinguish their connections. The network stack uses a combination of the transport protocol, the two addresses, and the two ports to describe a flow. You may hear that combination called a five-tuple.
| Observation point | Source for this packet | Destination for this packet |
|---|---|---|
| Before the lab router translates the outbound request | 192.168.40.18:51521 | 203.0.113.20:443 |
| On the outside path after translation | 198.51.100.10:62001 | 203.0.113.20:443 |
| Reply approaching the outside of the translating router | 203.0.113.20:443 | 198.51.100.10:62001 |
| Reply delivered to the original laptop | 203.0.113.20:443 | 192.168.40.18:51521 |
In your notebook circle the incoming destination port at the side you are debugging. The server’s application needs to accept the traffic aimed at its service port. A stateless filter on the return path can need a rule for the destination ephemeral port seen at that boundary. If you write both sides as “port 443” you can miss the actual return destination. If you record which network device sees each packet, the different numbers stop looking like contradictions.
Choose the transport that the application actually uses
TCP and UDP represent two ways to carry application data using the Internet Protocol. TCP sets up a connection and supplies an ordered byte stream with mechanisms for delivery and retransmission. A web browser can use TCP to communicate with an HTTPS service when the configured protocol uses TCP. SSH normally also uses TCP. The stream can deliver its data in pieces to the program, so an application such as HTTP has its own rules for recognizing where a message begins and ends.
UDP sends individual datagrams. It does not bring TCP’s built-in connection setup and ordered stream behavior. A program can build additional behavior above it. For example, QUIC runs over UDP and can support the reliable streams used by HTTP/3. This is the practical reason that the shorthand “HTTPS uses 443” needs more context for network policy. For a TCP HTTPS lab, allow the intended TCP port. If the service deliberately supports HTTP/3, check the service’s UDP requirements and its compatibility behavior as a separate configuration.
A service can also use more than one transport. DNS commonly uses UDP, and DNS can use TCP for supported cases. A firewall that allows only UDP 53 can leave some DNS operations failing. Read your actual program and network requirements before choosing either transport. If a troubleshooting step tests TCP 53, it establishes something about the TCP path. It does not test the UDP path merely because the number matches.
The operating system can hold a TCP and a UDP socket on the same local address and numeric port as different endpoints. Think of them as two separate sets of numbered delivery slots. A conflict for a second TCP listener on an address does not imply a conflict with a UDP receiver that uses the same number. Actual socket sharing and reuse can depend on settings and operating-system behavior. For a beginner lab, have one process per transport-and-address choice and inspect the socket table to see which protocols are present.
What evidence can you get in each case? An established TCP connection confirms the TCP exchange reached something that accepted it. A UDP sender can pass a datagram to the operating system without waiting for the other program to confirm receipt. For a UDP service, use a meaningful application request and response or an authorized service log, rather than interpreting an empty terminal as proof that the app received the data. The local socket lab below lets you observe both types with a receiver you control.
Use default values as a starting point for a check
Ports use a 16-bit field. It can represent numbers from 0 to 65535. The IANA registry groups port numbers into system, user, and dynamic or private ranges. These groupings organize assignments. They do not tell you which ports an operating system currently selects for a client or which service is running on your own server. Port zero has a special role as a binding request in many socket APIs: asking for local port zero can tell the system to allocate a suitable available port. Read back the chosen value before trying to connect to it.
On many Linux systems low-numbered ports require privileges or a service capability. The exact threshold can be configurable per network namespace. Let the operating system’s report and your service manager tell you what applies in the environment. Use a high-numbered local test port in the practice and avoid raising privileges just to make a teaching program work. In a real deployment a managed proxy or service configuration can hold the public listener while the app runs as a less privileged user.
Defaults still help a beginner. The browser normally uses port 80 for a plain HTTP URL and port 443 for an HTTPS URL, subject to how the application and transport work. SSH clients commonly choose 22. An ordinary MySQL service often listens on 3306. A different configured number can be entirely valid. If your training service listens at 127.0.0.1:8080, opening http://127.0.0.1/ without a port tries the HTTP default. Change the test URL to match the service you started.
Use a quick verification table when following a guide. Record the default mentioned in the guide, the actual configured value, and the condition that confirms it. On an approved Linux host, ss -ltn can show TCP listeners using numeric ports. Compare it with the app’s startup log. For a browser test, inspect the actual URL and its scheme. If a table says that a server on port 8000 is often used for a development framework, the table supplies a clue. The running process and expected response are better evidence of what is actually on that socket.
Choose the interface where the server waits
A listening address defines which local endpoints can receive a connection. Use 127.0.0.1:5000 for an app that should receive requests only from the same host in this IPv4 practice. Nginx can run on the same server and make an internal request to it. For a private application target called by a separate load balancer, the target needs to listen on an address reachable on the intended private interface. Scope its network permission to the caller in the architecture. Starting the program on loopback alone does not let a different machine reach it.
When a listener shows 0.0.0.0:5000, that commonly means an IPv4 wildcard bind on the local host. Read it as accepting connections on the local IPv4 interfaces that can reach that socket. It does not prove those interfaces are publicly routed or that a security rule permits the request. An IPv6 listener may show [::]:5000. Whether a particular IPv6 wildcard socket also accepts IPv4 can depend on system and application settings. Test the address family you intend your customers to use instead of assuming both are covered.
Suppose the dairy chooses a public HTTPS front door and an internal app. The proxy reads the listener for the public port and the upstream target’s address and port. A developer starts an updated web app and a second copy tries to use the same TCP endpoint. The operating system can reject the bind because the address is already in use. Before stopping anything, check which process owns the listener and which release should be active. A production deployment can perform a controlled restart or switch upstream targets. In your local lab use an unused high-numbered port for the second practice process.
A TCP listener and an accepted connection are separate objects. Many clients can connect to one listener. The operating system can place waiting connection requests in queues and the application accepts and services them. A service under load might have a listening socket but still struggle to accept new clients quickly. The socket table is one checkpoint, and successful real requests measure another part of service health. Use a controlled test instead of interpreting a single listening row as evidence that every visitor can complete an order.
Read the socket table and match it to a real request
On Linux, start with two read-only commands on a host you administer. The first lists listening TCP sockets. The second looks at UDP socket information with numeric addresses. Process details can be limited for another account’s processes. Ask the service owner through your normal access path when you need to confirm those details. In the student lab you can inspect your own process and use the app log rather than reading unrelated workload information.
ss -ltn
ss -lun
In the TCP result, find the local address and port. If your test program said it is listening on 127.0.0.1:8000, locate that exact row. If it is absent, check which machine ran the command and whether the program started successfully. If you see a wildcard or the port number is different, inspect the app’s current configuration. In the UDP output you can see a bound receiver even though UDP does not have the same connection state machine as TCP.
Run a real authorized request after the socket inspection. Use curl -i http://127.0.0.1:8000/ only when you have started your own HTTP lab service on that port. A successful status and the expected marker show that something answered and that it served the right test content. The result can still differ for the public hostname, where the browser selects HTTPS and reaches a different interface or proxy. Label the host, address, scheme and destination port with every recorded result.
Consider a server process listening on a private address, a load balancer health check on another port, and a visitor requesting HTTPS on port 443. These are three different endpoints. If the visitor receives a load balancer error, compare the configured target port, its actual listener and its health-check protocol and path. In some designs the health check deliberately uses a different port. Verify the design instead of forcing the two numbers to be equal. A healthy response from one test port does not establish that the live application route works.
Observe TCP and UDP on the same local port
Use Python 3 and an ordinary account on your own computer. The exercise binds only to IPv4 loopback. It sends two one-byte messages between sockets in one short-lived process. It creates no cloud resources and does not need administrative access. Open the Python interpreter, or save the snippet to a new temporary practice file and run it. Predict whether the TCP listener and UDP receiver can use the same numeric value, and which ports the two sending clients will choose.
import socket
host = "127.0.0.1"
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as listener, \
socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as inbox:
listener.bind((host, 0))
port = listener.getsockname()[1]
inbox.bind((host, port))
inbox.settimeout(2)
listener.listen(1)
listener.settimeout(2)
print("Shared local number:", port)
with socket.create_connection((host, port), timeout=2) as client:
connection, tcp_peer = listener.accept()
with connection:
connection.settimeout(2)
client.sendall(b"T")
print("TCP received:", connection.recv(1), "from", tcp_peer)
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sender:
sender.sendto(b"U", (host, port))
message, udp_peer = inbox.recvfrom(32)
print("UDP received:", message, "from", udp_peer)
The first line of output prints the numeric port chosen for the local TCP socket. The code asks the system to select it by binding that socket to port zero, then reads it back. The UDP socket uses the same number with UDP. Two different endpoint types can therefore coexist at that loopback address. The demonstration leaves the chosen number to the operating system instead of guessing a currently free listener port on your computer.
The TCP part makes one connection, lets the listener accept it and sends T. It reads one byte on the accepted socket and prints the peer address and client port. The UDP part sends U as a datagram and prints the tuple reported by the receiver. Each peer should be at 127.0.0.1, with a sender port selected for that socket. The exact numbers are not important. Run it twice and notice that the destination number and the clients’ temporary values need not stay fixed across runs.
If the UDP bind unexpectedly reports that the number is already in use, let the first attempt end, then run the complete snippet again. An automatic TCP allocation does not reserve the corresponding UDP slot. The short timeout prevents the exercise from waiting indefinitely. If the lab reports a timeout, check that every send and receive line was copied correctly before trying again. The socket contexts close after the snippet ends. If you saved a practice file, remove only that file when you finish. Keep no test process running in the background.
The useful observation is the mapping of protocol and port. Saying “we used port 60000” alone would fail to describe this test. Both protocols can have that number, and the operating system supplies their data to different sockets. In an AWS firewall exercise, treat the protocol and port as a pair, then check the actual source and destination as well. Use the lab’s observed output to explain why a successful TCP check cannot substitute for an intended UDP check.
Scope public and private permissions to the planned callers
Let the dairy choose a public HTTPS Application Load Balancer that forwards to a private app on TCP 8080. This design places TCP 443 on the public front door. The private app allows TCP 8080 from the expected load balancer’s security group in that VPC. The database allows its own service port from the app’s security group. Write those three connections down before opening any rules. A client’s request to TCP 443 does not mean the browser should also be able to connect to the private application port.
If SSH access is needed for administration, make it a separate decision. A disposable direct-admin lab may use its owner’s current public IPv4 with a /32 rule on standard TCP 22, if that is the approved path. A private application can use organization-approved remote access without adding a public SSH listener. Choose a narrow allowed source that matches the actual administration design. If a laptop changes networks, update the permitted path through the approved process rather than replacing a specific source with every IPv4 address.
Look at the database next. The team might be tempted to add an outside rule for TCP 3306 when the public page cannot save an order. Before doing that, ask who is meant to call the database. In this example, only the app is the database client. Verify the app-to-database path and login from that approved app role. The website’s public entry point can remain healthy while this separate private path needs repair. Opening a broad database port does not give the application the correct credentials or query.
Write the desired flow out before editing a security group or network ACL. Security groups are stateful and account for replies to an allowed tracked connection. A stateless ACL evaluates the directions separately. In the public TLS example, the server’s incoming packet has destination TCP 443. Replies can have a destination in the client’s temporary range. On a separate private link, the load balancer itself uses a source port when it connects to the application. Keep the two links separate, and read what each filter actually observes. A single pair of public client and server port numbers cannot describe the load balancer’s own backend connection.
Follow a backend port change through the dairy release
The developers move a packing API from port 8080 to 8081. In their terminal they can call the new port. The operations team says customer HTTPS still connects, but the packing page returns an upstream error. Start with the interface you know. The customer reaches a web component over the public endpoint. The local test proves the app responded on port 8081 on the server where that test ran. What remains is the promised proxy or load balancer path to the new listener.
Make a side-by-side list with the old listener, new listener, target configuration, health check port and expected security group path. Verify the new release’s actual bind address. If the proxy is on a different host but the app binds to 127.0.0.1:8081, the local app test will work and the separate caller will still have no reachable listener. If the app uses its intended private address but the security group accepts only port 8080 from that caller, the new target path also fails.
Choose a staged lab procedure. Start the new listener alongside the old one on a distinct available endpoint when the application supports that rollout. Test it from the intended private caller, confirm a health response, and move a controlled request path. Keep the working version available until the new route works. Make the switch according to the team’s change plan. Repeat the actual public request with the same path and inspect the version marker or safe response field. A status of 200 from an unrelated route would be weak evidence.
Consider a second version of the incident. Both the old and new backend listeners are reachable, but some clients continue seeing features of the old version. Check which backends are still registered and how the name or caching policy can affect their requests. A cache can supply older content even after a network rule was changed. A target group can contain mixed releases during an intentional rollout. The port is one part of the explanation. Correlate the version marker, target health, request time and deployed rule before editing anything else.
Explain three different failures without widening every rule
For the first lab symptom, a client connects to the correct machine but gets an immediate refusal for the application port. Check the listener on that machine. It may be stopped or bound on a different address. A device can also explicitly reject traffic, so record the observed reason and available authorized logs. Reinstalling the client or opening every inbound port would leave the wrong bind unfixed.
For the second symptom, a client’s connection hangs. Check the current destination and the path in both directions. Make sure the intended rule is attached to the relevant interface and permits the actual source. A stateless ACL or another control can drop a reply, which produces a different symptom from a clear application response. Use the transport and port the application expects. A test of TCP 22 showing SSH is alive still leaves the separate app on TCP 8080 unverified.
For the third symptom, a browser shows an HTTP error after a successful secure connection. The web component supplied a response. Read its status and the service’s logs before assuming the network dropped the attempt. An HTTP 404 can indicate a missing path. A proxy can return 502 when an upstream response fails in particular ways. A service can also report temporary unavailability. Look at the documented meanings within your own front door and app. The exact response helps you choose the next dependency to inspect.
Capture each observation without editing production. For a safe classroom simulation you can change one loopback listener variable and see the result in seconds. Choose a different known HTTP path or stop just your own process. The evidence will show whether the request got a connection, an application response, or the intended content. After repeating the test with the right endpoint, write a three-line incident note with the first failure and the supported explanation.
Use one listener to serve more than one website or path
A single listening port can serve multiple sites. Imagine the dairy has orders.dairy.example and packing.dairy.example on one HTTPS entry point. An incoming connection reaches the same numeric port. During TLS the configured front door can select the certificate for the requested service name, and after TLS it can use the HTTP host information and requested path to decide who should handle the request. The numeric port delivered traffic to the service that knows how to make the remaining choice.
Draw two routes under the ordering host. The first is /assets/logo.svg and the second is /api/orders. The same front door can deliver the static content to the first request and forward the second to an application. Read the public endpoint on the left of your drawing, then add the upstream endpoint on the right if a second connection is needed. The customer never needs to know a private application port that sits behind the route. Write which part of the request the routing decision uses, so your network design and web configuration document different layers of the same request.
Now try a new release example. Visitors get a successful 200 when requesting the ordinary homepage, but the checkout page shows a different organization’s logo. A TCP check to 443 will only show that the public port responds. Examine the hostname the user actually entered and what the listener chose for that name. Check the HTTP rule and document root for the requested path. The lesson is practical: use both the expected status and expected content when proving that the right service received the connection.
A website can serve several paths while using one security group rule for its public entrance. A security group can match protocol, port and network source. A web proxy or application reads HTTP information to control routing and user access. Restrict sensitive actions in the application using its authorization design. For example, a permitted request to an inventory URL still needs the authenticated employee who can see those records. Drawing one arrow for the shared listener does not say which operations that visitor may perform.
When two sites share the listener, make one known synthetic result per site for a health or test request. Label responses with safe information like a course version or module name. Test both hostnames after changing one. Check that the unaffected hostname still returns its own intended page. This small habit protects adjacent services on a shared server and makes it easier for somebody else to verify the outcome.
Observe connection state without confusing it with a service permission
A TCP socket table can show a listener even when nobody is using the service, and an established socket when a client has connected. The listener remains ready for new requests while the accepted connections have their own client addresses and ports. Think of the dairy order desk with a public counter and separate orders already in progress. A rush at the counter changes how many work items exist without changing the counter’s number.
Consider two entries while testing a known application. One says the local process listens at 127.0.0.1:8000. Another says one local client at 127.0.0.1:51521 is in an established exchange with it. On the same computer, many completed exchanges can also leave temporary connection state as the transport closes them. A socket table is a momentary picture. Ask whether you want evidence of a listener, an open exchange, or an application response, then choose the observation that supplies it.
This matters when a programmer sends many calls to the same backend. Each new TCP connection needs a usable local endpoint, and the network can need translation entries along the path. At modest lab load the operating system normally chooses an unused client-side port. At larger scale, the rate of new connections and the resources required to track those connections can become part of the performance problem. Use connection reuse from a supported client where it fits the application and investigate measured errors before changing any system-wide port setting. A beginner can understand this without tuning the kernel: connecting thousands of times is more work than reusing an appropriate established connection for several requests.
In a read-only lab check, make an ordinary request to your own HTTP app and inspect the local socket table while the request is active. A very fast request can end before you see its established row. That timing explains why the app log and socket table answer different questions. Use a controllable test and record the event time. If you need a visible established connection, the earlier Python socket example gives you a process whose lifetime you can follow. Add a deliberate short pause to the practice in a separate local script only, then remove it after the observation.
Separate connection reuse from NAT. A web client may reuse one TCP connection for multiple HTTP requests according to its protocol. A NAT device can track translation state for that connection. The port can remain the same for those requests because the network connection remains in use. Changing a URL path does not necessarily open a new socket. If the lesson’s HTTP request results differ, inspect the application path and request, while the connection table provides independent evidence of the transport.
Apply the port model to your own plan
- Make a protocol-aware service list. Write three expected endpoints for a web service, SSH administration and a database. Include the transport, source and destination. A strong answer provides a known public website path and limits the private service to its intended caller.
- Follow an ephemeral reply. Draw a client using TCP
52010to reach server TCP443. Label both ports on its reply. Then move the observation to the outside of a translator that picked client port63001. Explain which value applies on each side. - Predict an address bind mismatch. A test app on one host reports
127.0.0.1:5000. A proxy on a different host attempts its private IP at port 5000. State which check can work and why the other path needs the proper backend bind and security policy. - Read an existing socket listing. On an authorized lab host, identify the local address, transport and port of one practice listener. Request the intended service and record the response. If the listener is loopback-only, record that choice instead of trying to make it public.
Interview questions and worked answers
How can two customers connect to the same HTTPS listener at the same time?
The server has a common listening port. Each accepted connection is distinguished using both endpoints and the transport. Clients have addresses and temporary source ports. Even when the server port agrees across the requests, the complete connections differ.
Why can TCP and UDP use the same port number?
They are separate transports with separate socket spaces. The network stack uses the protocol as well as addresses and numbers when it delivers data. A TCP rule for that number does not allow a UDP request.
What does “connection refused” suggest that an HTTP 404 does not?
A refusal happens at the connection layer and can indicate that no process accepted that endpoint or that a device rejected it. A 404 is a response from an HTTP service to a request. It sends you to investigate service selection and the requested path.
When do replies need explicit ephemeral port consideration in AWS?
For stateless rules such as network ACLs, inspect the ports at the point of filtering in both directions. A server sends replies to the connected client’s source port. A stateful security group handles replies to permitted tracked connections differently.
What do you check when a web app changes from port 8080 to 8081?
Verify the new listener and bind address, the proxy or target group’s port, the approved path and any health check. Test privately and then through the normal site URL. Match the response to the intended version so an old listener cannot mask the change.
Why avoid using a public database rule to investigate a failed web form?
In the designed path, the application is the database client. Test its network connection, identity and query from that tier. Giving outside machines an unrelated port path adds exposure without confirming that the app can read or write its intended data.
Check the correct connection detail
You reach TCP 443 from source TCP 52010. Before any translation, where is the server’s reply aimed? Choose 22, 443, or 52010.
Answer and reasoning
52010. That is the client’s local port for this flow. The server’s own service port is the reply’s source.
One trusted client needs to send UDP to an application on port 9000. Does a TCP-only rule for 9000 meet the request?
Answer and reasoning
No. The numeric value agrees but the transport is different. Check the intended UDP listener and network permissions.
A process binds to
127.0.0.1:8000on EC2. Which test fits the binding: a local request from that EC2 shell or a direct public connection from a different machine?Answer and reasoning
The local request. Loopback belongs to the machine making the call. A separate host needs an approved address and network path to a listener reachable from it.
Two different page paths on the same HTTP listener return 200 and 404. Which checked pieces were shared?
Answer and reasoning
The host, transport port, network path and responding HTTP service can be the same. The service chose a different result based on the path requested.
Which proves the complete intended app path: a security group rule exists, a socket is listening, or an authorized end-to-end request returns the expected status and content?
Answer and reasoning
The authorized request returning the expected result proves that particular path and operation worked. The other observations test only individual pieces.
Revision cards
- Service endpoint
- Confirm address, transport and port. A port number by itself is not a full destination.
- Client source port
- A temporary local port distinguishes the client’s connection. The server replies to that port at the observation point, subject to translation.
- Listen versus allow
- The running process provides a listener. The network policy permits the intended traffic. Verify both and make a real request.
- Loopback bind
- Loopback is for the current host. A same-host proxy can call it, while a separate host needs a permitted reachable endpoint.
- TCP and UDP
- The transports have their own socket and port spaces. Use the transport the actual protocol requires.
- Backend port changes
- Test the correct bind address, target selection, health check and security rules together. Confirm the intended version through the user’s normal entry point.
Technical references
- IANA service name and port registry
- Port number registration and ranges, TCP specification and UDP specification
- QUIC transport and HTTP/3
- DNS transport over TCP and HTTP semantics
- Linux networking settings and local port ranges
- Python socket library and socket programming guide
- EC2 security group connection tracking and network ACL rules
- Load balancer target checks and application load balancer troubleshooting