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.
-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 xweb.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 127.0.0.1 dev eth0
127.0.0.0/24 dev eth0 proto kernel scope link src 127.0.0.86
126.0.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: `127.0.0.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`.

  • 221 Users Found This Useful
Was this answer helpful?

Related Articles

How to List Compiled PHP Modules from Command Line

Pre-Flight Check These instructions are intended specifically for listing compiled PHP modules...

How to Install or Uninstall PECL Extensions

Pre-Flight Check These instructions are intended specifically for installing or uninstalling...

How to Install the MongoDB PHP Driver (Extension) on CentOS 6

Step 1: Setup Environment, Install PHP Extension & Application Repository (PEAR) As a matter...

How to Add a User and Grant Root Privileges on CentOS 6.5

Step 1: Add the User It’s just one simple command to add a user. In this case, we’re...

How to Add a User and Grant Root Privileges on Ubuntu 14.04

Step 1: Add the User It’s just one simple command to add a user. In this case, we’re...