Read a sample: 1. The Multihomed Host: What You Are Trying to Find
A Linux host can have several IP addresses and several ways to reach a destination. A laptop might be connected to a wired network and a wireless network at the same time. A server might have separate interfaces for application traffic and management access. A virtual machine might have one connection to an internal network and another to a network that reaches the internet.
In each case, a common question sounds simple: Which IP address will this host use?
The useful answer begins with another question: Use for what destination, under what conditions? An address assigned to the host is not automatically the source address of every connection it makes. The destination matters, as do the selected route, the available addresses, and sometimes the application’s own choices.
This chapter establishes the vocabulary and the investigation sequence used throughout the book. The goal is not to memorize a single command, but to learn how the pieces of evidence fit together.
Consider a Linux workstation named atlas. It has two active network interfaces:
- enp1s0 is connected to a wired network.
- wlp2s0 is connected to a wireless network.
For this example, assume the host has the following IPv4 configuration:
The addresses in this example are used for documentation. Treat the networks as a hypothetical lab rather than public destinations to test.
The workstation also has routes that, in simplified form, say:
- The network 192.0.2.0/24 is reachable through enp1s0.
- The network 198.51.100.0/24 is reachable through wlp2s0.
- Other destinations can use a default route through gateway 192.0.2.1 on enp1s0.
Now suppose a user on atlas wants to connect to 198.51.100.44. That destination is on the wireless network in this example. A route lookup would ordinarily select wlp2s0, and the likely source address would be 198.51.100.20.
If the user instead connects to 203.0.113.80, the destination does not match either of the two directly connected networks. Under the simplified routing arrangement above, the default route sends the packet through enp1s0 toward 192.0.2.1. The likely source address is then 192.0.2.10.
The same host therefore has two assigned IPv4 addresses and, depending on the destination, may use either one as a source. The configuration permits a more useful statement than “the machine’s IP address is 192.0.2.10.” It permits a destination-specific prediction:
> For a lookup to 203.0.113.80 in this example, the expected outgoing interface is enp1s0, and the expected source address is 192.0.2.10.
That statement is still a prediction. An application can introduce additional context, and the actual configuration may differ from the simplified example. But the statement identifies what was investigated and what result is expected.
A network interface is a point through which the Linux networking stack can send or receive traffic. Some interfaces correspond to physical devices, such as an Ethernet adapter or wireless adapter. Others are virtual: a virtual machine interface, a bridge, a tunnel, or the loopback interface can all appear in the interface list.
An interface name identifies the interface on that system. Names such as enp1s0 and wlp2s0 are examples, not names you should expect on every host. Your system might use different names.
The existence of an interface does not establish that it is ready to carry useful traffic. An interface can be administratively disabled, lack a physical or wireless link, or have another condition that prevents normal communication. Conversely, seeing an interface in an active state does not prove that a remote service is reachable.
An initial view of the host’s interfaces is available with:
text
ip link show
This command reports link-layer information and interface state. It answers questions such as “Does the interface exist?” and “What state does Linux report for it?” It does not, by itself, answer which source IP address will be used for a particular destination.
Chapter 2 examines the state information in detail. For now, keep the distinction clear: an interface is a potential path, but its name alone is not an IP address, a route, or proof of connectivity.
An IP address is assigned to an interface so that the host can participate in IP communication. In the example, 192.0.2.10 is assigned to enp1s0, and 198.51.100.20 is assigned to wlp2s0.
A useful starting command is:
text
ip address show
A shortened example of the relevant IPv4 output might look like this:
text
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWERUP> mtu 1500 state UP
inet 192.0.2.10/24 scope global enp1s0
3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWERUP> mtu 1500 state UP
inet 198.51.100.20/24 scope global wlp2s0
The word inet identifies an IPv4 address in this output. The /24 is a prefix length; it helps describe the network associated with the address. Chapter 3 covers address output, and Chapter 4 works through prefixes and directly connected networks.
The important observation here is that this output is an inventory of assignments. It shows that the host has these addresses on these interfaces. It does not say that 192.0.2.10 will be the source of every packet, or that the first address displayed is preferred for all destinations.
An interface can also have more than one address. For example, enp1s0 could have both 192.0.2.10/24 and 192.0.2.11/24. Merely knowing that a route uses enp1s0 would then be insufficient to identify the source address without more evidence.
Likewise, a host can have IPv4 and IPv6 addresses at the same time. The principles of inspecting the destination, route, and source remain useful for both, but IPv6 has additional scope and address-preference considerations. Chapter 9 treats…