Annotation of wikisrc/tutorials/how_to_gather_network_information_on_netbsd.mdwn, revision 1.5
1.2 schmonz 1: **Contents**
2:
3: [[!toc]]
4:
5: #Preface
6:
7: 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.
8:
9: 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.
10:
11: 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).
12:
13: 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.
14:
15: 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.
16:
17: 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.
18:
19: #dmesg
20:
1.5 ! kim 21: Use [dmesg](//man.NetBSD.org/dmesg) to obtain information about network adapters on the NetBSD machine:
1.2 schmonz 22:
23: $ dmesg | more
24: $ less /var/run/dmesg.boot
25:
26: Dmesg provides basic information about installed network adapter. For example:
27:
28: rtk0 at pci3 dev 0 function 0: Realtek 8139 10/100BaseTX
29: rtk0: interrupting at irq 5
30: rtk0: Ethernet address 01:00:25:28:fa:c0
31:
32: 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.
33:
34: 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.
35:
36: #ifconfig
37:
38: Use ifconfig to see which network cards are in use:
39:
40: $ ifconfig -a
41: rtk0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
42: address: 00:00:21:20:fa:c0
43: media: Ethernet autoselect (none)
44: status: active
45: inet 192.168.17.1 netmask 0xffffff00 broadcast 192.168.17.255
46: inet alias 192.168.18.1 netmask 0xffffff00 broadcast 192.168.18.255
47: inet6 fe80::200:21ff:fe20:fac0%rtk0 prefixlen 64 scopeid 0x1
48: lo0: flags=8009<UP,LOOPBACK,MULTICAST> mtu 33192
49: inet 127.0.0.1 netmask 0xff000000
50: inet6 ::1 prefixlen 128
51: inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
52:
53: 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:
54:
55: /etc/ifconfig.rtk0
56:
57: Usually ifconfig.rtk0 have following content:
58:
59: inet 192.168.17.1 netmask 255.255.255.0
60:
61: 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.
62:
63: In the case from above ifconfig.rtk0 have following:
64:
65: inet 192.168.17.1 netmask 255.255.255.0
66: inet 192.168.18.1 netmask 255.255.255.0 alias
67:
68: 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.
69:
70: Note, ifconfig.rtk0 may also have content like this:
71:
72: inet 192.168.17.1 netmask 255.255.255.254
73:
74: 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.
75:
76: #ping
77:
1.5 ! kim 78: Use the [ping](//man.NetBSD.org/ping) command to check plain network connections of other devices (e.g. computers, printers, VoIP phones, etc.) which is connected to your the network.
1.2 schmonz 79:
80: For example, start from IP address of single computer to see if it is alive:
81:
82: # ping -n 192.168.17.1
83:
84: It returns:
85:
86: 64 bytes from 192.168.17.1: icmp_seq=0 ttl=255 time=0.049 ms
87: 64 bytes from 192.168.17.1: icmp_seq=1 ttl=255 time=0.051 ms
88: 64 bytes from 192.168.17.1: icmp_seq=2 ttl=255 time=0.050 ms
89:
90: Stop it by pressing CTRL+C.
91:
92: Please note that return-replies to our ping request means that the host is up and running.
93:
94: 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.
95:
96: #nmap
97: Install and use net/nmap to see list of all hosts in your the network. After installation of nmap, just run:
98:
99: # nmap -sP 192.168.17.1-254
100: or
101:
102: # nmap -sP 192.168.17.*
103:
104: Asterisk and 1-254 means that nmap checks the whole 192.168.17/24 network.
105:
106: nmap is a very powerful network tool. Please use with care.
107:
108: #mygate
109:
110: /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:
111:
112: 192.168.170.201
113:
114: or you can use:
115:
116: defaultroute="192.168.170.201"
117:
118: in your /etc/rc.conf
119:
120:
121: 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.
122:
123: #netstat
124:
1.5 ! kim 125: The [netstat](//man.NetBSD.org/netstat) command shows network status, command symbolically displays the contents of various network-related data.
1.2 schmonz 126:
127: To see network relating routing tables do:
128:
129: # netstat -rn
130:
131: It returs somthing like this:
132:
133: Internet:
134: Destination Gateway Flags Refs Use Mtu Interface
135: default 192.168.170.201 UGS 1 34064 - rtk0
136: loopback/8 localhost UGRS 0 0 33192 lo0
137: localhost localhost UH 1 6 33192 lo0
138: 192.168.170/24 link#1 UC 6 0 - rtk0
139: 192.168.170.201 00:60:97:51:d1:d0 UHLc 2 7121 - rtk0
140: 192.168.170.216 00:00:21:2b:d5:9b UHLc 0 71 - lo0
141: 192.168.170.255 link#1 UHLc 3 787 - rtk0
142:
143: This output means.
144:
145: 1. Your Network Interface Card (NIC) is here:
146:
147: 192.168.170.216 00:00:21:2b:d5:9b UHLc 0 71 - lo0
148:
149: 2. You have link#1 into 192.168.170.X network:
150:
151: 192.168.170/24 link#1 UC 6 0 - rtk0
152:
153: 3. Your default Gateway (e.g. IP address of router connected to your network) is here:
154:
155: default 192.168.170.201 UGS 1 34064 - rtk0
156:
157: You have to note, two columns and two lines that are important for routing:
158:
159: Destination Gateway Flags Refs Use Mtu Interface
160: default 192.168.170.201 UGS 1 34064 - rtk0
161: 192.168.170.201 00:60:97:51:d1:d0 UHLc 2 7121 - rtk0
162:
163: 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.
164:
1.4 sevan 165: #sockstat
1.2 schmonz 166:
167: The sockstat is a handy tool to list open sockets. It is commonly used to list all listening sockets:
168:
169: # sockstat -l
170: USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS
171: root dhcpcd 103 6 stream /var/run/dhcpcd.sock -
172: root syslogd 157 3 dgram /var/run/log -
173: root sshd 254 4 tcp *.ssh *.*
174: root lpd 283 5 stream /var/run/printer -
175: root lpd 283 6 tcp6 *.printer *.*
176: root lpd 283 7 tcp *.printer *.*
177: root Xorg 319 1 tcp6 *.x11 *.*
178: root Xorg 319 3 stream /tmp/.X11-unix/X0 -
179: root master 491 12 tcp *.smtp *.*
180: root master 491 13 tcp6 *.smtp *.*
181:
182: #ipnat
183:
184: Check contents of /etc/rc.local file. It can maintain following lines:
185:
186: sysctl -w net.inet.ip.forwarding=1
187: ipnat -f /etc/ipnat.conf
188:
189: This enables address translation. Check contents of /etc/ipnat.conf file:
190:
191: map rtk0 192.168.1.0/24 -> 91.193.165.158/32 proxy port ftp ftp/tcp
192: map rtk0 192.168.1.0/24 -> 91.193.165.158/32 portmap tcp/udp 10000:20000
193: map rtk0 192.168.1.0/24 -> 91.193.165.158/32
194:
195: 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
196:
197: 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:
198:
199: map rtk0 192.168.2.2/32 -> 91.193.165.158/32 proxy port ftp ftp/tcp
200: map rtk0 192.168.2.2/32 -> 91.193.165.158/32 portmap tcp/udp 10000:20000
201: map rtk0 192.168.2.2/32 -> 91.193.165.158/32
202:
203: For network with 254 hosts:
204:
205: map rtk0 192.168.2.0/24 -> 91.193.165.158/32 proxy port ftp ftp/tcp
206: map rtk0 192.168.2.0/24 -> 91.193.165.158/32 portmap tcp/udp 10000:20000
207: map rtk0 192.168.2.0/24 -> 91.193.165.158/32
208:
209: Or much more globally:
210:
211: map rtk0 0.0.0.0/0 -> 91.193.165.158/32 proxy port ftp ftp/tcp
212: map rtk0 0.0.0.0/0 -> 91.193.165.158/32 portmap tcp/udp 10000:20000
213: map rtk0 0.0.0.0/0 -> 91.193.165.158/32
214:
215: Note, ipnat translation is netmask sensitive thus you have to use only correct subnets.
216:
217: #subnets
218:
219: 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.
220:
221: To deal with subnets look for this table: [Image:Tablitsa1.jpg](/images/Tablitsa1.jpg) [Image:Tablitsa2.jpg](/images/Tablitsa2.jpg)
222:
223: For an additional calculations, you can use [net/sipcalc](http://pkgsrc.se/net/sipcalc).
224:
225: More information can be found at [Subnetwork](http://en.wikipedia.org/wiki/Netmask)
226:
227: #ipfilter
228:
229: Because both **ipfilter** and **ipnat** work together, check contents of **ipf.conf** file. Simple example is here:
230:
231: pass in from any to any
232: pass out from any to any
233:
234: However, some network cards, addresses and networks can be blocked or open.
235:
236: For advanced configuration see [IPFilter resources](http://www.obfuscation.org/ipf/) and [Packet Filter](http://netbsd.org/docs/network/pf.html).
237:
1.5 ! kim 238: #[resolv.conf](//man.NetBSD.org/resolv.conf)
1.2 schmonz 239:
240: The /etc/resolv.conf contains the addresses of nameservers, that allows to resolve alphabetical hostnames into numeric IP addresses.
241:
242: 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.
243:
244: In order to see which nameserver(s) are in use check contents of */etc/resolv.conf* file:
245:
246: nameserver 145.253.2.75
247: nameserver 194.146.112.194
248:
249: If the computer is the DNS server, the IP address usually is set like this:
250:
251: nameserver 127.0.0.1
252:
1.5 ! kim 253: If you experience 5-30 second delays while surfing, check with [dig](//man.NetBSD.org/dig), if all referred nameservers are really accessible, e.g:
1.2 schmonz 254:
255: $ dig @145.253.2.75 A www.netbsd.org
256:
257: #See also
258:
1.4 sevan 259: * [[How to set up a DHCP Server]]
1.2 schmonz 260: * [inetd](http://www.netbsd.org/docs/guide/en/chap-inetd.html#chap-inetd-services)
261: * [Network tools](http://www.netbsd.org/docs/guide/en/chap-tuning.html#tuning-ntools)
262: * [NetBSD Network](http://www.netbsd.org/docs/guide/en/chap-net-practice.html#chap-net-practice-small-net)
263: * [TCP/IP Networking](http://www.netbsd.org/docs/guide/en/chap-net-intro.html#chap-net-intro-tcpip-subnet)
264: * [Networking & related issues](http://www.netbsd.org/docs/guide/en/part-net.html)
265: * [Gnu Zebra](http://www.zebra.org/index.html)
266: * [Quagga Routing Suite](http://www.quagga.net/)
CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb