View Single Post
  #1   (View Single Post)  
Old 21st January 2010
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default The unknown /etc/networks file

On my local network utp.xnet I have a local DNS server, which resolves names in the utp.xnet network.

If one doesn't have such a server you always have to remember to specify the -n flag to netstat for example.
Code:
$ netstat -rn -f inet
Routing tables

Internet:
Destination        Gateway            Flags   Refs      Use   Mtu  Prio Iface
default            192.168.222.10     UGS        3       22     -     8 fxp0
127/8              127.0.0.1          UGRS       0        0 33200     8 lo0
127.0.0.1          127.0.0.1          UH         1        0 33200     4 lo0
192.168.222/24     link#1             UC         2        0     -     4 fxp0
192.168.222.10     00:08:c7:05:ca:0b  UHLc       1        4     -     4 fxp0
192.168.222.20     00:19:db:47:b0:4c  UHLc       1      180     -     4 fxp0
224/4              127.0.0.1          URS        0        0 33200     8 lo0
If you forget that -n option, netstat will do reverse name lookups on the addresses. If they don't resolve, because of absence of a nameserver the DNS requests will time out, and that can cause considerable delays.

Without the "don't resolve addresses to names" option, that same routing table looks like this:
Code:
 $ ]netstat -r -f inet  
Routing tables

Internet:
Destination        Gateway            Flags   Refs      Use   Mtu  Prio Iface
default            parmenides         UGS        3       23     -     8 fxp0
loopback           localhost          UGRS       0        0 33200     8 lo0
localhost          localhost          UH         1        0 33200     4 lo0
192.168.222/24     link#1             UC         2        0     -     4 fxp0
parmenides         00:08:c7:05:ca:0b  UHLc       1        4     -     4 fxp0
hercules           00:19:db:47:b0:4c  UHLc       1      204     -     4 fxp0
BASE-ADDRESS.MCAST localhost          URS        0        0 33200     8 lo0
Nearly all numeric values referring to hosts have been replaced by the names to those hosts.
But did you ever wonder where the BASE-ADDRESS.MCAST network name for 224/4 comes from?

It does not originate from DNS but from a file /etc/networks which as usual on the BSD's has a man page.
For the online versions see networks(5) for OpenBSD and for FreeBSD networks(5).

From the OpenBSD version:
Code:
NAME
     networks - Internet Protocol network name database

DESCRIPTION
     The networks file is used as a local source to translate between Internet
     Protocol (IP) network addresses and network names (and vice versa).  It
     can be used in conjunction with the Domain Name System (DNS).
The /etc/networks on my OpenBSD box:
Code:
#       $OpenBSD: networks,v 1.5 1997/09/15 09:54:52 deraadt Exp $
#

# Internet networks (from nic.ddn.mil)
# 1) The multicast network
BASE-ADDRESS.MCAST.NET  224
loopback                127     loop

# Your subnets follow...
Adding the following line
Code:
utp.xnet                192.168.222
And now utp.xnet will be used
Code:
$ netstat -r -f inet 
Routing tables

Internet:
Destination        Gateway            Flags   Refs      Use   Mtu  Prio Iface
default            parmenides         UGS        2       30     -     8 fxp0
loopback           localhost          UGRS       0        0 33200     8 lo0
localhost          localhost          UH         1        0 33200     4 lo0
utp.xnet           link#1             UC         2        0     -     4 fxp0
parmenides         00:08:c7:05:ca:0b  UHLc       2       20     -     4 fxp0
hercules           00:19:db:47:b0:4c  UHLc       1      363     -     4 fxp0
BASE-ADDRESS.MCAST localhost          URS        0        0 33200     8 lo0
You can also specify a netmask in this /etc/networks file.
Code:
# Your subnets follow...
utp.xnet                192.168.222
utp-mask                255.255.255
This allows you to do things like

Code:
# ifconfig lo1 create
# ifconfig lo1 192.168.222.245 netmask utp-mask
# ifconfig lo1
lo1: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 33200
        priority: 0
        groups: lo
        inet 192.168.222.245 netmask 0xffffff00
Nice uuh?
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote