How to Find Your IP Address in Linux

Linux network nodes illustrating private and public IP discovery

I checked the address assigned to this Linux machine with the iproute2 tools and an external address service. Use ip -br addr for addresses on local interfaces, ip route get 1.1.1.1 when a script needs the route-selected source address, and curl -4 -s icanhazip.com for the public IPv4 address.

These commands answer different questions. Your private address belongs to an interface on the local network, while your public address is the source address an outside service sees after network address translation.

Private and public IP addresses are different

AddressWhere it comes fromUse it for
Private IPLocal router, cloud subnet, or interface configurationConnecting to the machine inside its network
Public IPISP, router, or cloud providerAllowlists and services outside the network
LoopbackThe local hostTesting software on the same machine

Find the private IP with ip -br addr

The ip command from iproute2 lists addresses assigned to every interface.

ip -br addr
Terminal showing ip -br addr with loopback, the main interface, and private addresses

Read the address on the interface that carries your network traffic, not 127.0.0.1 on lo. This server reports 10.0.0.76/24 on enp0s6, plus several container bridge addresses.

Ask the routing table which address leaves the host

A machine with VPNs, containers, or several network cards can have several valid private addresses. Ask the kernel which source address it would use for a destination.

ip route get 1.1.1.1
Terminal showing ip route get with the src field identifying the route-selected address

Look for src in the output. A script that needs the primary route can extract that field rather than guessing from interface order.

Find the public IP from outside the machine

Local interface commands cannot know the public address when a router performs NAT, so query an address-echo service from the terminal.

curl -4 -s icanhazip.com
Terminal showing an external service returning the public IPv4 address
  • Use curl -s ifconfig.co for plain text when either address family is acceptable.
  • Use curl -4 -s icanhazip.com to request IPv4 only.
  • Use wget -qO- icanhazip.com when curl is unavailable.
  • Use dig +short myip.opendns.com @resolver1.opendns.com when DNS egress is available but HTTP is restricted.

An echo service sees the address presented to it, not necessarily an address assigned directly to your Linux interface. Treat the returned value as public network information.

Why ifconfig is missing

ifconfig belongs to the older net-tools package and is not installed on many current distributions. Use ip addr for the supported interface view.

sudo apt install net-tools

Install net-tools only when an older script or troubleshooting procedure requires ifconfig. For new scripts, ip addr and ip route expose more of the kernel’s current network state.

Choose the command for the task

NeedCommand
Quick private address listip -br addr
Route-selected source addressip route get 1.1.1.1
All non-loopback addresseshostname -I
Public IPv4curl -4 -s icanhazip.com
Public address over DNSdig +short myip.opendns.com @resolver1.opendns.com

For a script, make both lookups fail visibly instead of printing empty values.

priv=$(ip route get 1.1.1.1 | awk '{print $7; exit}')
pub=$(curl -4 -s --max-time 5 icanhazip.com)
[ -n "$priv" ] && printf 'private: %s\n' "$priv" || printf 'private: lookup failed\n'
[ -n "$pub" ] && printf 'public: %s\n' "$pub" || printf 'public: lookup failed\n'

The max-time limit prevents an unavailable network from holding the script forever. For related diagnostics, continue with our Linux ping guide, traceroute guide, and netstat and nslookup guide.

When DNS itself needs attention, compare the result with our change DNS on Linux guide and the wget IPv4 and IPv6 guide.

Frequently asked questions

How do I find my IP address in Linux?

Run ip -br addr for addresses assigned to local interfaces. Query curl -4 -s icanhazip.com when you need the public IPv4 address seen by an outside service.

What is the difference between a private and public IP?

A private IP is used inside a local network or cloud subnet. A public IP is the address an outside service sees after routing and NAT.

What replaces ifconfig on Linux?

Use ip addr or its compact form ip -br addr. Install net-tools only when you need the legacy ifconfig command for an older procedure.