17

What is the practical usage of /etc/networks file? As I understand, one can give names to networks in this file. For example:

root@fw-test:~# cat /etc/networks
default         0.0.0.0
loopback        127.0.0.0
link-local      169.254.0.0
google-dns      8.8.4.4
root@fw-test:~# 

However, if I try to use this network name for example in ip utility, it does not work:

root@fw-test:~# ip route add google-dns via 104.236.63.1 dev eth0
Error: an inet prefix is expected rather than "google-dns".
root@fw-test:~# ip route add 8.8.4.4 via 104.236.64.1 dev eth0
root@fw-test:~#

What is the practical usage of /etc/networks file?

14

As written in the manual page, the /etc/networks file is to describe symbolic names for networks. With network, it is meant the network address with tailing .0 at the end. Only simple Class A, B or C networks are supported.

In your example the google-dns entry is wrong. It's not a A,B or C network. It's an ip-address-hostname-relationship therefore it belongs to /etc/hosts. Actually the default entry is also not conformant.

Lets imagine you have an ip address 192.168.1.5 from your corporate network. An entry in /etc/network could then be:

corpname 192.168.1.0

When using utilities like route or netstat, those networks are translated (if you don't suppress resolution with the -n flag). A routing table could then look like:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
corpname        *               255.255.255.0   U     0      0        0 eth0
4

The ip command never uses a host name for input either, so your example is hardly relevant. Also you've put a host name into /etc/networks, not a network name!

Entries from /etc/networks are used by tools that try to convert numbers to names, e.g. the (deprecated) route command. Without a suitable entry it shows:

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.254   0.0.0.0         UG    0      0        0 eth0
192.168.0.0     *               255.255.254.0   U     0      0        0 eth0

If I now add a line mylocalnet 192.168.0.0 to /etc/networks:

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.1.254   0.0.0.0         UG    0      0        0 eth0
mylocalnet      *               255.255.254.0   U     0      0        0 eth0

In practice it's never really used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.