OS & Linux Engineering / LINUX NETWORKING & SERVICE DIAGNOSIS / OSX-029
Binding Mystery
Explore concept graphMateri
Misi: jelaskan mengapa host bisa memanggil
127.0.0.1:8080tetapi peer namespace tidak dapat menjangkau API melalui IP veth host.
Mulai: prediksi apakah server yang hanya listen 127.0.0.1 akan menerima koneksi ke target 127.0.0.2 dalam satu Linux namespace.
Host namespace cs101-peer namespace
127.0.0.1 (host lo) 127.0.0.1 (peer lo)
| |
TCP 127.0.0.1:8080 peer lo != host lo
|
10.200.30.1 (veth host) <---veth---> 10.200.30.2 (veth peer)
^
TCP bind 10.200.30.1:8080 + firewall/route allow
|
HTTP handlerDiagnostic sequence
ip -br addr
ip route
ip route get 10.200.30.2
ss -lntp '( sport = :8080 )'
curl --noproxy '*' --connect-timeout 2 http://127.0.0.1:8080/ip addr bukan ss: interface dapat memiliki IP walaupun aplikasi hanya mendengarkan loopback. 0.0.0.0 memperluas permukaan jaringan; pilih bind ke alamat interface spesifik bila itu sudah cukup. IPv6 harus diperiksa terpisah dengan ss -lnt4 dan ss -lnt6.
Konsep 1 / 3
Predict Linux IPv4 loopback and wildcard listening behavior without assuming remote reachability.
A healthy backend may work from host localhost while clients in a container or another namespace fail to connect.
Predict what happens if a Linux client connects to 127.0.0.2 while the server listens only on 127.0.0.1.
Intuisi utama
A TCP listener matches a destination IP and port within its network namespace. 127.0.0.1 is one local IPv4 loopback address; 0.0.0.0 is a wildcard bind for local IPv4 addresses, not a client destination.
Linux ip(7) distinguishes INADDR_LOOPBACK from INADDR_ANY. A listener on 127.0.0.1:8080 is not listening at the host's non-loopback interface IP. Binding 0.0.0.0:8080 accepts more local IPv4 destinations, but routes, firewall filters and namespace isolation still apply. IPv6 is a separate address family; verify actual -4/-6 listeners rather than assuming dual-stack.
Contoh bertahap
An HTTP server works on host localhost but not when addressed via host veth IPv4.
- Inspect ss -lntp '( sport = :8080 )'.
Mengapa: Local socket address distinguishes the listener from a running process.
Hasil yang diharapkan: 127.0.0.1:8080, rather than the host's veth address.
- Curl 127.0.0.1:8080 inside the host namespace.
Mengapa: The local destination matches the loopback-bound socket.
Hasil yang diharapkan: Local request succeeds when the server runs and policy allows.
- In a disposable lab, rebind to the host veth IP or 0.0.0.0.
Mengapa: The server now accepts a different set of local destination addresses.
Hasil yang diharapkan: ss shows the chosen address; remote reachability still depends on routing/filtering.
Konsep 2 / 3
Use ip addr, ip route, ss and curl as independent reachability observations.
A refusal, timeout or 5xx is ambiguous until interface, routing, bind and application boundaries are separated.
Run ip -br addr, ip route and ss -lnt; label what each command observes.
Intuisi utama
ip addr shows assigned interface addresses, ip route shows paths, ss shows sockets and curl probes the end-to-end connection. Each observes a different stage.
ip -br addr reports interface addresses; ip route get DEST predicts a route from the command's namespace. ss -lntp shows the process listening address and port, subject to permissions. curl targets an actual host/interface address, not 0.0.0.0. A refusal may arise from no matching listener or active reject; a timeout may indicate filtering or missing return path. Do not infer a root cause from the client error alone.
Contoh bertahap
A peer attempts http://10.200.30.1:8080 but the host service is only bound to localhost.
- Read host ip -br addr and ip route get 10.200.30.2.
Mengapa: Check that the host veth address exists and can route toward peer.
Hasil yang diharapkan: A veth address and connected route, independently of the server.
- Read host ss -lntp '( sport = :8080 )'.
Mengapa: The listener must match the destination IP and port.
Hasil yang diharapkan: 127.0.0.1:8080 is narrower than 10.200.30.1:8080.
- Read peer ip -n cs101-peer route, then test curl from the peer.
Mengapa: The peer has its own route table and must use host veth IP.
Hasil yang diharapkan: An observed connection error or HTTP response with an identifiable boundary.
Konsep 3 / 3
Demonstrate that peer namespace localhost is not host localhost, then prove an interface-specific bind correction in a disposable lab.
Containers and pods have independent network stacks; relying on host localhost can hide an otherwise healthy API from peers.
Check whether you have sudo and iproute2 inside a disposable Linux VM before creating any namespace.
Intuisi utama
Each network namespace owns its own lo interface, sockets and routes. A veth pair plus addresses creates a connection between two separate stacks.
ip netns add creates a named namespace. A veth pair can connect its interface to one left in the host namespace, with 10.200.30.1/30 on the host and 10.200.30.2/30 on the peer. A host service listening only on 127.0.0.1:8080 cannot accept a TCP request to the host's veth IP. Binding instead to the specific veth IP allows a match if routes and firewall policy permit. Creating netns and veth needs administrative privileges and must occur only on a disposable VM. The CI fixture checks 127.0.0.1 versus 127.0.0.2 in ONE namespace, not veth or peer isolation.
Contoh bertahap
A learner wants peer namespace cs101-peer to reach the host server at 10.200.30.1:8080.
- Create cs101-peer with ip netns add and a veth pair, assigning peer interface into cs101-peer.
Mengapa: Both network stacks need a link before peer traffic can reach the host.
Hasil yang diharapkan: Separate host and peer interfaces are listed by ip.
- Assign 10.200.30.1/30 and 10.200.30.2/30, and bring both veth links and the peer lo up.
Mengapa: Interfaces require addresses and operational state.
Hasil yang diharapkan: ip route in both namespaces reports the connected /30 network.
- Curl from peer to host veth IP with host bound to 127.0.0.1, then rebind host to 10.200.30.1 and retry.
Mengapa: Destination matching changes while the peer address stays constant.
Hasil yang diharapkan: The first connection has no matching listener; the second may succeed if filtering permits.
Referensi kernel dan iproute2
Sumber
Cross-domain connections
Curated relationships for this unit at G1. Proposed edges are suggestions, not prerequisites.
Dashed = proposed relationship; solid = reviewed connection. Only reviewed prerequisites constrain a learning path. Keyboard and text links remain available.