# Impossible to set IP address when onetemplate instantiate

**URL:** <https://forum.opennebula.io/t/impossible-to-set-ip-address-when-onetemplate-instantiate/11650>\
**Category:** Installation & Configuration\
**Created:** [November 2, 2023, 2:56pm UTC](https://forum.opennebula.io/t/impossible-to-set-ip-address-when-onetemplate-instantiate/11650 "2023-11-02T14:56:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![d.yermak](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@d.yermak](https://forum.opennebula.io/u/d.yermak)\
**Post date:** [November 2, 2023, 2:56pm UTC](https://forum.opennebula.io/t/impossible-to-set-ip-address-when-onetemplate-instantiate/11650/1 "2023-11-02T14:56:46Z")

</div>

Hello!

I keep getting “Cannot get IP/MAC lease from virtual network” trying to run:

onetemplate instantiate 69 --hold   
–name testvm --memory 2048  
–cpu 4 --vcpu 4   
–user-inputs “SET\_HOSTNAME=test”,“CORES\_PER\_SOCKET=2”,“IPADDR”=“10.50.28.100”

but it gets ip address OK when I set the var directly like that:

NIC = [  
IP = “10.50.28.100”,  
…  
]

I think the possible reason may be that no IP variable substitution happens when  
IP = $IPADDR  
(am I right here?)

## Extracts from the template:

CONTEXT = [  
CORES\_PER\_SOCKET = “$CORES\_PER\_SOCKET”,  
IPADDR = “$IPADDR”,  
SET\_HOSTNAME = “$SET\_HOSTNAME”,  
NETWORK = “YES”,  
]  
…  
NIC = [  
IP = “$IPADDR”,  
NETWORK = “WN\_int\_10-50-28-15”,  
NETWORK\_UNAME = “gridadmin”,  
SECURITY\_GROUPS = “0” ]  
…  
USER\_INPUTS = [  
CORES\_PER\_SOCKET = “M|number|cores per socket| |”,  
IPADDR = “M|text|ipaddress| |”,  
SET\_HOSTNAME = “M|text|VM hostname| |” ]

## Notes:

Other variables SET\_HOSTNAME and CORES\_PER\_SOCKET that is used in section  
TOPOLOGY = [CORES = “$CORES\_PER\_SOCKET”, …]

are initiated OK.

I tried disable/enable network contextualization  
CONTEXT = [  
…  
NETWORK = “YES”,  
]

with no luck.

My OpenNebula version: 6.2.0.1

best regards,  
Dzmitry

---

<div class="post-metadata">

**Author:** ![dclavijo](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/dclavijo/32/5265_2.png) [@dclavijo](https://forum.opennebula.io/u/dclavijo)\
**Post date:** [November 3, 2023, 3:15pm UTC](https://forum.opennebula.io/t/impossible-to-set-ip-address-when-onetemplate-instantiate/11650/2 "2023-11-03T15:15:15Z")

</div>

Instead of defining the IP parameter in the NIC, try and define ETH0\_IP in the CONTEXT section.

For example

```auto
CONTEXT = [
CORES_PER_SOCKET = “$CORES_PER_SOCKET”,
ETH0_IP="$IPADDR",
SET_HOSTNAME = “$SET_HOSTNAME”,
NETWORK = “YES”,
]
…
NIC = [
NETWORK = “WN_int_10-50-28-15”,
NETWORK_UNAME = “gridadmin”,
SECURITY_GROUPS = “0” ]
…
USER_INPUTS = [
CORES_PER_SOCKET = “M|number|cores per socket| |”,
IPADDR = “M|text|ipaddress| |”,
SET_HOSTNAME = “M|text|VM hostname| |” ]

```

---

<div class="post-metadata">

**Author:** ![d.yermak](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@d.yermak](https://forum.opennebula.io/u/d.yermak)\
**Post date:** [November 8, 2023, 2:14pm UTC](https://forum.opennebula.io/t/impossible-to-set-ip-address-when-onetemplate-instantiate/11650/3 "2023-11-08T14:14:59Z")

</div>

Daniel,

thank you very much for your reply.

Unfortunatly, it does not work. It looks like Opennebula ignores direct ETH0\_IP setting.

As a result I can see that settings in the VM template:

## User template

CORES\_PER\_SOCKET = “2”  
IPADDR = “"10.50.28.100"”  
USER\_INPUTS = [  
CORES\_PER\_SOCKET = “M|number|cores per socket| |”,  
IPADDR = “M|text|ipaddress| |"10.50.28.100"”,  
SET\_HOSTNAME = “M|text|VM hostname| |” ]

## Template

CONTEXT = [  
…  
CORES\_PER\_SOCKET = “2”,  
ETH0\_IP = “10.50.28.100”,  
NETWORK = “YES”,  
SET\_HOSTNAME = “test”]

NIC = [  
IP = “10.50.28.15”,  
NAME = “NIC0”,  
NETWORK = “WN\_int\_10-50-28-15” ]

TOPOLOGY = [  
…  
CORES = “$CORES\_PER\_SOCKET” ]

My 10.50.28.100 is ignored and 10.50.28.15 is autoselected from available Network address range.

p.s. and I found that “Add network contextualization” checkbock has no effect on the selection process.

Dzmitry

---

<div class="post-metadata">

**Author:** ![dclavijo](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/dclavijo/32/5265_2.png) [@dclavijo](https://forum.opennebula.io/u/dclavijo)\
**Post date:** [November 9, 2023, 2:52pm UTC](https://forum.opennebula.io/t/impossible-to-set-ip-address-when-onetemplate-instantiate/11650/4 "2023-11-09T14:52:46Z")

</div>

I think the problem could be that you have both `NIC[IP]` and `CONTEXT[ETH0_IP]`. Try removing `NIC[IP]` and just leave `ETH0_IP` in CONTEXT.

---

<div class="post-metadata">

**Author:** ![d.yermak](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@d.yermak](https://forum.opennebula.io/u/d.yermak)\
**Post date:** [November 13, 2023, 2:13pm UTC](https://forum.opennebula.io/t/impossible-to-set-ip-address-when-onetemplate-instantiate/11650/5 "2023-11-13T14:13:50Z")

</div>

Daniel,  
thank you!

The problem was that I set no NIC[IP] when instantiated that VM. That value 10.50.28.15 was autoselected and desirable IP was ignored.

I posted the template of active and running VM, I can see it in menu “Instances” → “VM”.

I tried different combinations of settings. In the end I just used web fontend to start all my VMs. There was no problem to set desirable IP addresses for VMs by GUI - unlike CLI.

Dzmitry
