# domainname

## Kronos

How's this work?  For a while I couldn't get the command domainname to tell me anything until I threw my domain name into the NISDOMAINNAME="DOMAIN" thing.  Still when the login prompt shows up I'm getting MACHINE.unknown_domain rather than my MACHINE.DOMAIN.

----------

## jmbsvicetto

Hi.

You're looking for dnsdomainname and not domainname. The latter is used for NIS. You should look at your /etc/conf.d/domainname and for the DNSDOMAIN definition

```
atlantis@atl64 ~/teste $ cat /etc/conf.d/domainname

OVERRIDE=1

DNSDOMAIN="acores.pt"

#NISDOMAIN=""

atlantis@atl64 ~/teste $  
```

----------

## richard.scott

I have the same problem as Kronos.

My /etc/conf.d/domainname is as follows:

```
# /etc/conf.d/domainname

# $Header: /var/cvsroot/gentoo-src/rc-scripts/etc/conf.d/domainname,v 1.1.4.1 2005/02/19 02:13:53 vapier Exp $

# When setting up resolv.conf, what should take precedence?

# If you wish to always override DHCP/whatever, set this to 1.

OVERRIDE=1

# To have a proper FQDN, you need to setup /etc/hosts and /etc/resolv.conf

# properly (domain entry in /etc/resolv.conf, and FQDN in /etc/hosts).

#

DNSDOMAIN="dnsdomain.com"

# This only set what /bin/hostname returns.  If you need to setup NIS, meaning

# what /bin/domainname returns, please see:

#

#   http://www.linux-nis.org/nis-howto/HOWTO/

#

NISDOMAIN=""
```

When my system boots the console login line tells me my machine is called box.dnsdomain.com. However, when I type in domainname at the command line I get nothing as the result. See below:

```
(root@box:~)# domainname

(root@box:~)# domainname -f

box.dnsdomain.com

(root@box:~)# hostname

box

(root@box:~)# hostname -f

box.dnsdomain.com

(root@box:~)#

```

It looks like somethings not working. when you look at sysctl output for domain you get:

```
(root@box:~)#sysctl -a | grep domainname

kernel.domainname = 
```

I have tried setting NISDOMAIN="nisdomain.com" to see what happens and I get the following output:

```
(root@box:~)# domainname

nisdomain.com

(root@box:~)# domainname -f

box.dnsdomain.com

(root@box:~)# hostname

box

(root@box:~)# hostname -f

box.dnsdomain.com

(root@box:~)#

```

and

```
(root@box:~)#sysctl -a | grep domainname

kernel.domainname = nisdomain.com
```

As you can see, setting NISDOMAIN correctly sets my domainame kernel settings too.

I can't see a bug for this as yet, as anyone else seen a bug listed or knows which file in baselayout sets the domainname?

----------

## richard.scott

ok, I think I've found the solution.

my current /etc/init.d/domainname file is as follows:

```
start() {

        local retval=0

        local retval2=0

        if checkconfig_nis ; then

                ebegin "Setting NIS domainname to ${NISDOMAIN}"

                /bin/domainname "${NISDOMAIN}"

                retval=$?

                eend ${retval} "Failed to set the NIS domainname"

        fi

        if checkconfig_dns ; then

                ebegin "Setting DNS domainname to ${DNSDOMAIN}"

                 resolv=$(grep -v '^[[:space:]]*domain' /etc/resolv.conf)

                [[ ${OVERRIDE} == "1" ]] \

                        && resolv="${resolv}"$'\n'"domain ${DNSDOMAIN}" \

                        || resolv="domain ${DNSDOMAIN}"$'\n'"${resolv}"

                echo "${resolv}" > /etc/resolv.conf

                retval2=$?

                eend ${retval2} "Failed to set the DNS domainname"

        fi

        return $((retval + retval2))

}

```

I've changed mine to be:

```
start() {

        local retval=0

        local retval2=0

        if checkconfig_nis ; then

                ebegin "Setting NIS domainname to ${NISDOMAIN}"

                /bin/nisdomainname "${NISDOMAIN}"

                retval=$?

                eend ${retval} "Failed to set the NIS domainname"

        fi

        if checkconfig_dns ; then

                ebegin "Setting DNS domainname to ${DNSDOMAIN}"

                /bin/domainname "${DNSDOMAIN}"

                resolv=$(grep -v '^[[:space:]]*domain' /etc/resolv.conf)

                [[ ${OVERRIDE} == "1" ]] \

                        && resolv="${resolv}"$'\n'"domain ${DNSDOMAIN}" \

                        || resolv="domain ${DNSDOMAIN}"$'\n'"${resolv}"

                echo "${resolv}" > /etc/resolv.conf

                retval2=$?

                eend ${retval2} "Failed to set the DNS domainname"

        fi

        return $((retval + retval2))

}
```

That made two changes to that part of the code:

Line 7 was : bin/domainname "${NISDOMAIN}" 

and is now:  bin/nisdomainname "${NISDOMAIN}" 

and I've added in a line around 14 of:

bin/domainname "${DNSDOMAIN}"

Looks like the lins had been missed out  :Embarassed: 

I'll go raise a bug report  :Cool: 

----------

## JC99

In /etc/hosts put the following

192.168.0.1     hostname.domainname.tld       hostname

----------

## basvanlola

I've solved the unknown_domain issue by adding my computer in /etc/hosts:

```

192.168.1.103 athlonbox.wassink athlonbox

```

I don't think this is a very 'clean' solution, but at least it works.

----------

## nixnut

Moved from Installing Gentoo to Networking & Security.

----------

## richard.scott

 *basvanlola wrote:*   

> I've solved the unknown_domain issue by adding my computer in /etc/hosts:
> 
> ```
> 
> 192.168.1.103 athlonbox.wassink athlonbox
> ...

 

I have found that I needed to do that to get postfix to detect the domainname correctly.

I always add it as the 127.0.0.1 address as follows:

 *Quote:*   

> 127.0.0.1 box.domainname.com box localhost

 

The seem to be needed in that order otherwise things aren't detected correctly for some reason.

Anyhow, thanks all for your help and advice!

----------

## magic919

One of my machines did this after an update.  I removed /etc/hostname, a symlink to /etc/conf.d/hostname and then it worked.

----------

## richard.scott

ok, it looks like I had misunderstood the usage of the domainname binary.

Apparently it is only for setting the NIS domain name.....doh!  :Embarassed: 

to set your dns domainname you only need to edit your /etc/resolv.conf and add in:

domain yourdomain.com

This is done for you by the /etc/init.d/domainname script from the DNSDOMAIN variable in /etc/conf.d/domainname.

time for a beer I think.  :Laughing: 

----------

## jmbsvicetto

Well, you can complain that in the good old *nix way the name is at least confusing. Most people is expecting the DNS name variable to be called DOMAINNAME and not DNSDOMANNAME. This one we must owe in part to SUN.

----------

