Read a sample: 1. Before You Change the Network
A Linux machine can have a network address and still be difficult to reach. It might be connected through the wrong interface, using an unexpected gateway, or relying on a name server that does not answer. It might also be working perfectly until someone changes the connection that carries their remote terminal session.
This book follows a more deliberate path. Before requesting a new address or changing a DHCP setting, you will identify what the machine is already doing and preserve enough evidence to recognize what changed. That baseline will make later troubleshooting faster, and it can help you recover if an experiment has an unexpected result.
The commands in this chapter are primarily observational. They display the current state rather than deliberately modifying it. Even so, use an appropriate lab and follow the access rules for any network you inspect. Network output can reveal addresses, interface identifiers, domain names, and other information that should not be posted publicly without review.
A virtual machine is a convenient place to begin. It gives you a Linux guest whose network configuration you can inspect without experimenting directly on your main workstation. A spare physical computer can work equally well if you have local access to its screen and keyboard.
For a first lab, aim for these conditions:
- You can open a local console to the Linux machine, even if its network connection fails.
- The machine has a network adapter connected to a lab network that provides IPv4 addresses through DHCP.
- You have permission to inspect and change the guest’s network configuration.
- You know how to restore the virtual machine or its network settings if necessary.
- You can identify whether the lab contains anything that depends on the machine staying online.
Virtualization platforms offer different networking modes. A guest attached through a virtual NAT network commonly receives configuration from a service provided by the host or virtualization platform. A bridged guest may appear as a separate device on the physical network. An isolated network may have no DHCP service unless you provide one. These arrangements affect what you should expect to see, so check the settings of your own platform rather than assuming that every virtual adapter behaves the same way.
A snapshot or backup can be useful before a configuration exercise, but it is not a substitute for understanding recovery. Know how to reach the console and how to restore the relevant configuration. Also consider what else a snapshot rollback might undo, such as files created since the snapshot.
Do not set up a DHCP server on a shared network merely to make the examples work. An unintended server can affect other clients. If you need to provide DHCP yourself, use a suitably isolated lab and confirm how that isolation works.
If you are connected over SSH, the interface you want to investigate may be the same interface carrying your session. Restarting a network service, deactivating a connection, changing an address, or releasing a lease can interrupt that session. A command that appears to hang may have succeeded in removing the network path back to you.
The safest place to practice disruptive changes is a lab machine with a working local or out-of-band console. On a virtual machine, that usually means the console supplied by the virtualization platform, not another SSH window. On physical or hosted equipment, an out-of-band management console may be available; verify that you can actually use it before you need it.
For a remote system that must remain available, pause before making any change and answer these questions:
1. Which interface and route carry my current connection?
2. Is there a tested console or independent management path if that connection drops?
3. What specific configuration will I change, and how will I restore it?
4. Is there an approved maintenance window and someone who can assist if needed?
5. How will I verify the result from both the machine and the remote side?
A second SSH session can be useful for observation, but it is not an independent recovery path when it uses the same network. Likewise, a terminal multiplexer may preserve a running shell after a disconnect, but it cannot restore a broken route or give you access to the screen.
If no recovery path exists, collect evidence and defer disruptive changes. Later chapters describe ways to refresh connections and leases; those procedures belong on a system where you can tolerate interruption or recover from it.
Examples in this book show commands in fenced blocks. Type the command itself; do not type a shell prompt such as $ or #. Output examples are illustrative. Interface names, addresses, service names, and formatting will differ among systems.
Most inspection commands in this chapter can be run as an ordinary user. Some systems restrict access to particular logs or configuration details, and later configuration commands will commonly require administrative privileges. When a command needs elevated privileges, examples use sudo:
bash
sudo command
Your account must be authorized to use sudo, and the system may ask for your password. If your environment uses a different administrative procedure, follow its rules. Avoid opening a privileged shell simply because a command might need it; using privilege deliberately makes it easier to see which operations can alter the system.
A command that produces no output does not always mean something is broken. It can mean that no matching object…