# phpsysinfo canonical hostname [SOLVED]

## dvc5

I've tried searching around and can't seem to find a clear solution to this. I'm a bit new to apache and virtual hosts. I was wondering how to properly setup the canonical hostname for my machine so that it returns "vikingnet.dyndns.org" in phpsysinfo. Currently it returns "localhost." 

```
vikingnet root # cat /etc/hostname

vikingnet

vikingnet root # cat /etc/domainname

dyndns.org

vikingnet root # cat /etc/dnsdomainname

dyndns.org

vikingnet root #

```

My vhosts.conf:

```
################# vhosts.conf

#This is where we store the VirtualHosts configuration.

#

#Since Apache 1.3.19, we modified the setup to include some nice tricks:

#

#- Added SuExecUserGroup [user] [group] directive so VirtualHosts now work with

#  suexec directive. If set, Apache will run all cgi scripts under that

#  user and group (provided the uid and gid are > 1000 for security). The

#  directories and cgi files *must* belong to that user/group for the

#  feature to work

#- We added the Setenv VLOG directive. This works in conjunction with

#  the CustomLog in commonapache2.conf. When Setenv VLOG is set, apache will

#  create a /var/log/apache2/VLOG-YYYY-MM-<ServerName>.log instead of logging

#  to access_log. Use this instead of defining a special logfile for

#  each vhost, otherwise you eat up file descriptors.

#- You can also specify a path for the VLOG for each Vhost, for example,

#  to place the logs in each user's directory. However, if you want to

#  use the file for accounting, place it in a directory owned by root,

#  otherwise the user will be able to erase it.

#- I suggest only including the ErrorLog *only* if the vhost will use

#  cgi scripts. Again, it saves file descriptors!

 

################# IP-based Virtual Hosts

#<VirtualHost 192.168.2.100>

#SuExecUserGroup jmdault jmdault

#DocumentRoot /home/jmdault/public_html

#ServerName test2.com

#Setenv VLOG /home/jmdault/logs

#ErrorLogs /home/jmdault/test2-error_log

#RewriteEngine On

#RewriteOptions inherit

#</VirtualHost>

 

################# Named VirtualHosts

#NameVirtualHost 111.222.33.44

#<VirtualHost 111.222.33.44>

#ServerName www.domain.tld

#ServerPath /domain

#DocumentRoot /web/domain

#</VirtualHost>

 

NameVirtualHost *:80

 

##vikingnet.dyndns.org##############

<VirtualHost *:80>

ServerName vikingnet.dyndns.org

DocumentRoot /var/www/localhost/htdocs

</VirtualHost>
```

Is there some duh mistake I've made? Any help would be appreciated.

----------

## Deebster

Do you have your eth0 IP in /etc/hosts?

Also, if you don't plan to use virtual hosts, it's easier just to leave the vhosts.conf file all commented.  For this, you may need to turn UseCanonicalName Off in commonapache2.conf, which means the server will call itself what you've used to connect to it with (I'm assuming you're using apache 2).

----------

## dvc5

Okay, I've changed my commonapache2.conf to set UseCanonicalName Off, and my vhosts.conf is commented entirely since this is the only site hosted on the machine. My /etc/hosts file is the following:

```
# /etc/hosts:  This file describes a number of hostname-to-address

#              mappings for the TCP/IP subsystem.  It is mostly

#              used at boot time, when no name servers are running.

#              On small systems, this file can be used instead of a

#              "named" name server.  Just add the names, addresses

#              and any aliases to this file...

# $Header: /home/cvsroot/gentoo-src/rc-scripts/etc/hosts,v 1.7 2002/11/18 19:39:22 azarah Exp $

#

127.0.0.1       localhost                localhost

127.0.0.1       vikingnet.dyndns.org     vikingnet

127.0.0.1       vikingnet                vikingnet

192.168.0.18    vikingnet.dyndns.org     vikingnet
```

However it still returns "localhost" as the canonical hostname in phpsysinfo even though I've tried restarting apache2 and rebooting the whole machine. Thanks for any help you can offer.

----------

## Deebster

I just had a peek at the phpsysinfo code, and it seems that it gets that value from /proc/sys/kernel/hostname, which makes it nice and easy.

/etc/hostname is the correct file to update, but it only gets read at startup (when /etc/init.d/hostname sets the hostname in the boot run-level).

To change the hostname without rebooting do

#echo "vikingnet" > /proc/sys/kernel/hostname

or on Gentoo you can just do

# hostname "vikingnet"

