Redhat Linux: Find Out My IP Address

How do I to find out ip address on a CentOS or Fedora or Redhat Enterprise Linux server or desktop system using bash shell or command line options?

You can use any one of the following command to view ip address information for each interface under an RHEL / CentOS / Fedora Linux based system:

ADVERTISEMENTS

Redhat Linux: Find Out My IP Address

  1. ip command: Display or manipulate IP address, routing, devices, policy routing and tunnels. This command can show ip address on a CentOS or RHEL servers.
  2. ifconfig command: It is used to configure the kernel-resident network interfaces as well as display information about it.

ip command example to find an IP address for RHEL 5 system

To see current ip address information for eth0, enter:
# ip addr show eth0
Sample outputs:

2: eth0:  mtu 1500 qdisc mq state UP qlen 1000
    link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::baac:6fff:fe65:31e5/64 scope link 
       valid_lft forever preferred_lft forever

To see routing information, enter:
# ip route show
Sample outputs:

10.0.xx.yy dev ppp0  proto kernel  scope link  src 10.1.3.199 
38.xx.yy.zz via 192.168.1.2 dev eth0  src 192.168.1.100 
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.100  metric 1 
10.0.0.0/8 dev ppp0  scope link 
default via 192.168.1.2 dev eth0  proto static 

ifconfig command example

Simply type the ifconfig command as follows to display eth0 IP information:
# ifconfig -a
OR
# ifconfig eth0
Sample outputs:

eth0      Link encap:Ethernet  HWaddr b8:ac:6f:65:31:e5  
          inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::baac:6fff:fe65:31e5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:308560 errors:0 dropped:0 overruns:0 frame:0
          TX packets:217836 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:431112624 (431.1 MB)  TX bytes:20994801 (20.9 MB)
          Interrupt:17 

You can simply type the following grep command to just display an IP and its netmask:
# ifconfig eth0 | grep 'inet addr:'
Sample outputs:

 inet addr:192.168.1.100  Bcast:192.168.1.255  Mask:255.255.255.0
RHEL [Redhat linux] IP Address Find Command

RHEL / CentOS commands to list an IP address for eth0

Conclusion

You learned how to show IP address in Linux using command line options. Most modern Linux distro only use the ip command to display or configure IP address at run time. Hence, you must stick with the ip command for CentOS/RHEL/Fedora and other Linux distros.

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
6 comments… add one
  • Leonidas Aug 18, 2011 @ 6:58

    using command
    #ifconfig

  • moke Sep 8, 2012 @ 2:27

    hmm .. thanks !

  • _ck_ Jun 28, 2014 @ 1:59

    hostname -i

    • Velathora Jul 25, 2014 @ 14:01

      So much easier considering it answers the question EXACTLY

    • brett Feb 23, 2015 @ 15:40

      hostname -i|awk ‘{print $2}’

  • Leandroqara Oct 6, 2016 @ 11:22

    hostname -i Rules!

    I was looking for this answer for long time!
    thanks

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.