0
0
Linux CLIscripting~15 mins

ifconfig and ip addr in Linux CLI - Deep Dive

Choose your learning style9 modes available
Overview - ifconfig and ip addr
What is it?
ifconfig and ip addr are commands used in Linux to view and manage network interfaces. ifconfig is the older tool that shows network settings like IP addresses and interface status. ip addr is a newer, more powerful command that provides detailed information and control over network interfaces. Both help you understand and configure how your computer connects to networks.
Why it matters
Without tools like ifconfig or ip addr, it would be very hard to see or change your computer's network settings. This would make fixing internet problems or setting up networks confusing and slow. These commands give you clear, direct control over your network connections, which is essential for troubleshooting and automation.
Where it fits
Before learning these commands, you should understand basic networking concepts like IP addresses and interfaces. After mastering them, you can learn advanced network configuration, scripting network tasks, or using network management tools like NetworkManager or systemd-networkd.
Mental Model
Core Idea
ifconfig and ip addr are tools that let you see and change your computer’s network connections by showing and setting interface details.
Think of it like...
It's like checking and adjusting the settings on your car’s dashboard to see your speed, fuel, and change gears to control how it runs.
┌───────────────┐       ┌───────────────┐
│ Network Card  │──────▶│ ifconfig      │
│ (Interface)   │       │ (Old tool)    │
└───────────────┘       └───────────────┘
         │                      │
         │                      ▼
         │              Shows IP, status
         │                      │
         ▼                      ▼
┌───────────────┐       ┌───────────────┐
│ Network Card  │──────▶│ ip addr       │
│ (Interface)   │       │ (New tool)    │
└───────────────┘       └───────────────┘
                                │
                                ▼
                      Shows detailed info
                      and allows configuration
Build-Up - 7 Steps
1
FoundationUnderstanding Network Interfaces Basics
🤔
Concept: Learn what a network interface is and why it matters.
A network interface is like a door your computer uses to connect to a network. It can be physical, like an Ethernet port, or virtual, like a Wi-Fi adapter. Each interface has an IP address that identifies your computer on the network. Knowing about interfaces helps you understand what ifconfig and ip addr show.
Result
You understand that interfaces are the points where your computer talks to other devices.
Understanding interfaces is key because all network commands revolve around managing these connection points.
2
FoundationBasic ifconfig Command Usage
🤔
Concept: Learn how to use ifconfig to see network interface details.
Run the command 'ifconfig' in the terminal. It lists all active network interfaces with their IP addresses, MAC addresses, and status (up or down). For example, 'eth0' might show an IP like 192.168.1.10 and say 'UP' if connected.
Result
You see a list of interfaces with their current network settings.
Knowing how to quickly check your network status helps you spot connection problems fast.
3
IntermediateExploring ip addr for Detailed Info
🤔Before reading on: do you think ip addr shows less, the same, or more info than ifconfig? Commit to your answer.
Concept: ip addr provides more detailed and flexible information about interfaces than ifconfig.
Run 'ip addr' to see all interfaces, their IP addresses (both IPv4 and IPv6), link status, and more. It shows interfaces even if they are down. For example, 'ip addr show eth0' gives detailed info about that interface.
Result
You get a richer view of your network interfaces, including more address types and states.
Understanding ip addr’s detail helps you manage complex networks and troubleshoot subtle issues.
4
IntermediateUsing ifconfig to Change Interface Settings
🤔Before reading on: do you think ifconfig can enable or disable interfaces? Commit to your answer.
Concept: ifconfig can activate or deactivate interfaces and assign IP addresses.
You can bring an interface up with 'ifconfig eth0 up' or down with 'ifconfig eth0 down'. You can also assign an IP address like 'ifconfig eth0 192.168.1.20'. This changes how your computer connects to the network.
Result
You can control whether your computer uses a network interface and what IP it has.
Knowing how to enable or disable interfaces is essential for network troubleshooting and configuration.
5
IntermediateConfiguring Interfaces with ip addr
🤔Before reading on: do you think ip addr can replace ifconfig for configuration? Commit to your answer.
Concept: ip addr can add, change, or remove IP addresses and manage interface states with more options.
Use 'ip addr add 192.168.1.30/24 dev eth0' to add an IP address, or 'ip addr del 192.168.1.30/24 dev eth0' to remove it. Bring interfaces up or down with 'ip link set eth0 up' or 'ip link set eth0 down'. This is more flexible than ifconfig.
Result
You can fully manage network interfaces with ip commands, including multiple addresses.
Mastering ip addr commands prepares you for modern Linux networking and scripting.
6
AdvancedDifferences and Deprecation of ifconfig
🤔Before reading on: do you think ifconfig is still recommended for modern Linux systems? Commit to your answer.
Concept: ifconfig is deprecated and replaced by ip commands in most Linux distributions.
ifconfig is older and limited to IPv4 and basic tasks. ip commands support IPv6, multiple addresses, and advanced features. Many Linux systems no longer install ifconfig by default. Scripts and tools are moving to ip commands for better support.
Result
You understand why ip commands are preferred and when ifconfig might still appear.
Knowing the deprecation helps avoid using outdated tools and prepares you for future-proof scripting.
7
ExpertScripting Network Changes with ip Commands
🤔Before reading on: do you think ip commands can be safely scripted for dynamic network setups? Commit to your answer.
Concept: ip commands are designed to be script-friendly and support complex network automation.
You can write scripts that use 'ip addr' and 'ip link' to dynamically add or remove IPs, change interface states, or configure routing. This is common in cloud setups, containers, and automated deployments. ip commands provide consistent output and error codes for reliable scripting.
Result
You can automate network configuration tasks safely and flexibly.
Understanding ip commands’ scripting capabilities unlocks powerful automation and reduces manual errors.
Under the Hood
Both ifconfig and ip addr interact with the Linux kernel's networking stack through system calls. ifconfig uses older ioctl calls to query and set interface parameters, which limits its capabilities. ip addr uses the netlink socket interface, a more modern and flexible communication channel with the kernel, allowing richer data exchange and control over network interfaces and addresses.
Why designed this way?
ifconfig was designed decades ago when networks were simpler and mostly IPv4. As networking grew complex with IPv6, multiple addresses, and virtual interfaces, the older ioctl interface became insufficient. ip addr was created to use netlink sockets, enabling more detailed and extensible network management. This design allows Linux to evolve networking features without changing user tools constantly.
┌───────────────┐          ┌───────────────┐          ┌───────────────┐
│ ifconfig cmd  │─────────▶│ ioctl system  │─────────▶│ Kernel Network│
│ (old tool)    │          │ calls         │          │ Stack         │
└───────────────┘          └───────────────┘          └───────────────┘

