Search code examples
network-programmingdebianraspberry-piraspbianhostname

cannot resolve hostname (raspbian)


I have my hostname declared within /etc/environment as MYHOSTNAME=thisisaname

If I use this variable in the config files I get an error.

# cat /etc/hostname
$MYHOSTNAME

# cat /etc/hosts

stuff..

127.0.0.1.1 $MYHOSTNAME

Next I do sudo /etc/init.d/hostname.sh

With every sudo I do I get the error: cannot resolve hostname

I know that you get this error when the value in hostname is not the same as in hosts. I do not understand why because the /etc/environment file is loaded correctly.

Can somebody help me with this?

I want the hostname in a variable because I am making a config script which enables to set the hostname permanently.


Solution

  • populate /etc/hosts on the fly based on hostname content ...

    echo "127.0.0.1 $(hostname)" >> /etc/hosts
    

    or on HOSTNAME value :

    echo "127.0.0.1 $HOSTNAME" >> /etc/hosts
    

    /etc/hostname and /etc/hosts don't accept variables, they are bare text files.