Back to Blog
Lesson 32 of the Linux: Linux Command Line for Developers course
LinuxAugust 19, 20264 min read

Mastering Linux IP Configuration: A Developer's Guide

Learn how to inspect IP addresses, understand subnets, and identify gateway settings using the ip command to master your server's network configuration.

linuxnetworkingipbashserver-administration
A close-up view of PHP code displayed on a computer screen, highlighting programming and development concepts.

Previously in this course, we explored Network Interfaces Overview: Managing Linux Connectivity, where we learned to identify hardware interfaces using ip link. In this lesson, we move from the physical layer to the logical layer by configuring and inspecting IP addresses, subnets, and routing.

Understanding IP Addressing and Subnets

At its core, an IP address is a logical label assigned to a device on a network. However, an IP address alone isn't enough; your server needs to know which part of that address identifies the network and which part identifies the specific host. This is where subnets come in.

A subnet mask (or CIDR notation) defines the "network portion" of your address. If you are on a home network, your devices likely share the same network prefix but have unique host identifiers. Understanding this allows you to determine if a destination is "local" (reachable directly) or "remote" (requiring a gateway).

Inspecting Configurations with ip addr

The modern standard for viewing network details on Linux is the ip command suite. While older tools like ifconfig are still occasionally found in legacy scripts, ip addr is the industry-standard tool for modern server administration.

Run the following command in your terminal:

Bash
ip addr show

You will see output for each interface (like eth0 or lo). Look for the inet line. It will look something like this:

inet 192.168.1.50/24 brd 192.168.1.255 scope global eth0

  • 192.168.1.50: Your assigned IP address.
  • /24: The CIDR (Classless Inter-Domain Routing) notation. This is shorthand for a subnet mask of 255.255.255.0, meaning the first 24 bits define the network.
  • brd 192.168.1.255: The broadcast address for your network segment.

Identifying the Gateway

If your server needs to talk to the internet or another network, it sends traffic to a "Gateway"—usually your router. You can identify the default gateway by inspecting the routing table:

Bash
ip route show

The line starting with default is the key:

default via 192.168.1.1 dev eth0 proto dhcp metric 100

  • default via 192.168.1.1: This tells your system that any traffic not destined for the local network should be sent to the device at 192.168.1.1.
  • dev eth0: The physical interface used to reach that gateway.

Hands-on Exercise

To verify your understanding, perform these steps on your server environment:

  1. Run ip addr and identify the IP address of your primary network interface.
  2. Calculate the network range if your subnet mask is /24. (Hint: For 192.168.1.50/24, the network is 192.168.1.0).
  3. Run ip route and note the IP address of your gateway.
  4. If you have a project configuration file (created in Project Task: Creating Initial Configs in Bash), add a comment line with your current IP address for documentation purposes.

Common Pitfalls

  • Confusing /24 with /32: A /32 subnet means the server is isolated to its own IP address and cannot see anything else on the local network. A /24 is a standard home/office network size.
  • Ignoring the Loopback: You will always see an lo interface with address 127.0.0.1. Do not attempt to reconfigure this; it is essential for internal system communication.
  • Assuming Persistence: Running commands with ip changes settings in memory (runtime). If you reboot, these changes are lost unless you have configured them in your distribution's network configuration files (like Netplan on Ubuntu or sysconfig on RHEL).

Frequently Asked Questions

Q: What is the difference between ip addr and ifconfig? A: ifconfig is part of the deprecated net-tools package. ip is part of iproute2, which is more efficient and supports modern features like network namespaces.

Q: How do I change my IP address? A: You can use sudo ip addr add 192.168.1.60/24 dev eth0. However, always modify your system's network configuration files to make the change permanent.

Q: What does "scope global" mean? A: It indicates that the IP address is valid for communication outside of the local host.

Recap

We have moved from simple interface discovery to understanding logical addressing. By using ip addr and ip route, you can now diagnose whether your server has a valid IP address and a route to the outside world—a foundational skill for any server administrator.

Up next: Testing Connectivity, where we use ping and traceroute to verify these paths.

Similar Posts