Different ways/commands to look for IP address of your Linux Machine ?

This is one of another basic article that explains various commands through which we can look for IP address assigned to our Linux Operating System.

1. ifconfig
Ifconfig is most widely used command on Linux to view IP address.

[root@ngelinux ~]# ifconfig -a
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::4ebb:d12f:c486:4700 prefixlen 64 scopeid 0x20 ether 08:00:27:fa:bc:09 txqueuelen 1000 (Ethernet)
RX packets 10 bytes 1703 (1.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 72 bytes 8156 (7.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.21.49.239 netmask 255.255.255.0 broadcast 172.21.49.255
inet6 fe80::2eb2:8db5:88cc:a30d prefixlen 64 scopeid 0x20 ether 08:00:27:c6:10:21 txqueuelen 1000 (Ethernet)
RX packets 1591 bytes 365206 (356.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 138 bytes 29065 (28.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

enp0s9: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.99.100 netmask 255.255.255.0 broadcast 192.168.99.255
inet6 fe80::609b:ff42:efd3:ef71 prefixlen 64 scopeid 0x20 ether 08:00:27:7b:71:f0 txqueuelen 1000 (Ethernet)
RX packets 3 bytes 1433 (1.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 29 bytes 4738 (4.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:7a:96:47 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

virbr0-nic: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 52:54:00:7a:96:47 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@ngelinux ~]#

 

2. ip addr
ip addr is another command usually available on most of the linux systems and is useful to view options of Ethernet interfaces alongwith IP address.

[root@ngelinux ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:fa:bc:09 brd ff:ff:ff:ff:ff:ff
inet 10.0.2.15/24 brd 10.0.2.255 scope global noprefixroute dynamic enp0s3
valid_lft 86109sec preferred_lft 86109sec
inet6 fe80::4ebb:d12f:c486:4700/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:c6:10:21 brd ff:ff:ff:ff:ff:ff
inet 172.21.49.239/24 brd 172.21.49.255 scope global noprefixroute enp0s8
valid_lft forever preferred_lft forever
inet6 fe80::2eb2:8db5:88cc:a30d/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4: enp0s9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:7b:71:f0 brd ff:ff:ff:ff:ff:ff
inet 192.168.99.100/24 brd 192.168.99.255 scope global noprefixroute dynamic enp0s9
valid_lft 909sec preferred_lft 909sec
inet6 fe80::609b:ff42:efd3:ef71/64 scope link noprefixroute
valid_lft forever preferred_lft forever
5: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:7a:96:47 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
6: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:7a:96:47 brd ff:ff:ff:ff:ff:ff
[root@ngelinux ~]#

 

3. nmcli
From RHEL 7, or Centos 7 onwards, we have a command known as “nmcli” i.e. Network Manager CLI to manage network interfaces.

[root@ngelinux ~]# nmcli
enp0s3: connected to enp0s3
"Intel 82540EM"
ethernet (e1000), 08:00:27:FA:BC:09, hw, mtu 1500
ip4 default
inet4 10.0.2.15/24
route4 0.0.0.0/0
route4 10.0.2.0/24
inet6 fe80::4ebb:d12f:c486:4700/64
route6 fe80::/64
route6 ff00::/8

enp0s8: connected to enp0s8
"Intel 82540EM"
ethernet (e1000), 08:00:27:C6:10:21, hw, mtu 1500
inet4 172.21.49.239/24
route4 172.21.49.0/24
route4 0.0.0.0/0
inet6 fe80::2eb2:8db5:88cc:a30d/64
route6 fe80::/64
route6 ff00::/8

enp0s9: connected to Wired connection 1
"Intel 82540EM"
ethernet (e1000), 08:00:27:7B:71:F0, hw, mtu 1500
inet4 192.168.99.100/24
route4 192.168.99.0/24
inet6 fe80::609b:ff42:efd3:ef71/64
route6 fe80::/64
route6 ff00::/8

virbr0: connected to virbr0
"virbr0"
bridge, 52:54:00:7A:96:47, sw, mtu 1500
inet4 192.168.122.1/24
route4 192.168.122.0/24

lo: unmanaged
"lo"
loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

virbr0-nic: unmanaged
"virbr0-nic"
tun, 52:54:00:7A:96:47, sw, mtu 1500

DNS configuration:
servers: 17.76.1.51 17.76.3.51
interface: enp0s3

Use "nmcli device show" to get complete information about known devices and
"nmcli connection show" to get an overview on active connection profiles.

Consult nmcli(1) and nmcli-examples(5) manual pages for complete usage details.

 

4. IP route
IP route shows IP address alongwith different routes available on our system.

[root@ngelinux ~]# ip route
default via 10.0.2.2 dev enp0s3 proto dhcp metric 100
default via 172.21.49.1 dev enp0s8 proto static metric 101
10.0.2.0/24 dev enp0s3 proto kernel scope link src 10.0.2.15 metric 100
172.21.49.0/24 dev enp0s8 proto kernel scope link src 172.21.49.239 metric 101
192.168.99.0/24 dev enp0s9 proto kernel scope link src 192.168.99.100 metric 102
192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
[root@ngelinux ~]#

5. hostname
hostname command has an option “-I” to view IP addresses assigned to out host.

[root@ngelinux ~]# hostname -I
10.0.2.15 172.21.49.239 192.168.99.100 192.168.122.1

Leave a Reply

avatar
  Subscribe  
Notify of