Find the IP of a Linux Server in Command Line

Knowing your server’s IP address(s) can be a useful bit of information to have for various reasons. After all, other than your domain, the server’s IP is the main address used to reach the server. Knowing a server’s IPs may be necessary when making changes to: DNS, networking, and security. A server may have a single IP, or multiple IPs, sometimes you need a quick way double check since it’s easy to forget.

This tutorial will teach you how to check the IPs of any modern Linux server. To follow along will simply need access to the server via SSH or TTY.

Pre-flight Check:

  • This tutorial requires basic knowledge of SSH and command line.
    See our KB article on command line access via SSH.
  • You must have SSH access to the server.

Check IPs with Command Line

  1. Begin the process by logging into your server via SSH:
    ssh liquidweb.example
  2. Now logged in via SSH, run the following command to check the servers IP:
    ip route

    This command is using the `ip` tool and is calling the `route` object, this command prints the current routing table.

Reading the Results

Once you execute that command you’ll see output similar to the following text. This is showing the servers IP routing table, essentially this is a set of rules used to determine where data will be directed.

When using this technique to find a server’s IPs you’ll keep an eye out for lines containing `src` followed by an IP. On these lines, the IP address following `src` are an IP configured on the server.

default via 203.0.113.1 dev eth0
203.0.113.0/24 dev eth0 proto kernel scope link src 203.0.113.86
198.51.0.0/16 dev eth0 scope link metric 1002
Any device using IP addresses will have a routing table used to determine the devices networking behavior.

In the example results, shown above, you see a severs routing table showing that the server has an IP address of: `203.0.113.86`.

While it may not look like much to new users these lines are dense with information. Each line of the routing table is there to describe a different behavior or condition. More information on these can be found in the ip commands manual pages, these can be found in the command line using `man ip route`. You can also read the man page online here.

Be Sociable, Share!

About the Author: Dan Pock

Dan Pock does Technical Writing & Marketing at Liquid Web with a background in System Administration, Public Relations, and Customer Service. His favorite things include: his cats, Oscar Boots and Dash Nouget; experimenting with PHP; and making up recipes (or at least attempting to). You can find his coding hijinks on GitHub, where he shares most of his projects and open source work.

Here's 75 % off, Launch a New VPS Today. Find out why 30,000 customers have chosen our Best-in-Class Performance & 24x7 Heroic Support