Random   •   Archives   •   RSS   •   About   •   Contact

Change default gateway on all SmartOS Zones and KVM guests

Today I needed to change the default gateway on every Zone and KVM guest on my SmartOS hypervisor because I switched my ISP and as a result my gateway changed from to After changing one guest I got lazy and put together this script.


for VM in `vmadm list -p -o alias,uuid`

    # create an array called VM_PARTS splitting on ':'
    IFS=':' VM_PARTS=($VM)

    # create some helper varibles for alias and uuid

    mac=`vmadm get $uuid | json nics | json -a mac`

    echo "
   \"update_nics\": [
        \"mac\": \"$mac\",
        \"gateway\": \"\"
" | vmadm update $uuid

[root@hypervisor /opt/setup-jsons/updates]# bash update-all-gateways.sh
Successfully updated VM 211b992b-a448-40b4-94c9-xxxxxxxxxxxx
Successfully updated VM 31baa6a5-aa98-4750-80df-xxxxxxxxxxxx
Successfully updated VM 65d176b4-c36d-4cbf-b6ed-xxxxxxxxxxxx
Successfully updated VM aa0f603c-9572-4cb0-b96f-xxxxxxxxxxxx
Successfully updated VM ad928301-f3e1-4fe8-a1c1-xxxxxxxxxxxx
Successfully updated VM b82a257e-5628-46db-aee4-xxxxxxxxxxxx
Successfully updated VM da72b638-51de-4d7d-9853-xxxxxxxxxxxx
Successfully updated VM ee42bf30-51ce-4ae2-915b-xxxxxxxxxxxx

You are welcome!

Also to change the global zone (head node) default gateway, edit /usbkey/config and then run the following commands:

[root@hypervisor /]# route delete default
delete net default: gateway

[root@hypervisor /]# route add default
add net default: gateway

[root@hypervisor /]# netstat -r

Want comments on your site?

Remarkbox — is a free SaaS comment service which embeds into your pages to keep the conversation in the same place as your contentr. It works everywhere, even static HTML sites like this one!

Remarks: Change default gateway on all SmartOS Zones and KVM guests

© Russell Ballestrini.