Separate network environments

A network namespace provides its own interfaces, routes, port bindings and other networking state. Even the loopback interface is separate. Two environments can each listen on port 80 without competing for the same binding, if they use separate network namespaces. Different hostnames alone do not provide this separation.

The physical CPU, RAM and any shared physical-network capacity remain shared. Namespaces do not impose consumption limits or automatically provide external connectivity.

Build the source’s virtual cable

A veth pair is created as two connected virtual interfaces. Traffic transmitted through one is received through the other. Moving one endpoint into a different namespace preserves the pairing.

PDF pages 20-22 illustrate:

sudo ip netns add ns1
sudo ip link add name veth0 type veth peer name veth1 netns ns1
Host network namespace          Namespace ns1
         veth0 <--------------> veth1

Another source variant creates both endpoints in the host namespace and then moves one:

sudo ip link set veth1 netns ns1

These are alternative construction paths, not instructions to create the same pair twice. Interface names are scoped to their namespace. The slides also show moving an endpoint using a process’s externally visible PID to identify an existing namespace.

Connection versus working IP connectivity

The source output shows new interfaces and the new namespace’s loopback as DOWN. The cable exists, but normal IP traffic needs active interfaces and suitable addressing. Outside connectivity additionally needs routing/bridging and any required translation/firewall policy. Creating a namespace or pair does not itself configure Internet access.

Inspect the namespace without an interactive shell

ip link
sudo ip netns exec ns1 ip link
sudo ip -n ns1 link show

The first lists host interfaces. The second executes a command with ns1’s network environment. The third is a direct namespace-targeted ip inspection. Namespace separation explains why host output can list veth0 without listing veth1 as a local interface.

The PDF’s generalized root/parent visibility wording needs qualification: network namespaces do not have PID-style ancestor visibility. Host-side permission to inspect or enter another namespace is different from automatically seeing all its interfaces in the current network view.

Check the peer from the host

ip link show veth0
sudo ethtool -S veth0

The PDF shows output shaped like veth0@if2 ... link-netns ns1: the host endpoint reports a peer interface index and namespace. ethtool can expose peer_ifindex. An index must be interpreted in the peer’s namespace; cross-namespace output may show its index rather than resolve its name. To confirm that index 2 is called veth1, target ns1 with ip -n ns1 link show. Linux veth manual.

This establishes pairing, not proof that addressing, routes and firewalls permit an application’s traffic. The cable and the network configuration answer different questions.

For registered names, ip netns list lists named namespaces and sudo ip -all netns exec ip link runs inspection in each named namespace. This does not include the host’s default namespace or every unnamed process-created namespace. ip-netns manual.

Retrieval practice

Why is the other endpoint missing from the host’s local interface list? It belongs to another namespace; query that namespace or use the visible endpoint’s peer metadata.

Two endpoints are paired but cannot exchange an IP packet. What next? Check interface state, addresses and the intended path; pairing alone is insufficient. No diagnostic has actually been run for these notes.

Do separate UTS hostnames let two services bind the same IP/port in one network namespace? Generally no. UTS changes system names, not the shared network binding space.

Lecture 06 - Lightweight Virtualization - Cgroups and Namespaces, PDF pages 11-13 and 19-25. Peer checks and administration-versus-visibility distinctions expand the source commands. The tcpdump example on page 24 means capturing within the chosen network namespace, not all network namespaces automatically.