gve-sw / gve_devnet_meraki_vlan_dns_bulk_update

This script modifies the DHCP DNS Nameservers for all VLANs across all appliance networks based on a selected matching criteria. The script only considers MX VLANs which are running a DHCP Server and meet the matching criteria.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Meraki VLAN DNS Bulk Update Tool

This script modifies the DHCP DNS Nameservers for all VLANs across all appliance networks based on a selected matching criteria. The script only considers MX VLANs which are running a DHCP Server and meet the matching criteria. For VLAN's which are matched, the script replaces or appends to existing DNS values with new DNS Nameserver values.

The following Nameserver Values are supported for matching and configuration:

  • Umbrella (opendns)
  • Google (google_dns)
  • Proxy to Upstream (upstream_dns)
  • Custom Nameservers (IPs and Domain Names)

Supported matching criteria (and configuration behavior) are divided into 2 groups: Cloud, Custom IP/Domain

Note: You CANNOT mix cloud and custom IP/domains within matching criteria or replacement configuration.

Cloud:

If a list of 1 or more cloud options (opendns, googledns, upstream_dns) is provided for matching, VLANs which utilize any of the cloud options will be matched. The replacement configuration will be applied holistically, as is (this could be a different cloud option, or a list of Custom IPs/Domains).

Note: 1 or more options can be provided in the matching criteria, but only 1 cloud option can be provided in the replacement configuration.

Custom IP/Domain:

If matching on a list of Custom IPs/Domains, the following matching options are supported:

  1. All: Replace (or Append) All VLAN DNS Values with a new list of IPs/Domains
  2. Exact Match: Match explicit list of old DNS Values, replace with a list of new IPs/Domains
  3. Find and Replace: Match old DNS Values which contain a provided list, remove old values, append new list of IPs/Domains.

The replacement behavior of each option is only relevant if the replacement configuration is a list of Custom IPs/Domains. If the replacement configuration is a cloud option, all previous DNS configuration will be replaced with the cloud option regardless of selection.

Contacts

  • Trevor Maco

Solution Components

  • Meraki

Prerequisites

Meraki API Keys

In order to use the Meraki API, you need to enable the API for your organization first. After enabling API access, you can generate an API key. Follow these instructions to enable API access and generate an API key:

  1. Login to the Meraki dashboard
  2. In the left-hand menu, navigate to Organization > Settings > Dashboard API access
  3. Click on Enable access to the Cisco Meraki Dashboard API
  4. Go to My Profile > API access
  5. Under API access, click on Generate API key
  6. Save the API key in a safe place. The API key will only be shown once for security purposes, so it is very important to take note of the key then. In case you lose the key, then you have to revoke the key and a generate a new key. Moreover, there is a limit of only two API keys per profile.

For more information on how to generate an API key, please click here.

Note: You can add your account as Full Organization Admin to your organizations by following the instructions here.

Installation/Configuration

  1. Clone this repository with git clone [repository name]
  2. Rename the .env_sample file to .env. Rename config_sample.py to config.py.
  3. Add Meraki API key to environment variable in .env.
API_KEY="0F...."
  1. Add Meraki Org Name to configuration variable in config.py. Specify an optional list of keywords to filter network names on. The filtering checks if the network name 'contains' one or more provided words. Provide a list of Old DNS values (matching criteria) and New DNS values in config.py. Depending on selected matching criteria, the old list is used to match VLANs and the new list represents replacement values for the old values.
Ex: Match all VLANs with only DNS values (X.X.X.X, Y.Y.Y.Y) and replace them with (Z.Z.Z.Z) (Explicit match - Option 2)
# Meraki API Section
ORG_NAME = "Sample"

# Keywords to Filter Network Names on (case-sensitive) - optional
NETWORK_NAMES = [""]

# DNS Values
OLD_DHCP_DNS_VALUES = ["X.X.X.X", "Y.Y.Y.Y"]
NEW_DHCP_DNS_VALUES = ["Z.Z.Z.Z"]
  1. Set up a Python virtual environment. Make sure Python 3 is installed in your environment, and if not, you may download Python here. Once Python 3 is installed in your environment, you can activate the virtual environment with the instructions found here.
  2. Install the requirements with pip3 install -r requirements.txt

Usage

To run the program, use the command:

$ python3 main.py

This will prompt you with several options to define matching criteria (using the old DNS list defined in config.py) and (if option 1 [All] is selected) whether to overwrite exisiting values or append the new DNS values. Depending on the selection, the matching behavior defined above will apply to all VLANs which meet the criteria.

/IMAGES/0image.png

LICENSE

Provided under Cisco Sample Code License, for details see LICENSE

CODE_OF_CONDUCT

Our code of conduct is available here

CONTRIBUTING

See our contributing guidelines here

DISCLAIMER:

Please note: This script is meant for demo purposes only. All tools/ scripts in this repo are released for use "AS IS" without any warranties of any kind, including, but not limited to their installation, use, or performance. Any use of these scripts and tools is at your own risk. There is no guarantee that they have been through thorough testing in a comparable environment and we are not responsible for any damage or data loss incurred with their use. You are responsible for reviewing and testing any scripts you run thoroughly before use in any non-testing environment.

About

This script modifies the DHCP DNS Nameservers for all VLANs across all appliance networks based on a selected matching criteria. The script only considers MX VLANs which are running a DHCP Server and meet the matching criteria.

License:Other


Languages

Language:Python 100.0%