When running ip addr add to assign an address to a network interface, you need (or can) specify the subnet of the interface. So then when you run ifconfig you can see the subnet:
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::f36f:407:e015:2633 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:73:e9:14 txqueuelen 1000 (Ethernet)
RX packets 105172 bytes 120417336 (120.4 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 27040 bytes 4403397 (4.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
I don't understand why is this necessary? I don't believe it's for routing purposes, since the routing table is used for this, so what is it good for?
EDIT: to be more clear: I know that the netmask is used to know the range of addresses that are directly linked to the network, i.e., can be reached without routing. But that's set in the routing table. So my question is: what's the relation between the setting of the interface and the routing table.
It's seems that they're not directly connected, see this:
root@yoav-VirtualBox:/home/yoav# ip addr add 192.168.1.2/24 dev first
root@yoav-VirtualBox:/home/yoav# ip addr
1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: second@first: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether a2:a9:4f:c3:c5:be brd ff:ff:ff:ff:ff:ff
3: first@second: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether f2:38:32:ea:b4:8f brd ff:ff:ff:ff:ff:ff
inet 192.168.1.2/24 scope global first
valid_lft forever preferred_lft forever
root@yoav-VirtualBox:/home/yoav# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
root@yoav-VirtualBox:/home/yoav#