networking

Find Ip Address Linux Terminal: Commands And Examples

Finding your IP address via the Linux command line is a fundamental task for managing network connections, troubleshooting connectivity drops, and configuring local servers. Whether you're working on

Find Ip Address Linux Terminal: Commands And Examples
In this story

Finding your IP address via the Linux command line is a fundamental task for managing network connections, troubleshooting connectivity drops, and configuring local servers. Whether you're working on a remote headless Ubuntu server or setting up a local network interface on Fedora, knowing the right commands saves time and bypasses graphical settings menus entirely.

Modern Linux distributions have transitioned away from older tools in favor of unified networking suites, but several robust utilities remain available. This guide covers how to quickly discover both local private IP addresses and external public IP addresses using standard command-line tools.

Understanding Local Versus Public IP Addresses

Before running commands, it helps to clarify what kind of IP address you're looking for. Your local IP address is assigned by your home or office router, allowing your machine to communicate with other devices on the same local area network (LAN). Your public IP address is assigned by your Internet Service Provider (ISP), representing your network to the wider internet.

Most network troubleshooting tasks—such as setting up an SSH connection or fixing printer sharing—require your local IP address. Tasks like configuring port forwarding or testing remote firewall rules require your public IP address.

Finding Your Local IP Address

Linux provides several utilities to check local network interfaces. Depending on your operating system version and installed packages, you can choose the tool that fits your workflow.

Using the Ip Command

The ip command is the modern standard for configuring and viewing network interfaces in Linux. It replaces the older ifconfig utility found in legacy distributions.

To view all network interfaces and their assigned addresses, run:

ip addr show

You can shorten this command to save keystrokes:

ip a

Look through the output for your active network interface—typically named eth0, enp3s0, or wlan0 for wireless connections. Next to the inet label under your active interface, you will see your local IPv4 address, formatted similarly to 192.168.1.50.

If you only want to see IPv4 addresses and filter out the noise, use:

ip -4 addr show

Using the Ifconfig Command

While deprecated in many modern distributions, ifconfig remains widely recognized and is often installed manually via the net-tools package.

To check your network configuration with ifconfig, run:

ifconfig

The output displays active interfaces alongside their IP addresses, netmasks, and broadcast addresses. Look for the inet entry next to your primary network card. If the command returns an error stating the utility isn't found, your distribution relies exclusively on the newer iproute2 suite.

Using the Hostname Command

For a quick look at your local machine's IP address without parsing extensive interface tables, the hostname command offers a streamlined shortcut.

Run the following command in your terminal:

hostname -I

This returns a space-separated list of all IP addresses assigned to the host. It's often the fastest way to grab your local IPv4 address for scripting or quick connection tests.

Finding Your Public IP Address

Local commands only reveal addresses inside your private network. To discover the external IP address visible to web servers and remote networks, you need to query an external service via command-line HTTP clients like curl or wget.

Several public services provide your external IP in plain text format. Run one of the following commands:

curl ifconfig.me

Alternatively, you can use reliable alternatives if your preferred endpoint experiences downtime:

curl icanhazip.com
wget -qO- https://api.ipify.org

These commands query external servers and print your public IPv4 address directly to your terminal window.

👉 See also: What Is My IP

Common Mistakes and Troubleshooting

Network troubleshooting often involves unexpected roadblocks. Here are a few common pitfalls to avoid when working with network commands.

  • Checking the loopback interface: Don't confuse your primary interface with the loopback interface (lo), which typically lists the address 127.0.0.1. Always verify you're looking at your physical Ethernet or Wi-Fi adapter.
  • Missing packages: If ifconfig or netstat fails, don't waste time trying to fix legacy packages. Modern systems expect you to use ip and ss.
  • VPN interference: If your public IP address query returns unexpected geographic locations or network ranges, check whether an active VPN service is routing your traffic.

For deeper documentation on networking utilities, consult the official Linux Documentation Project.

Frequently Asked Questions

Why doesn't the ifconfig command work on my system?

Many modern Linux distributions, including recent releases of Ubuntu and Fedora, omit net-tools by default. Use ip a instead of ifconfig for modern network inspection.

How do I find my default gateway IP address?

Run ip route show in your terminal. Look for the line starting with default via, where the subsequent IP address represents your router's local gateway.

Can I find my IP address without third-party services for public IPs?

If you control your home router, you can log directly into its admin dashboard via your browser to view the WAN IP address assigned by your ISP. Command-line curl requests simply offer a faster shortcut.

What is the difference between IPv4 and IPv6 addresses?

IPv4 addresses use a 32-bit numeric format (e.g., 192.168.1.10), while IPv6 addresses use a 128-bit alphanumeric format (e.g., 2001:db8::1) designed to accommodate the expanding number of connected devices globally.

CR

Written by

Chloe Ramirez

Chloe Ramirez excels at making complicated information accessible, turning dense research into clear narratives that engage diverse audiences.

More from networking