Viewing TCP connection data

The netstat utility provides a command line interface to retrieve system routing tables, connection states, and network statistics. Two of the available statisticss, “tcpPassiveOpens” and “tcpActiveOpens,” provide data on the number of new connections to a server (tcpPassiveOpens), and the number of connections initiated by the server (tcpActiveOpens). Both statistics counters can be retrieved with netstat’s “-s” option, and a simple while loop allows a SysAdmin to get a high level view of TCP connections to and from a server:

$ while :
> do
>        netstat -s | egrep '(tcpPassiveOpens|tcpActiveOpens)'
>       sleep 10
> done
        tcpActiveOpens      =  6228     tcpPassiveOpens     =    75
        tcpActiveOpens      =  6228     tcpPassiveOpens     =    75
        tcpActiveOpens      =  6228     tcpPassiveOpens     =    76
        tcpActiveOpens      =  6228     tcpPassiveOpens     =    85
        tcpActiveOpens      =  6228     tcpPassiveOpens     =   140
        tcpActiveOpens      =  6228     tcpPassiveOpens     =   197
        tcpActiveOpens      =  6228     tcpPassiveOpens     =   255

This is kinda fun to run on super busy web servers!!!

Regression testing Sun and Fujitsu hardware

When I get deploy new Fujitsu and Sun hardware, I always run VTS (Validation Test Suite) on the hardware platforma. VTS performs rigorous hardware testing, and **usually** finds faults in components that are faulty out of the box. The VTS commands are available in “/opt/SUNWvts/bin.”

The VTS tools rely on the RPC framework ( *grumble* ), so you need to make sure rpcbind is running prior to invoking the various utilities. To start the VTS GUI, you can execute the “sunvts” or “fjvts” utility:

$ sunvts &

To get a curses based display, you can pass the “-t” option to the “sunvts” or “fjvts” utility:

$ sunvts -t

Once the display appears, I usually navigate to “set_options” -> “Test_Execution” and enable the “Verbose” and “Run On Error” options. The “Run On Error” option allows the validation test suite to continue operating if it finds an error. The “Verbose” option causes a plethora of information to be printed to the console display. Once these items are enabled, you can hit “start,” and watch the test suite leep into action. I find it useful to tail(1) /var/adm/messages while VTS is running. This will allow you to see hardware error discovery as it happen.

Apache Name-based virtual hosts

Name-based virtual hosts allow a web server to host multiple domain names (,, from one IP address. This allows a web hosting infrastructure to conserve IP address space, and simplify namespace management.

Apache name-based virtual hosts are configured with the “NameVirtualHost” and “VirtualHost” directives, and rely on the HTTP “Host:” header attribute. This attribute is required in HTTP 1.1, and should be present with every request. The following example grabs /index.html using the HTTP/1.1 protocol:

$ telnet 80
Connected to
Escape character is '^]'.
GET / HTTP/1.1

HTTP/1.1 200 OK
Date: Thu, 24 Feb 2005 16:33:23 GMT
Server: Apache/2.0.52
Last-Modified: Sun, 20 Jun 2004 14:39:21 GMT
ETag: "d54a2-912-c108d840"
Accept-Ranges: bytes
Content-Length: 2322
Content-Type: text/html

[ ... ]

Based on this output, it looks like my friend Clay needs to obscure his “Server:” header. Server identification is controlled with the “ServerTokens” directives.

Converting Solaris packages

The Solaris package commands (e.g., pkgproto, pkgadd, pkgtrans ) operate on two package formats. The first format is the “datastream” format. Packages created as datastream formatted packages use a single self contained file. This file includes the binary contents, application configuration files, and metadata to describe the package and installation process. The second format is the “file system format.” File system formatted packages contain hierarchical directory structures with all of the binaries, configuration, and metadata to describe the packages.

Both package formats can be installed with the pkgadd(1m) utility, and serve a unique purpose. Datastream formatted files are usually easier to distribute, since an archiving tool is removed from the installation/bundling process. File system formatted packages are nice to use with Solaris Jumpstart post install scripts, and make locating individual files within a package much easier.

The Solaris pkgtrans utility allows you to convert between both formats relatively easily. The following example takes a datastream formatted package, and converts it to a file system formatted package:

$ pkgtrans -o /tmp/RICHPse /var/tmp RICHPse

When pkgtrans is invoked with the “-s” option, packages can be converted from file system to datastream format:

$ pkgtrans -s /tmp /var/tmp/RICHPse.pkg RICHPse

A lot of people complain about Sun packages, but I find them easy to build, manage, and support.

Grabbing a protected webpage from the command line

Ever needed to grab a password protected page from the command line? This can be accomplished with curl’s “-u” option:

$ curl -k -i -u me:somethingstrong |more

The username and password can be passed as an argument to the “-u” option. If you are paranoid about your password being visible on the command line, you can omit the password, and curl will prompt you for it:

$ curl -k -i -u me

In case you are curious, the “-k” option forces curl to dump the HTTP headers. I use both options to debug web server issues.

Reading OpenBSD PF log entries in realtime

When the OpenBSD packet filter (PF) is configured to log traffic, each packet is logged to the OpenBSD “pflog” pseudo-device. This device can be queried with several tools, including tcpdump:

oscar# tcpdump -i pflog0 -ttt -e -o
tcpdump: WARNING: pflog0: no IPv4 address assigned
tcpdump: listening on pflog0
Jan 23 21:27:33.361173 rule 4/0(match): block in on tun0: > icmp: echo request
Jan 23 21:28:01.505716 rule 4/0(match): block in on tun0: > S (src OS: short-pkt) 3962893738:3962893738(0) win 5840 (DF)

If you are running a busy firewall, you are probably using pflogd to archive this information to a file on your FFS file system. I occassionally like to monitor pflog0 when I am testing new services, especially ones that don’t play nicely with firewalls.