Difference between ip addr and ifconfig

ipip addressnetworkingsubnets

If it's subnet then it should have 254 hosts. But it's showing me that it's my private ip address of my linux VM but it looks like subnet. If i use ip addr command it shows my ip is 10.0.1.178/24 as show below but if i use ifconfig command it show my ipaddres is 10.0.1.178 as show below

Output of ip addr

eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 9001 qdisc fq_codel state UP group default qlen 1000
    link/ether 02:e4:6b:7e:e5:ea brd ff:ff:ff:ff:ff:ff
    inet 10.0.1.178/24 brd 10.0.1.255 scope global dynamic eth0
       valid_lft 1928sec preferred_lft 1928sec
    inet6 fe80::e4:6bff:fe7e:e5ea/64 scope link 
       valid_lft forever preferred_lft forever

Output of ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 10.0.1.178  netmask 255.255.255.0  broadcast 10.0.1.255
        inet6 fe80::e4:6bff:fe7e:e5ea  prefixlen 64  scopeid 0x20<link>
        ether 02:e4:6b:7e:e5:ea  txqueuelen 1000  (Ethernet)
        RX packets 782364  bytes 646522004 (646.5 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 363184  bytes 42400501 (42.4 MB)

Best Answer

The outputs of ip addr and ifconfig are equivalent but slightly different notations of the same IP address and network mask.

The notion

10.0.1.178/24

means your IP address is 10.0.1.178, and the network mask for your network consists of the first 24 bits of the address. This is the same as the statement

inet 10.0.1.178 netmask 255.255.255.0

of the ifconfig output, only in a more compact notation, and means that as far as the Kernel routing table is concerned, your IP address is considered as belonging to a subnet that can host up to 254 different computers, whose addresses may range from 10.0.1.1 to 10.0.1.254.

The netmask information is relevant for the kernel when trying to determine if it is possible to reach a given remote address you want to open a connection to. An address such as 10.0.1.25 e.g. is immediately reachable since it belongs to the same subnet as your own computer, but in order to reach, say, 10.0.2.105 an appropriate route must be configured.

You may want to look at this Wikipedia article or this article on routing for further reading.

Related Question