The goal of this article is to help deal with networks under the NetBSD. The NetBSD Operating System provides a number of usable network tools to deal with particular and general network whereabouts. Use of these tools is briefly explained here.
Before we start, anyone should realize that computer hosts (and/or different network devices) must be connected via cable, which provides physical connection into the network. This article touches network tools in general and doesn't explain wireless network in particular.
Physical connection is done (e.g. all cables connected). All hosts and network devices should also bear the logical connection. Only both, physical and logical connections enables devices to talk together (e.g. enables information interchange).
First, the physical part of the network. Very often networks look like a number of hosts connected into single or number of hubs or concentrators e.g. the physical connection is presented. Precisely check these hubs. Misunderstanding can happen just in one of the devices. Instead of the simple hub it can be a switch. Switches may have vlan or similar options enabled specifically to decline connection of particular hosts or group of hosts. All hubs and switches should be checked (usually through telnet or web interface) to verify connection options in use. Sometimes memory reset needs to be performed to achieve absolute assurance of absence network blocking options.
Second, the logical part of the network. Hosts even if they are materially connected together may work withing different logical networks. For an example, one network is 192.168.1.X and another network is 192.168.2.X, etc. This is two different networks. Hosts from different logical networks can not interchange information. Special options as address translation, routing, etc. allows to, and enable information interchange within different networks. When hosts connected within one network like 192.168.1.X, for an example Host-A has address 192.168.1.10 and Host-B has address 192.168.1.20, logical information interchange is enabled.
Third. One from many NetBSD advantages is the feature that single computer can utilize several different network cards. The same computer can service large number of different networks. The same computer can provide routing and network address translation options per your desire. The same computer can refer into number of Dynamic Names Servers DNS. The same computer can provide services such as an independentor web-server. NetBSD also provides a number of tools and features which allows to test the network.
Use dmesg to obtain information about network adapters on the NetBSD machine:
$ dmesg | more $ less /var/run/dmesg.boot
Dmesg provides basic information about installed network adapter. For example:
rtk0 at pci3 dev 0 function 0: Realtek 8139 10/100BaseTX rtk0: interrupting at irq 5 rtk0: Ethernet address 01:00:25:28:fa:c0
This means that network card has Realtek chip and the system calls it - rtk0. A computer can have 1, 2 or even 5 different network cards installed and it is ok. Number of available slots in the mainboard limits number of network cards.
In BSD the network interface name contains the name of the network driver. rtk is the network driver for Realtek 8129/8139 based network cards. rtk0 is the first network card with the rtk chip. A second same card would be named rtk1.
Use ifconfig to see which network cards are in use:
$ ifconfig -a rtk0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 address: 00:00:21:20:fa:c0 media: Ethernet autoselect (none) status: active inet 192.168.17.1 netmask 0xffffff00 broadcast 192.168.17.255 inet alias 192.168.18.1 netmask 0xffffff00 broadcast 192.168.18.255 inet6 fe80::200:21ff:fe20:fac0%rtk0 prefixlen 64 scopeid 0x1 lo0: flags=8009<UP,LOOPBACK,MULTICAST> mtu 33192 inet 127.0.0.1 netmask 0xff000000 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
You can see the card rtk0 is UP and running with status: active. It does have the current IP address: 192.168.17.1 This card also has a second IP address 192.168.18.1 which is an alias. The network card configuration is stored in:
Usually ifconfig.rtk0 have following content:
inet 192.168.17.1 netmask 255.255.255.0
Where: 192.168.17.X is the network. 192.168.17.1 is the address of host e.g. the address of this machine. 255.255.255.0 is subnet (netmask) which allows to access 254 hosts of the network.
In the case from above ifconfig.rtk0 have following:
inet 192.168.17.1 netmask 255.255.255.0 inet 192.168.18.1 netmask 255.255.255.0 alias
This content demonstrates ability to have access not only one but two or more networks, with different addresses of this host. Additional addresses referred as alias.
Note, ifconfig.rtk0 may also have content like this:
inet 192.168.17.1 netmask 255.255.255.254
In this example subnet defines the number of hosts within the network. Use of the 255.255.255.254 subnet is limiting number of hosts up to 2 hosts. Count starts from the address of the machine and continues up further.
Use the ping command to check plain network connections of other devices (e.g. computers, printers, VoIP phones, etc.) which is connected to your the network.
For example, start from IP address of single computer to see if it is alive:
# ping -n 192.168.17.1
64 bytes from 192.168.17.1: icmp_seq=0 ttl=255 time=0.049 ms 64 bytes from 192.168.17.1: icmp_seq=1 ttl=255 time=0.051 ms 64 bytes from 192.168.17.1: icmp_seq=2 ttl=255 time=0.050 ms
Stop it by pressing CTRL+C.
Please note that return-replies to our ping request means that the host is up and running.
Also check the the response. It may be come from a different IP address. Subnet, router or intermediary switch, may bear special route or have altered address, and answer calls on the middle of route.
Install and use net/nmap to see list of all hosts in your the network. After installation of nmap, just run:
# nmap -sP 192.168.17.1-254
# nmap -sP 192.168.17.*
Asterisk and 1-254 means that nmap checks the whole 192.168.17/24 network.
nmap is a very powerful network tool. Please use with care.
/etc/mygate contains the IP address of your default gateway. The address of such router may be written infile, like this:
or you can use:
in your /etc/rc.conf
Some systems have route added into /etc/rc.conf file or routing software installed like Zebra, Quagga, etc. to deal with TCP, BGP, OSPF and other protocols. In this case /etc/mygate file may be empty.
The netstat command shows network status, command symbolically displays the contents of various network-related data.
To see network relating routing tables do:
# netstat -rn
It returs somthing like this:
Internet: Destination Gateway Flags Refs Use Mtu Interface default 192.168.170.201 UGS 1 34064 - rtk0 loopback/8 localhost UGRS 0 0 33192 lo0 localhost localhost UH 1 6 33192 lo0 192.168.170/24 link#1 UC 6 0 - rtk0 192.168.170.201 00:60:97:51:d1:d0 UHLc 2 7121 - rtk0 192.168.170.216 00:00:21:2b:d5:9b UHLc 0 71 - lo0 192.168.170.255 link#1 UHLc 3 787 - rtk0
This output means.
Your Network Interface Card (NIC) is here:
192.168.170.216 00:00:21:2b:d5:9b UHLc 0 71 - lo0
You have link#1 into 192.168.170.X network:
192.168.170/24 link#1 UC 6 0 - rtk0
Your default Gateway (e.g. IP address of router connected to your network) is here:
default 192.168.170.201 UGS 1 34064 - rtk0
You have to note, two columns and two lines that are important for routing:
Destination Gateway Flags Refs Use Mtu Interface default 192.168.170.201 UGS 1 34064 - rtk0 192.168.170.201 00:60:97:51:d1:d0 UHLc 2 7121 - rtk0
Means, NIC 00:60:97:51:d1:d0 with IP 192.168.170.201 is listened by your card; and this computer uses this particular IP address as a gateway to other part of network.
The sockstat is a handy tool to list open sockets. It is commonly used to list all listening sockets:
# sockstat -l USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS root dhcpcd 103 6 stream /var/run/dhcpcd.sock - root syslogd 157 3 dgram /var/run/log - root sshd 254 4 tcp *.ssh *.* root lpd 283 5 stream /var/run/printer - root lpd 283 6 tcp6 *.printer *.* root lpd 283 7 tcp *.printer *.* root Xorg 319 1 tcp6 *.x11 *.* root Xorg 319 3 stream /tmp/.X11-unix/X0 - root master 491 12 tcp *.smtp *.* root master 491 13 tcp6 *.smtp *.*
Check contents of /etc/rc.local file. It can maintain following lines:
sysctl -w net.inet.ip.forwarding=1 ipnat -f /etc/ipnat.conf
This enables address translation. Check contents of /etc/ipnat.conf file:
map rtk0 192.168.1.0/24 -> 220.127.116.11/32 proxy port ftp ftp/tcp map rtk0 192.168.1.0/24 -> 18.104.22.168/32 portmap tcp/udp 10000:20000 map rtk0 192.168.1.0/24 -> 22.214.171.124/32
This orders network card rtk0 to translate all addresses heard from the 192.168.1.X network into only one address 126.96.36.199
The reasons to translate are simple. ISP's usually provide customers single or small set of IP addresses and don't deal with customers networks at all. Address translation of large internal networks into small set of public IP address or even into single address allows to reach whole other part of the network. For en example to provide Internet access. Here, single IP address services network whith bandwidth of internal addresses from 192.168.1.0 to 192.168.1.255 (i.g. 254 hosts) Such mapping can be very flexible. For an example for single address:
map rtk0 192.168.2.2/32 -> 188.8.131.52/32 proxy port ftp ftp/tcp map rtk0 192.168.2.2/32 -> 184.108.40.206/32 portmap tcp/udp 10000:20000 map rtk0 192.168.2.2/32 -> 220.127.116.11/32
For network with 254 hosts:
map rtk0 192.168.2.0/24 -> 18.104.22.168/32 proxy port ftp ftp/tcp map rtk0 192.168.2.0/24 -> 22.214.171.124/32 portmap tcp/udp 10000:20000 map rtk0 192.168.2.0/24 -> 126.96.36.199/32
Or much more globally:
map rtk0 0.0.0.0/0 -> 188.8.131.52/32 proxy port ftp ftp/tcp map rtk0 0.0.0.0/0 -> 184.108.40.206/32 portmap tcp/udp 10000:20000 map rtk0 0.0.0.0/0 -> 220.127.116.11/32
Note, ipnat translation is netmask sensitive thus you have to use only correct subnets.
Very often IP addresses bears additional slash and number, for an example: 192.168.2.2/24 or /32, etc. That's called the CIDR notation.
For an additional calculations, you can use net/sipcalc.
More information can be found at Subnetwork
Because both ipfilter and ipnat work together, check contents of ipf.conf file. Simple example is here:
pass in from any to any pass out from any to any
However, some network cards, addresses and networks can be blocked or open.
The /etc/resolv.conf contains the addresses of nameservers, that allows to resolve alphabetical hostnames into numeric IP addresses.
Note. The addresses of the DNS nameservers are usually obtained (when connecting to the internet) from your Internet Service Provider. You can also use any public DNS nameservers. You can set up your ownServer with NetBSD.
In order to see which nameserver(s) are in use check contents of /etc/resolv.conf file:
nameserver 18.104.22.168 nameserver 22.214.171.124
If the computer is the DNS server, the IP address usually is set like this:
If you experience 5-30 second delays while surfing, check with dig, if all referred nameservers are really accessible, e.g:
$ dig @126.96.36.199 A www.netbsd.org