ip Command in Linux: Check IP Address and Routes

Aidin

Network plug illustration for an ip command guide

Hi everyone. Whether you want to SSH into a machine, set up port forwarding on your router, or just confirm you are online, the first question is usually the same: what is my IP address? On Windows you type ipconfig. On Linux, plenty of older tutorials tell you to use ifconfig, but on a fresh Ubuntu install that command is not even there anymore. Its replacement is the ip command.

In this guide I do not change any network settings. We only read information: your IP address, gateway, DNS server, and the state of your network card. If you want to set an address that never changes, that is covered in the guide on setting a static IP on Ubuntu Server with Netplan.

Distro    : Ubuntu 26.04.1 LTS (Desktop)
Interface : enp0s3 (wired, DHCP)

Why ifconfig Does Not Work

The first thing that trips up beginners is ifconfig suddenly failing, even though it shows up in countless videos and articles.

The reason is simple. ifconfig comes from an old package called net-tools, and Ubuntu no longer installs it by default. The ip command replaces it, does more, and is always available.

Try running ifconfig

ifconfig not found on Ubuntu 26.04
ifconfig

You get Command ‘ifconfig’ not found (number 1), along with a hint to install net-tools. You can install it if you really want to, but there is no need. Everything ifconfig shows, ip shows too.

See Your IP Address with ip a

ip a is short for ip address. It is the command you will use most to check your IP on Linux, the closest thing to ipconfig on Windows.

The output is long, but do not let that put you off. You only need to look at a few lines, and I have marked them below.

Run ip a

ip a output showing the IP address and MAC address
ip a

There are two blocks. The first is lo (number 1), short for loopback. It is a virtual network the computer uses to talk to itself, always at 127.0.0.1, so you can skip it.

The one that matters is enp0s3 (number 2), the real network card in my machine. Yours may have a different name, such as eth0, ens33, or wlp2s0 for WiFi. state UP (number 3) means the card is active and connected.

The inet line (number 4) holds your IP address, 10.0.2.15/24 here. The /24 at the end describes the size of the network and means the same as a 255.255.255.0 subnet mask. link/ether (number 5) is the MAC address, a unique ID for the network card that you might need when setting up MAC filtering on a router.

Note: The inet6 lines are IPv6 addresses. For most home and office networks, the inet line (IPv4) is the one you care about.

A shorter view with ip -br a

Short output from ip -br a and hostname -I

If ip a feels too noisy, add -br for brief output.

ip -br a
hostname -I

Now each network card fits on a single line (number 1) with its name, its UP state, and its IP. Much easier to read. Even shorter is hostname -I, which prints just the IP addresses with no labels at all (number 2). Handy when you only need the number to copy and paste.

Find Your Gateway and DNS Server

An IP address alone does not prove you can reach the internet. You also need to know your gateway, the router that acts as the exit door to the internet, and your DNS server, which turns website names into IP addresses.

Both come up all the time when troubleshooting. When the internet is down, checking the gateway is one of the first things to do.

See the gateway with ip r

ip r showing the default gateway
ip r

ip r is short for ip route. The line that starts with default via (number 1) shows the gateway, 10.0.2.2 on my machine, reached through enp0s3. The line below it (number 2) is the local network 10.0.2.0/24, which means any computer with a 10.0.2.x address can be reached directly without going through the gateway.

See which DNS server you use

resolvectl dns showing the DNS server in use
resolvectl dns

On Ubuntu, DNS is handled by systemd-resolved, so you check it with resolvectl. enp0s3 is using 192.168.1.1 (number 1), which means this machine gets its DNS from the router on the network.

Check the State of Your Network Card

Sometimes ip a shows no IP at all. Before you panic, make sure the network card is actually up.

This happens when a cable is unplugged, WiFi is not connected yet, or the card has been switched off.

Use ip -br link

Network card state UP with ip -br link
ip -br link

This lists the state of every network card. enp0s3 is UP (number 1), so it is on and connected. DOWN would mean the card is off or the cable is out. Next to it you can see the same MAC address that ip a showed earlier (number 2).

Common Problems and How to Fix Them

Network trouble on Linux can take many forms, but the output of ip usually points you in the right direction. These are the cases I see most.

To check whether you can actually reach the internet, the next step is the ping command, which I cover in the next guide.

ifconfig: command not found

Newer Ubuntu releases do not ship ifconfig. Use ip a instead, or install it with sudo apt install net-tools if you really prefer it.

No inet line on the network card

The computer has not received an IP from the router. Check the cable or WiFi, then confirm the card is UP with ip -br link.

The IP starts with 169.254

The computer failed to get an address from the router through DHCP and made one up for itself. Check the connection to the router or restart it.

No default via line in ip r

There is no gateway, so the machine cannot reach the internet even though it has an IP. This usually happens with an incomplete static IP setup.

That is how you check your IP address, gateway, DNS, and network card state on Linux with the ip command. For everyday use, ip -br a and ip r give you the full picture in two lines. Once the IP and gateway look right, the next step is testing the connection with the ping command in Linux. If you get output that does not make sense, post it in the comments.

Leave a Comment