I am assuming you haven't actually rebooted your machine since editing /eetc/hostname, if you have, then you have some more to do.

The hostname init script should be be running at boot, check this with

# rc-update -s | grep hostname

should show  hostname | boot

If it doesn't, run

# rc-update add hostname boot

----------

## dvc5

Thanks for the quick reply, however I'm still having the same problem.

```
vikingnet root # cat /proc/sys/kernel/hostname

vikingnet

vikingnet root # cat /proc/sys/kernel/domainname

dyndns.org

vikingnet root #

relevent apache2.conf section:

vikingnet root # cat /etc/apache2/conf/apache2.conf

### /etc/apache2/conf/apache2.conf

### $Id: apache2.conf,v 1.3 2003/09/25 02:20:48 woodchip Exp $

###

### Main Configuration Section

### You really shouldn't change these settings unless you're a guru

###

ServerRoot /etc/apache2

#ServerName vikingnet.dyndns.org

#LockFile /etc/apache2/apache2.lock

PidFile /var/run/apache2.pid

ErrorLog logs/error_log

LogLevel warn

DocumentRoot /var/www/localhost/htdocs

```

Perhaps it's falling back to some different hostname than what's in /proc/sys/kernel/hostname?

----------

## Deebster

Well the actual function is 

```
    // get our canonical hostname

    function chostname () {

        if ($fp = fopen('/proc/sys/kernel/hostname','r')) {

            $result = trim(fgets($fp, 4096));

            fclose($fp);

            $result = gethostbyaddr(gethostbyname($result));

        } else {

            $result = 'N.A.';

        }

        return $result;

    }
```

So let's do a code dry run  :Smile:   (Lazy me only skimmed it before, missing the important part)

It's definitely reading /proc/sys/kernel/hostname correctly, because you're not getting 'N.A.' returned.

We know the contents of hostname is 'vikingnet'

Looks like the problem is in gethostbyname()...

Remove the following line from your /etc/hosts

127.0.0.1       vikingnet     vikingnet

gethostbyname() is finding that line first, and returning that (so gethostbyname('vikingnet') == '127.0.0.1') and as we all know (and will certainly never forget now) gethostbyaddr(127.0.0.1) == localhostLast edited by Deebster on Sat Feb 28, 2004 8:40 pm; edited 1 time in total

----------

## dvc5

You are a genius! It works! Thanks so much for the help. I always miss those little details.   :Very Happy: 

----------

## Deebster

No problem, but could you tell me what's going on in your avatar?  :Wink: 

A ghost's head floating over something metal (armour?)?

----------

## dvc5

Hehe, that would be Lou Dog (R.I.P.). I'm a huge Sublime fan.   :Laughing: 

----------

## Deebster

Aaaah!  Now I see.  That clicked in like one of those magic eye stereogram pictures  :Wink: 

----------

## dvc5

If you're interested you can check out the phpsysinfo on my server: http://vikingnet.dyndns.org/sysinfo/

Too bad my mobo's so old 512MB is the maximum amt of ram.   :Sad: 

----------

## b0fh

I'm having a similar problem with phpsysinfo and my hostname. "cat /proc/sys/kernel/hostname" returns my (dyndns) hostname correct, but phpsysinfo seems to do a reverse-lookup on the ip of ppp0 which results in a hostname in the form "blabla-pool-something.myprovider.net" and I'd like more my nice dyndns-hostname there.

----------

## dvc5

What does your /etc/hosts file look like? The first entry is what phpsysinfo grabs.

----------

## Deebster

 *lozdvc5 wrote:*   

> What does your /etc/hosts file look like? The first entry is what phpsysinfo grabs.

 

Weeeell, not exactly.

/etc/nsswitch.conf defines what order stuff is looked up in.  Mine says "hosts:       files dns", not sure if that's default.  This means that it will check /etc/hosts before checking the dns server.  If dns was first, it would only read the hosts file if the lookup wasn't in the dns.

Your myprovider.net hostname is your official hostname, your dyndns just happens to point to the same place.

If you want to get phpsysinfo to report your dyndns address, the easiest way is just to edit htdocs/phpsysinfo/includes/os/class.Linux.inc.php and replace 

```
    function chostname () {

        if ($fp = fopen('/proc/sys/kernel/hostname','r')) {

            $result = trim(fgets($fp, 4096));

            fclose($fp);

            $result = gethostbyaddr(gethostbyname($result));

        } else {

            $result = 'N.A.';

        }

        return $result;

    }
```

 with 

```
    function chostname () {

        return 'your.dyndns.com';

    }
```

----------

