**Contents**
[[!toc]]
#Preface
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 independent [[DNS-server|DNS]] or [[Apache]] web-server. NetBSD also provides a number of tools and features which allows to test the network.
#dmesg
Use [dmesg](http://netbsd.gw.com/cgi-bin/man-cgi?dmesg++NetBSD-current) 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.
#ifconfig
Use ifconfig to see which network cards are in use:
$ ifconfig -a
rtk0: flags=8843 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 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:
/etc/ifconfig.rtk0
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|How_to_gather_network_information_on_NetBSD#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.
#ping
Use the [ping](http://netbsd.gw.com/cgi-bin/man-cgi?ping++NetBSD-current) 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
It returns:
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.
#nmap
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
or
# 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.
#mygate
/etc/mygate contains the IP address of your default gateway. The address of such router may be written in [[/etc/mygate|Network/Default_route]] file, like this:
192.168.170.201
or you can use:
defaultroute="192.168.170.201"
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.
#netstat
The [netstat](http://netbsd.gw.com/cgi-bin/man-cgi?netstat++NetBSD-current) 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.
1. Your Network Interface Card (NIC) is here:
192.168.170.216 00:00:21:2b:d5:9b UHLc 0 71 - lo0
2. You have link#1 into 192.168.170.X network:
192.168.170/24 link#1 UC 6 0 - rtk0
3. 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.
#[[sockstat|basics/sockstat]]
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 *.*
#ipnat
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 -> 91.193.165.158/32 proxy port ftp ftp/tcp
map rtk0 192.168.1.0/24 -> 91.193.165.158/32 portmap tcp/udp 10000:20000
map rtk0 192.168.1.0/24 -> 91.193.165.158/32
This orders network card rtk0 to translate all addresses heard from the 192.168.1.X network into only one address 91.193.165.158
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 -> 91.193.165.158/32 proxy port ftp ftp/tcp
map rtk0 192.168.2.2/32 -> 91.193.165.158/32 portmap tcp/udp 10000:20000
map rtk0 192.168.2.2/32 -> 91.193.165.158/32
For network with 254 hosts:
map rtk0 192.168.2.0/24 -> 91.193.165.158/32 proxy port ftp ftp/tcp
map rtk0 192.168.2.0/24 -> 91.193.165.158/32 portmap tcp/udp 10000:20000
map rtk0 192.168.2.0/24 -> 91.193.165.158/32
Or much more globally:
map rtk0 0.0.0.0/0 -> 91.193.165.158/32 proxy port ftp ftp/tcp
map rtk0 0.0.0.0/0 -> 91.193.165.158/32 portmap tcp/udp 10000:20000
map rtk0 0.0.0.0/0 -> 91.193.165.158/32
Note, ipnat translation is netmask sensitive thus you have to use only correct subnets.
#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.
To deal with subnets look for this table: [Image:Tablitsa1.jpg](/images/Tablitsa1.jpg) [Image:Tablitsa2.jpg](/images/Tablitsa2.jpg)
For an additional calculations, you can use [net/sipcalc](http://pkgsrc.se/net/sipcalc).
More information can be found at [Subnetwork](http://en.wikipedia.org/wiki/Netmask)
#ipfilter
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.
For advanced configuration see [IPFilter resources](http://www.obfuscation.org/ipf/) and [Packet Filter](http://netbsd.org/docs/network/pf.html).
#[resolv.conf](http://netbsd.gw.com/cgi-bin/man-cgi?resolv.conf++NetBSD-current)
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 own [[DNS]] Server with NetBSD.
In order to see which nameserver(s) are in use check contents of */etc/resolv.conf* file:
nameserver 145.253.2.75
nameserver 194.146.112.194
If the computer is the DNS server, the IP address usually is set like this:
nameserver 127.0.0.1
If you experience 5-30 second delays while surfing, check with [dig](http://netbsd.gw.com/cgi-bin/man-cgi?dig++NetBSD-current), if all referred nameservers are really accessible, e.g:
$ dig @145.253.2.75 A www.netbsd.org
#See also
* [[Network/How to set up a DHCP Server]]
* [inetd](http://www.netbsd.org/docs/guide/en/chap-inetd.html#chap-inetd-services)
* [Network tools](http://www.netbsd.org/docs/guide/en/chap-tuning.html#tuning-ntools)
* [NetBSD Network](http://www.netbsd.org/docs/guide/en/chap-net-practice.html#chap-net-practice-small-net)
* [TCP/IP Networking](http://www.netbsd.org/docs/guide/en/chap-net-intro.html#chap-net-intro-tcpip-subnet)
* [Networking & related issues](http://www.netbsd.org/docs/guide/en/part-net.html)
* [[How to set up Quagga Router|Network/quagga]]
* [Gnu Zebra](http://www.zebra.org/index.html)
* [Quagga Routing Suite](http://www.quagga.net/)