┌───────────────┐          ┌───────────────┐          ┌───────────────┐
│ ip addr cmd   │─────────▶│ netlink socket│─────────▶│ Kernel Network│
│ (new tool)    │          │ interface     │          │ Stack         │
└───────────────┘          └───────────────┘          └───────────────┘
Myth Busters - 4 Common Misconceptions
Quick: Does ifconfig show all network interfaces, including those that are down? Commit to yes or no.
Common Belief:ifconfig shows all network interfaces regardless of their state.
Tap to reveal reality
Reality:ifconfig only shows interfaces that are currently active (up). Interfaces that are down or inactive do not appear by default.
Why it matters:This can mislead you into thinking an interface is missing or not configured when it is simply down, causing confusion during troubleshooting.
Quick: Can ip addr only show IPv4 addresses? Commit to yes or no.
Common Belief:ip addr only displays IPv4 addresses like ifconfig does.
Tap to reveal reality
Reality:ip addr shows both IPv4 and IPv6 addresses, providing a more complete view of network configuration.
Why it matters:Ignoring IPv6 can cause network issues in modern environments where IPv6 is common, so relying on ifconfig alone can miss important info.
Quick: Is ifconfig still the recommended tool for all Linux distributions? Commit to yes or no.
Common Belief:ifconfig is the standard and recommended tool for all Linux systems.
Tap to reveal reality
Reality:Most modern Linux distributions have deprecated ifconfig in favor of ip commands, which are more powerful and actively maintained.
Why it matters:Using deprecated tools can lead to compatibility problems and missing out on newer networking features.
Quick: Does running 'ip addr add' overwrite existing IP addresses? Commit to yes or no.
Common Belief:Adding an IP address with 'ip addr add' replaces the current IP address on the interface.
Tap to reveal reality
Reality:'ip addr add' adds an additional IP address without removing existing ones; to replace, you must delete the old address first.
Why it matters:Misunderstanding this can cause multiple IPs to accumulate unintentionally, leading to network conflicts or confusion.
Expert Zone
1
ip addr commands support multiple IP addresses per interface, enabling advanced setups like virtual hosting or container networking.
2
The netlink interface used by ip commands allows asynchronous notifications from the kernel, which can be used to monitor network changes in real time.
3
ifconfig’s output format is inconsistent across systems, making it unreliable for scripting compared to the stable, parseable output of ip commands.
When NOT to use
Avoid using ifconfig on modern Linux systems for new scripts or configurations; use ip commands instead. For very simple or legacy systems without ip tools, ifconfig may still be used. For complex network automation, consider higher-level tools like NetworkManager or systemd-networkd that build on ip commands.
Production Patterns
In production, ip commands are used in automated scripts to configure network interfaces dynamically during boot or container startup. Network administrators use ip addr to audit network states and troubleshoot connectivity. ip commands integrate with firewall and routing tools for comprehensive network management.
Connections
Network Interface Card (NIC)
ip addr and ifconfig show and configure NICs, which are the hardware interfaces for networking.
Understanding NICs helps you grasp why interfaces appear as they do and how physical hardware relates to software commands.
System Calls
Both commands use system calls (ioctl or netlink) to communicate with the kernel.
Knowing system calls clarifies how user commands control hardware indirectly through the operating system.
Human Nervous System
Like nerves transmit signals between brain and body, network interfaces transmit data between computer and network.
This analogy helps appreciate the role of interfaces as communication channels essential for system function.
Common Pitfalls
#1Trying to see all interfaces with ifconfig but missing down interfaces.
Wrong approach:ifconfig
Correct approach:ip addr
Root cause:ifconfig only lists active interfaces, so down interfaces are hidden, causing incomplete information.
#2Assigning a new IP with ifconfig without subnet mask, causing network issues.
Wrong approach:ifconfig eth0 192.168.1.50
Correct approach:ip addr add 192.168.1.50/24 dev eth0
Root cause:ifconfig requires separate commands or defaults for subnet masks, while ip addr requires explicit CIDR notation, preventing ambiguity.
#3Using ifconfig in scripts on modern systems where it is not installed.
Wrong approach:ifconfig eth0 up
Correct approach:ip link set eth0 up
Root cause:ifconfig is deprecated and may not be available, causing scripts to fail.
Key Takeaways
ifconfig and ip addr are commands to view and manage network interfaces, but ip addr is the modern, more powerful tool.
ifconfig only shows active interfaces and supports basic IPv4, while ip addr shows all interfaces with IPv4 and IPv6 details.
ip addr uses a modern kernel interface (netlink) allowing richer control and scripting capabilities.
ifconfig is deprecated on most Linux systems; learning ip addr prepares you for current and future network management.
Understanding these commands is essential for troubleshooting, configuring, and automating Linux network interfaces.