# FQDN in SET\_HOSTNAME

**URL:** https://forum.opennebula.io/t/fqdn-in-set-hostname/2680
**Category:** Product Support
**Created:** [July 29, 2016, 4:51pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680 "2016-07-29T16:51:56Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [July 29, 2016, 4:51pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/1 "2016-07-29T16:51:56Z")

</div>

Fairly new to ONE and have what may be a n00b question. I am trying to set FQDN in context using SET\_HOSTNAME="$[NAME.example.com](http://NAME.example.com)". The machine keeps coming back online as $NAME-example-com. Is there a way to keep the dots or is there a way to set $DOMAIN and use that?

Thanks

Tony

---

<div class="post-metadata">

### Author: ![ruben](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ruben/32/19_2.png) [@ruben](https://forum.opennebula.io/u/ruben)
#### Post date: [August 2, 2016, 9:01am UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/2 "2016-08-02T09:01:23Z")

</div>

The info is here:

[http://docs.opennebula.org/5.0/operation/vm\_setup/kvm.html](http://docs.opennebula.org/5.0/operation/vm_setup/kvm.html)

and here:

[http://docs.opennebula.org/5.0/operation/references/template.html#template-context](http://docs.opennebula.org/5.0/operation/references/template.html#template-context)

Make sure you have installed the context packages in the VM.

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 2, 2016, 1:48pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/3 "2016-08-02T13:48:37Z")

</div>

Thanks for the reply!

So yeah I am using the Centos image from marketplace and I verified that it has context packages installed in the VM.

I tried adding $DOMAIN as a custom variable and then SET\_HOSTNAME as $NAME.$DOMAIN and that didn’t work. Also, when I put FQDN into SET\_HOSTNAME the dots are replaced with “-” when instantiated on the VM.

I am sure that I can come up with some script that gets FQDN set after first boot, or bake it into the image, but it looks like there should be a way when I am instantiating.

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 2, 2016, 1:56pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/4 "2016-08-02T13:56:21Z")

</div>

I also just tried leaving it $NAME and added the machine as [test.example.com](http://test.example.com). It shows up as “[test.example.com](http://test.example.com)” in sunstone, but on the VM the hostname is “test-example-com”.

---

<div class="post-metadata">

### Author: ![ruben](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ruben/32/19_2.png) [@ruben](https://forum.opennebula.io/u/ruben)
#### Post date: [August 2, 2016, 1:57pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/5 "2016-08-02T13:57:32Z")

</div>

Can you post the output of onetemplate show and onevm show for the template  
and the resulting instantiated VM?

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 2, 2016, 2:05pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/6 "2016-08-02T14:05:37Z")

</div>

Sure…this is REALLY weird. Looks like it should be working. I also posted the hostname command at the end showing the dashes.

_onetemplate show 0 ---------\>_

TEMPLATE 0 INFORMATION  
ID : 0  
NAME : CentOS 7.2 - KVM  
USER : oneadmin  
GROUP : oneadmin  
REGISTER TIME : 06/15 14:56:49

PERMISSIONS  
OWNER : um-  
GROUP : —  
OTHER : —

TEMPLATE CONTENTS  
CONTEXT=[  
DOMAIN=“[dkistdc.nso.edu](http://dkistdc.nso.edu)”,  
NETWORK=“YES”,  
SET\_HOSTNAME="$NAME",  
SSH\_PUBLIC\_KEY="$USER[SSH\_PUBLIC\_KEY]",  
START\_SCRIPT="#!/bin/sh  
if [! -f /etc/salt/minion]; then  
yum clean all  
yum -y update  
yum -y install salt-minion  
systemctl enable salt-minion.service  
systemctl start salt-minion.service  
fi" ]  
CPU="1"  
DISK=[  
IMAGE=“CentOS 7.2 - KVM”,  
IMAGE\_UNAME=“oneadmin” ]  
DISK=[  
IMAGE=“Test Disk”,  
IMAGE\_UNAME=“thays” ]  
GRAPHICS=[  
LISTEN=“0.0.0.0”,  
TYPE=“VNC” ]  
LOGO="images/logos/centos.png"  
MEMORY="768"  
NIC=[  
NETWORK=“Mgmt”,  
NETWORK\_UNAME=“oneadmin” ]  
OS=[  
ARCH=“x86\_64” ]

_onevm show 71 output -------\>_

VIRTUAL MACHINE 71 INFORMATION  
ID : 71  
NAME : [dnstest2.dkistdc.nso.edu](http://dnstest2.dkistdc.nso.edu)  
USER : thays  
GROUP : oneadmin  
STATE : ACTIVE  
LCM\_STATE : RUNNING  
RESCHED : No  
HOST : drax  
CLUSTER ID : 0  
CLUSTER : default  
START TIME : 08/02 07:52:54  
END TIME : -  
DEPLOY ID : one-71

VIRTUAL MACHINE MONITORING  
CPU : 74.94  
MEMORY : 1G  
NETTX : 1.6M  
NETRX : 222.6M

PERMISSIONS  
OWNER : um-  
GROUP : —  
OTHER : —

VM DISKS  
ID DATASTORE TARGET IMAGE SIZE TYPE SAVE  
0 default vda CentOS 7.2 - KVM 1.2G/8G file NO  
1 default vdb Test Disk 1000M/100 file NO  
2 - hda CONTEXT 1M/- - -

VM NICS  
ID NETWORK BRIDGE IP MAC PCI\_ID  
0 Mgmt br0 10.224.128.205 02:00:0a:e0:80:cd

SECURITY

NIC\_ID NETWORK SECURITY\_GROUPS  
0 Mgmt 0

SECURITY GROUP TYPE PROTOCOL NETWORK RANGE  
ID NAME VNET START SIZE  
0 default OUTBOUND ALL  
0 default INBOUND ALL

VIRTUAL MACHINE HISTORY  
SEQ HOST ACTION DS START TIME PROLOG  
0 drax none 0 08/02 07:53:13 0d 00h07m 0h00m19s

USER TEMPLATE  
LOGO=“images/logos/centos.png”

VIRTUAL MACHINE TEMPLATE  
AUTOMATIC\_DS\_REQUIREMENTS="“CLUSTERS/ID” @\> 0"  
AUTOMATIC\_REQUIREMENTS="(CLUSTER\_ID = 0) & !(PUBLIC\_CLOUD = YES)“  
CONTEXT=[  
DISK\_ID=“2”,  
DOMAIN=“[dkistdc.nso.edu](http://dkistdc.nso.edu)”,  
ETH0\_CONTEXT\_FORCE\_IPV4=”",  
ETH0\_DNS=“10.224.128.13”,  
ETH0\_GATEWAY=“10.224.128.1”,  
ETH0\_GATEWAY6="",  
ETH0\_IP=“10.224.128.205”,  
ETH0\_IP6="",  
ETH0\_IP6\_ULA="",  
ETH0\_MAC=“02:00:0a:e0:80:cd”,  
ETH0\_MASK="",  
ETH0\_MTU="",  
ETH0\_NETWORK="",  
ETH0\_SEARCH\_DOMAIN=“[dkistdc.nso.edu](http://dkistdc.nso.edu)”,  
ETH0\_VLAN\_ID="",  
ETH0\_VROUTER\_IP="",  
ETH0\_VROUTER\_IP6="",  
ETH0\_VROUTER\_MANAGEMENT="",  
NETWORK=“YES”,  
SET\_HOSTNAME=“[dnstest2.dkistdc.nso.edu](http://dnstest2.dkistdc.nso.edu)”,  
SSH\_PUBLIC\_KEY=“ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdI0ldF55NEfr/mSSZL/Ft4kjuJnuzTftwunYI/x63ORJFf/LclNOGGqSRPlxYPBZXAPbImu1O9qndn9XLcJYZuTRgWIXQOJXmlxjtN3BNI1VGYWSyhloyslCbEviMKklkjYBzDy4+aBgciyGzKsEDe4XF9pcPPfhQLWHRrvCQ1Jq6hXDSTjfCJ2PiaTMf5oZqmfnguDfDgfjdjCb3YVrPW7rpHzKjg1+MFAQt3GujnQwQkMKbDQrGmCzFNKeRoyAx4YWwykF1T3eHSCr1QLa7IcASQTz1kZsqNkDY8H8ygW7JaU1RV96p1Qor9jq2PKbv4BZhFVVfitYWTe+H6LFz”,  
START\_SCRIPT="#!/bin/sh  
if [! -f /etc/salt/minion]; then  
yum clean all  
yum -y update  
yum -y install salt-minion  
systemctl enable salt-minion.service  
systemctl start salt-minion.service  
fi",  
TARGET=“hda” ]  
CPU="1"  
GRAPHICS=[  
LISTEN=“0.0.0.0”,  
PORT=“5971”,  
TYPE=“VNC” ]  
MEMORY="1024"  
OS=[  
ARCH=“x86\_64” ]  
TEMPLATE\_ID="0"  
VMID=“71”

_hostname output ----------------\>_

[root@dnstest2-dkistdc-nso-edu ~]# hostname  
**dnstest2-dkistdc-nso-edu**

---

<div class="post-metadata">

### Author: ![ruben](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ruben/32/19_2.png) [@ruben](https://forum.opennebula.io/u/ruben)
#### Post date: [August 2, 2016, 2:21pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/7 "2016-08-02T14:21:18Z")

</div>

Yes you are right SET\_HOSTNAME is for the hostname which is different from the FQDN. Unsafe chars are explicitly removed:

> echo “$SET\_HOSTNAME” | sed -e ‘s/[^-a-zA-Z0-9]/-/g’ -e ‘s/^-​\*//g’ -e ‘s/-\*​$//g’  
> dnstest2-dkistdc-nso-edu

This is what is happening for the VM.

---

<div class="post-metadata">

### Author: ![ruben](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ruben/32/19_2.png) [@ruben](https://forum.opennebula.io/u/ruben)
#### Post date: [August 2, 2016, 2:23pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/8 "2016-08-02T14:23:23Z")

</div>

By the way, you can add SEARCH\_DOMAIN and DNS in the Network template to  
configure the DNS client for VMs in that network…

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 2, 2016, 2:31pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/9 "2016-08-02T14:31:26Z")

</div>

So the “.” is an unsafe char?

I have the SEARCH\_DOMAIN and DNS working now and it resolves great.

My main issue is that my config management relies on FQDN, so when it auto-registers itself without FQDN it is rejected.

Is there no way to escape the “.” to override and have SET\_HOSTNAME be exact?

---

<div class="post-metadata">

### Author: ![ruben](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ruben/32/19_2.png) [@ruben](https://forum.opennebula.io/u/ruben)
#### Post date: [August 2, 2016, 2:34pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/10 "2016-08-02T14:34:47Z")

</div>

You can:

1.- Modify the context script

2.- Do it after context with something like `hostname $NAME` in the  
START\_SCRIPT as it is executed after the network set up.

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 2, 2016, 2:37pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/11 "2016-08-02T14:37:58Z")

</div>

That’s a good idea. Just keep it to shortname in ONE and handle it externally.

Thanks so much for your help!

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 2, 2016, 2:42pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/12 "2016-08-02T14:42:07Z")

</div>

Do you know if context variables are passed into the startup script or do I need to set them there as well?

---

<div class="post-metadata">

### Author: ![ruben](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/ruben/32/19_2.png) [@ruben](https://forum.opennebula.io/u/ruben)
#### Post date: [August 2, 2016, 2:49pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/13 "2016-08-02T14:49:56Z")

</div>

They should be available

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 15, 2016, 4:52pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/14 "2016-08-15T16:52:45Z")

</div>

Hi Ruben,

So I ended up with a pretty good solution, I think. I have SET\_HOSTNAME=$NIC[IP]-$UNAME-$VMID. Once I instantiate this becomes x-x-x-x-thays-x as the hostname, on the box which is exactly what I am looking for. I am trying to figure out what is swapping out the delimiter. Is this base64 encoding that is actually swapping the “.” for the “-”? I have a dns hook that uses SET\_HOSTNAME and it actually shows up as x.x.x.x-thays-x, and it is conflicting with the name that was set by the template.

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 15, 2016, 6:56pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/15 "2016-08-15T18:56:59Z")

</div>

Where does this sed take place?

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 15, 2016, 8:32pm UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/16 "2016-08-15T20:32:39Z")

</div>

I found the sed in addon-context-linux. Is there a reason that “.” is considered unsafe? Is the code just manipulating the text so it can be standard input to hostnamectl? For example, collapsing spaces. I feel like there must be some history here I am missing.

Thanks

---

<div class="post-metadata">

### Author: ![anandharaj](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@anandharaj](https://forum.opennebula.io/u/anandharaj)
#### Post date: [August 16, 2016, 2:11am UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/17 "2016-08-16T02:11:20Z")

</div>

for hostname, “.” is consider unsafe because “.” is used as delimiter between hostname and domain. So the parameter “SET\_HOSTNAME” is passing the hostname only.

So if you need to append the domain name, modify the one-context script (/etc/one-context.d/05-hostname) and add the domain

---

<div class="post-metadata">

### Author: ![t0nyhays](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/t0nyhays/32/4749_2.png) [@t0nyhays](https://forum.opennebula.io/u/t0nyhays)
#### Post date: [August 16, 2016, 2:32am UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/18 "2016-08-16T02:32:47Z")

</div>

Perfect…Thanks for the reply.

---

<div class="post-metadata">

### Author: ![jfontan](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jfontan/32/18_2.png) [@jfontan](https://forum.opennebula.io/u/jfontan)
#### Post date: [August 17, 2016, 10:55am UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/19 "2016-08-17T10:55:32Z")

</div>

I’m thinking that setting FQDN is useful but I’m not sure how to implement this.

- Remove “.” restriction from `SET_HOSTNAME`
- Add `SET_DOMAIN` and use it to set the FQDN

I believe that letting use “.” is the most straightforward solution and maybe what people expect.

---

<div class="post-metadata">

### Author: ![anandharaj](https://avatars.discourse-cdn.com/v4/letter/a/6bbea6/32.png) [@anandharaj](https://forum.opennebula.io/u/anandharaj)
#### Post date: [August 24, 2016, 1:28am UTC](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680/20 "2016-08-24T01:28:25Z")

</div>

I prefer the second option using the “SET\_DOMAIN” or use “SET\_FQDN”

[Next page](https://forum.opennebula.io/t/fqdn-in-set-hostname/2680.md?page=2)
