Okay, let's be real: trying to find your IP address in Linux shouldn't feel like decoding ancient hieroglyphs. But here we are. I remember the first time I needed to check an IP on a headless server - staring at a black terminal with that sinking "now what?" feeling. If you've ever typed show ip
like it's Cisco gear and gotten that nasty "command not found" error, you're not alone. This guide cuts through the noise to show you exactly how to use Linux IP address commands properly.
Why These Commands Actually Matter
So why fuss with terminal commands when you could just click some network manager icon? Three solid reasons:
- Servers don't have GUIs: Most production servers run without graphical interfaces. Terminal is your only friend.
- Scripting and automation: Ever tried to automate network configs? You need these commands in your scripts.
- Troubleshooting cred: When networks break (and oh, they will), these tools reveal truths GUI tools hide.
Last month I watched a junior admin spend 20 minutes reinstalling network drivers because he didn't know how to check interface status with ip
. Don't be that person.
The Old Warrior: ifconfig
Ah, ifconfig
. The granddaddy of Linux IP address commands. It's been around since the Stone Age of Linux (okay, the 1980s). Most tutorials start here, but honestly? It's becoming legacy tech.
Where to Find It
Fun fact: on modern Ubuntu or Debian systems, ifconfig
might be MIA. You'll need to install the net-tools
package:
sudo apt install net-tools # Debian/Ubuntu
sudo dnf install net-tools # Fedora/RHEL
Basic usage? Simple:
ifconfig
This dumps info for all interfaces. Want just eth0?
ifconfig eth0
What You're Actually Seeing
That wall of text isn't just random letters. Key elements:
Section | What It Means | Example |
---|---|---|
inet | IPv4 address | inet 192.168.1.15 |
inet6 | IPv6 address | inet6 fe80::20c:29ff:fe12:3456 |
netmask | Subnet mask | netmask 255.255.255.0 |
RX packets | Received data stats | RX packets 12045 errors 0 |
TX packets | Transmitted data stats | TX packets 8932 errors 0 |
Heads up: ifconfig has limitations. It won't show multiple IPs on an interface, and its subnet mask reporting is prehistoric. Also, setting IPs with ifconfig doesn't persist after reboot - a nasty surprise if you don't know.
The Modern Powerhouse: ip command
Meet the ip
command - the replacement that actually understands modern networking. Part of the iproute2
suite, it's what sysadmins actually use daily. It's more verbose, but infinitely more powerful.
Basic syntax structure:
ip [OPTIONS] OBJECT COMMAND
Where OBJECT can be:
link
(physical interfaces)addr
(IP addresses)route
(routing tables)
Practical ip Command Cheat Sheet
Task | Command | Real-World Use Case |
---|---|---|
Show all IPs | ip addr show or ip a | Quickly verify all interface assignments |
Show specific interface | ip addr show eth0 | Check config on primary NIC |
Add IP address | sudo ip addr add 192.168.1.100/24 dev eth0 | Adding virtual IP for web server |
Remove IP address | sudo ip addr del 192.168.1.100/24 dev eth0 | Cleaning up old test configs |
Bring interface up | sudo ip link set eth0 up | Reviving dead NIC after maintenance |
Show routing table | ip route show | Tracing why traffic goes wrong path |
Why ip Command Beats ifconfig
Working on a CentOS box last year, I needed to add three IPs to one interface. ifconfig choked - ip
handled it with ease:
sudo ip addr add 192.168.1.101/24 dev eth0
sudo ip addr add 192.168.1.102/24 dev eth0
sudo ip addr add 192.168.1.103/24 dev eth0
Check results with:
ip addr show eth0
Pro tip: Add -c
for colorized output (ip -c a
). Lifesaver for dense outputs!
Quick 'n Dirty Alternatives
hostname Command
Need just the IP? Fastest method:
hostname -I
The -I
(capital i) shows all non-loopback IPs. Quick note: options differ between distros. On some, you'll need:
hostname -i
But honestly, -i
sometimes returns 127.0.0.1 which is useless. Test both.
Digging with nmcli
If you use NetworkManager (most desktops do), nmcli
is gold:
nmcli -p device show
That -p
makes output readable. Sample snippet:
GENERAL.DEVICE: wlp3s0
IP4.ADDRESS[1]: 192.168.1.72/24
IP4.GATEWAY: 192.168.1.1
Handling Multiple Network Interfaces
Modern servers often have 4+ NICs. Identifying them is step one:
ip link show
Look for interface names:
- eth0: Traditional Ethernet (still common)
- enp3s0: Predictable network interface names (systemd)
- wlp4s0: Wireless interfaces
When I configured a web server last month, I bonded two NICs. Verification command:
ip link show bond0
IPv6? No Sweat
IPv6 addresses look scary but commands stay the same:
ip -6 addr show
Sample output:
inet6 2001:db8:0:1::abc/64 scope global
valid_lft forever preferred_lft forever
Key difference: that "/64" is your subnet prefix. Don't panic.
When Things Break: Troubleshooting
No IP Assigned?
If ip addr show
shows no IPv4 address:
- Check DHCP:
sudo dhclient -v eth0
- Interface down?:
sudo ip link set eth0 up
- Driver issues?:
dmesg | grep eth0
IP Conflicts
Sporadic disconnects? Might be duplicate IPs. Scan with:
arp-scan --localnet
Install via sudo apt install arp-scan
if missing.
True story: Once debugged a "haunted" server disconnecting hourly. arp-scan
revealed a forgotten test VM cloned with same IP. Classic.
FAQs: What People Actually Ask
How do I make IP changes permanent?
Ah, the eternal question. Temporary changes with ip
/ifconfig
vanish on reboot. Permanent solutions:
- Debian/Ubuntu: Edit
/etc/network/interfaces
- RHEL/CentOS: Edit interface configs in
/etc/sysconfig/network-scripts/
- Modern distros: Use
netplan
(Ubuntu 18.04+) ornmcli
Why does ip command show temporary addresses?
Those are IPv6 privacy extensions. Disable with:
sudo sysctl -w net.ipv6.conf.all.use_tempaddr=0
But understand privacy implications first.
Scripting with ip vs ifconfig?
Always choose ip
for scripts. Its output is more consistent and parseable. Example getting just the IP:
ip -4 -o addr show eth0 | awk '{print $4}' | cut -d'/' -f1
Versus ifconfig's messier output.
How to find public IP from terminal?
Internal IPs vs external IPs confuse many. For public IP:
curl ifconfig.me
Or:
curl icanhazip.com
Can I use these commands in containers?
Yes, but with caveats. Docker containers share host's network stack by default. Check actual container IP:
docker exec -it container_name ip addr show
Command Showdown: Which Should You Use?
Let's compare our contenders:
Command | Best For | Limitations | When I Reach For It |
---|---|---|---|
ip | Modern systems, scripting, detailed config | Steeper learning curve | 95% of server work |
ifconfig | Quick checks on legacy systems | Missing features, deprecated | Only on ancient boxes |
hostname -I | Getting IP fast in scripts | No interface details | Automation tasks |
nmcli | Desktop systems with NetworkManager | Not on minimal servers | My Ubuntu laptop |
Seriously, learn ip
deeply. It pays off when debugging at 3AM.
Beyond Basics: Pro Scenarios
Bonding Interfaces
Need more bandwidth or redundancy? Create a bond:
sudo ip link add bond0 type bond mode 802.3ad
sudo ip link set eth0 master bond0
sudo ip link set eth1 master bond0
sudo ip addr add 192.168.1.50/24 dev bond0
sudo ip link set bond0 up
MAC Address Spoofing
Temporarily change MAC (useful for testing):
sudo ip link set dev eth0 down
sudo ip link set dev eth0 address 00:11:22:33:44:55
sudo ip link set dev eth0 up
Route Specific Traffic
Send YouTube traffic via different gateway (don't ask why I needed this):
ip route add 173.194.0.0/16 via 192.168.1.254
Essential Tools Beyond Built-in Commands
Sometimes you need extra firepower:
- nmap: Network scanning (
sudo apt install nmap
) - netcat: Test connectivity (
nc -zv google.com 443
) - tcpdump: Packet inspection (
sudo tcpdump -i eth0
) - ethtool: NIC diagnostics (
sudo ethtool eth0
)
Common Mistakes You'll Make (I Did!)
Save yourself the headaches:
- Changing NICs without updating configs: New hardware? Interface names change!
- Forgetting /CIDR notation:
ip addr add 192.168.1.10
fails without /24 - Testing connectivity without DNS:
ping 8.8.8.8
before pinging domains - Ignoring link status:
ip link show
reveals if interface is UP
Once spent two hours debugging "dead" network only to find the physical cable was loose. Always check layer 1 first!
Final Thoughts
Mastering Linux IP address commands isn't about memorizing syntax. It's understanding what happens when packets leave your machine. Start with ip addr
, graduate to ip route
, then explore ip neigh
for ARP tables. Within weeks, you'll diagnose issues that baffle GUI users.
Will you occasionally typo commands and break networking? Absolutely. Will you learn faster by breaking things? Guaranteed. Keep virtual machines or test boxes handy for experiments. And remember: sudo ip link set eth0 down
is always more educational when done remotely at 2AM. Just kidding... mostly.
Leave a Message