# Custom routes for VMs

**URL:** <https://forum.opennebula.io/t/custom-routes-for-vms/6167>\
**Category:** Product Support\
**Created:** [July 16, 2018, 4:49pm UTC](https://forum.opennebula.io/t/custom-routes-for-vms/6167 "2018-07-16T16:49:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [July 16, 2018, 4:49pm UTC](https://forum.opennebula.io/t/custom-routes-for-vms/6167/1 "2018-07-16T16:49:00Z")

</div>

Hi,  
I’m trying to generate a “/etc/sysconfig/network-scripts/route-eth0” to add custom routes to my VM. The reason why I need to do this, is simply because we have 2 sets of FW/Routers. 1 is the public firewall, 2 is the internal firewall providing network access to private subnets.  
The way I was hoping to achieve this is by adding a custom attribute named “INTERNAL\_GATEWAY” (in this case 10.4.4.4) to the virtual network. And using the the START\_SCRIPT in the VM template, I would populate the file like this:

```
# File generated by opennebula
10.0.0.0/8 via 10.4.4.4
192.168.0.0/16 via 10.4.4.4

```

I was trying to access the network templates values from the start script but it doesn’t seem possible as $NETWORK is empty. I also tried to create a custom var in the VM template like this  
INTERNAL\_GATEWAY=$NETWORK[INTERNAL\_GATEWAY, NETWORK\_ID=$NIC[NETWORK\_ID]]  
but is seems the nested variables are not supported, see the following error:

```
one.template.instantiate result FAILURE [one.template.instantiate] Error allocatin
g a new virtual machine template. Error parsing: DISK_ID=1@^_^@INTERNAL_GATEWAY=$NETWORK[INTERNAL_GATEWAY, NETWORK_ID=$NIC[NETWORK_ID]]
@^_^@NETWORK=YES... syntax error, unexpected OBRACK
ET, expecting CBRACKET at line 1869902689, columns 74:75

```

What would be way to achieve what I am trying to do here ?

Thank you

* * *

\*\*Versions of the related components and OS (frontend, hypervisors, VMs): 5.4.13 \*\*

---

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [July 17, 2018, 11:23am UTC](https://forum.opennebula.io/t/custom-routes-for-vms/6167/2 "2018-07-17T11:23:16Z")

</div>

I found how to do this, but I believe the instructions on how to do this should be included relevant sections like this one: [http://docs.opennebula.org/5.0/operation/network\_management/manage\_vnets.html](http://docs.opennebula.org/5.0/operation/network_management/manage_vnets.html)

I found the info here: [https://github.com/OpenNebula/one/issues/959](https://github.com/OpenNebula/one/issues/959)

---

<div class="post-metadata">

**Author:** ![bms8197](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/bms8197/32/5288_2.png) [@bms8197](https://forum.opennebula.io/u/bms8197)\
**Post date:** [July 17, 2018, 11:24am UTC](https://forum.opennebula.io/t/custom-routes-for-vms/6167/3 "2018-07-17T11:24:05Z")

</div>

A workaround, probably not the most elegant one, would be this:

In the OS template used to instantiate a new VM, go to the Context section and there, in the startup script do something like:

```
cat > /etc/sysconfig/network-scripts/route-eth <<EOF
# File generated by opennebula
10.0.0.0/8 via 10.4.4.4
192.168.0.0/16 via 10.4.4.4
EOF

```

Click Update. Now, the newly deployed VMS, using the above mentioned template, will have this as default.

What I’m usually doing is this. Deploy a new VM from a standard template, customizing that VM the way I like or need, updating all the packages, add/create any custom configuration that I need. When I’m done with that VM, I power it off, save it as a template and then I deploy the new virtual machines from that template (saves time and I have it customized the way I like or need).

Hope it helps!

---

<div class="post-metadata">

**Author:** ![jsfrerot](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.opennebula.io/jsfrerot/32/6690_2.png) [@jsfrerot](https://forum.opennebula.io/u/jsfrerot)\
**Post date:** [August 29, 2018, 9:55pm UTC](https://forum.opennebula.io/t/custom-routes-for-vms/6167/4 "2018-08-29T21:55:58Z")

</div>

Thx for the tips. Works well !
