# Add random MAC to CONTEXT

**URL:** <https://forum.opennebula.io/t/add-random-mac-to-context/3467>\
**Category:** Product Support\
**Created:** [December 21, 2016, 12:19am UTC](https://forum.opennebula.io/t/add-random-mac-to-context/3467 "2016-12-21T00:19:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oscar](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/oscar/32/5120_2.png) [@oscar](https://forum.opennebula.io/u/oscar)\
**Post date:** [December 21, 2016, 12:19am UTC](https://forum.opennebula.io/t/add-random-mac-to-context/3467/1 "2016-12-21T00:19:51Z")

</div>

Hi,

I’d like to add the HWADDR parameter in the network script.

My template definition:  
NIC = [NETWORK = “blue”, IP = 192.168.2.3]  
NIC = [NETWORK = “interconnect”, IP = 192.168.100.3]

CONTEXT = [  
NETWORK = “YES”,  
BLUE\_IP = “$NIC[IP, NETWORK=“blue”]”,  
INTERCONNECT\_IP = “$NIC[IP, NETWORK=“interconnect”]”,  
**INTERCONNECT\_MAC = “$NIC[MAC, NETWORK=“interconnect”]”,**  
SET\_HOSTNAME = “$NAME”,  
DOMAIN=“[vdicube.com](http://vdicube.com)”  
]

Anybody knows how can I add it when the mac address is generated randomly by the system?

Thanks a lot.

---

<div class="post-metadata">

**Author:** ![mcabrerizo](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/mcabrerizo/32/4829_2.png) [@mcabrerizo](https://forum.opennebula.io/u/mcabrerizo)\
**Post date:** [December 22, 2016, 6:38pm UTC](https://forum.opennebula.io/t/add-random-mac-to-context/3467/2 "2016-12-22T18:38:29Z")

</div>

Hi oscar!  
I maybe wrong but the CONTEXT looks fine to me, your INTERCONNECT\_MAC should get the MAC address value for your NETWORK interconnect once the VM gets instantiated from the VM template, at that moment the MAC address will be generated randomly.

In any case, I assume that you’re preparing your own contextualization script so it can use that BLUE\_IP, INTERCONNECT\_IP variables aren’t you? but do you know that if you use the [contextualization scripts](http://docs.opennebula.org/5.2/operation/vm_setup/context_overview.html#context-overview) shipped by OpenNebula your IP, MAC, Gateway… would be set automatically as [ETHX\_ variables](http://docs.opennebula.org/5.2/operation/references/template.html?highlight=context#context-section) are added automatically to the context section if you set NETWORK=YES

Cheers!
