Skip to main content

Ever wonder how STCP knows what its name is? In the >system>stcp directory is a file called host. The file contains one line which is the name of the module. You can edit or display the file directly but I recommend that you use the hostname command. Without arguments it will display the contents of the host file.

hostname
athenavs
ready  13:46:51
Figure 1 – display the host name with the hostname command

If you provide an argument it will set the contents of the host file to that argument value, and that becomes the STCP host name.

hostname this-is-a-test
this-is-a-test
ready  13:47:00

hostname
this-is-a-test
ready  13:47:03
Figure 2 – Change the host name with the hostname command

Besides the command there is a  programming function to return the host name

#include <stdio.h>
#include <errno.h>
#include <netdb.h>

int errno;
void exit (int);

main ()
{
char name [32];

if (gethostname (name, 32) < 0)
{
perror ("ex_gethostname: Error getting hostname");
exit (errno);
}
else
printf ("hostname is %sn", name);
Figure 3 – Program using the gethostname function

A number of subsystems rely on the host name to be able to identify the module. They retrieve the name and either use the name as a character string or resolve the name into an IP address. If the name is not there, wrong, resolves to the wrong IP address or cannot be resolved the application may fail or function incorrectly.

For example if you are doing external authentication via a Radius server, the IP address of the module, resolved from the host name,  is sent in the Radius request packet in the NAS-IP-ADDRESS field. Your Radius server may reject the request if the IP address is not one it is expecting or if the provided user ID is not associated with that IP address.

The hostname command is part of the module_start_up command macro. It is not necessary to set the name every time the system boots since the name is persistent across boots, but it doesn’t hurt. The important thing is to make sure that the name is set to something that resolves to the correct IP address. Having the wrong name or the wrong IP address resolution may make subsystems like Radius, SSH or Samba unusable.

© 2024 Stratus Technologies.