≡ Menu

Linux command to get IP address

Question – I need to find the IP address of my Linux machine. Is there a command that can do this on CentOS?

The ifconfig command can be used to get all of the IP addresses of a Linux machine. The command can be used to get information about network adapters and their IP addresses. It will output information about all network interfaces and their addresses. Without any arguments, ifconfig will display the status of all network interfaces on a system:

[root@server ~]# ifconfig
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:46 errors:0 dropped:0 overruns:0 frame:0
          TX packets:46 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:4324 (4.2 KiB)  TX bytes:4324 (4.2 KiB)

venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:127.0.0.1  P-t-P:127.0.0.1  Bcast:0.0.0.0  Mask:255.255.255.255
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
          RX packets:652227 errors:0 dropped:0 overruns:0 frame:0
          TX packets:573625 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:226629604 (216.1 MiB)  TX bytes:40755604 (38.8 MiB)

venet0:0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:199.167.196.116  P-t-P:199.167.196.116  Bcast:199.167.196.116  Mask:255.255.255.255
          UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1

[root@server ~]#

To get only the IP addresses, you can use the following command:

[root@server ~]# ifconfig | grep "inet addr"
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet addr:127.0.0.1  P-t-P:127.0.0.1  Bcast:0.0.0.0  Mask:255.255.255.255
          inet addr:199.167.196.116  P-t-P:199.167.196.116  Bcast:199.167.196.116  Mask:255.255.255.255
[root@server ~]#

Since ifconfig displays information on all network interfaces, you will get a list of all of your IP addresses!

Comments on this entry are closed.