Main Menu
  • COMPANY
    • Boundless Cybersecurity
    • Press Releases
    • News
    • Events
    • Awards
    • Leadership
    • Press Kit
    • Careers
  • PROMOTIONS
    • SonicWall Promotions
    • Customer Loyalty Program
  • MANAGED SERVICES
    • Managed Security Services
    • Security as a Service
    • Professional Services
SonicWall
  • Products
      All Products A–Z
      Free Trials
    • Network Security
      • Next-Generation Firewall (NGFW)
      • Network Security Services
      • Network Security Management
      • Secure SD-WAN
    • Threat Protection
      • Advanced Threat Protection Cloud
      • Advanced Threat Protection Appliance
      • Capture Labs
    • Secure Access Service Edge (SASE)
      • Zero-Trust Network Access (ZTNA)
    • Cloud Security
      • Cloud Firewall
      • Cloud App Security
    • Endpoint Security
      • Endpoint Detection & Response (EDR)
    • Email Security
      • Cloud Email Security
      • Hosted Email Security
      • On-Prem Email Security
    • Secure Access
      • Wireless Access Points
      • Network Switch
      • Virtual Private Network (VPN)
    • Wi-Fi 6 Access Points

      SonicWall SonicWave 600 series access points provide always-on, always-secure connectivity for complex, multi-device environments.

      Read More
  • Solutions
    • Industries
      • Distributed Enterprises
      • Retail & Hospitality
      • K-12 Education
      • Higher Education
      • State & Local
      • Federal
      • Healthcare
      • Financial Services
      • Carriers
    • Use Cases
      • Secure SD-Branch
      • Network Segmentation
      • Zero Trust Security
      • Secure SD-WAN
      • Office 365 Security
      • SaaS Security
      • Secure Wi-Fi
    • Solutions Widgets
      • Solutions Content Widgets
        Federal

        Protect Federal Agencies and Networks with scalable, purpose-built cybersecurity solutions

      • Solutions Image Widgets
  • Partners
    • SonicWall Partners
      • Partners Overview
      • Find a Partner
      • Authorized Distributors
      • Technology Partners
    • Partner Resources
      • Become a Partner
      • SonicWall University
      • Training & Certification
    • Partner Widgets
      • Custom HTML : Partners Content WIdgets
        Partner Portal

        Access to deal registration, MDF, sales and marketing tools, training and more

      • Partners Image Widgets
  • Support
    • Support
      • Support Portal
      • Knowledge Base
      • Technical Documentation
      • Community
      • Video Tutorials
      • Product Life Cycle Tables
      • Partner Enabled Services
      • Contact Support
    • Resources
      • Resource Center
      • Events
      • Free Trials
      • Blog
      • SonicWall University
      • MySonicWall
    • Capture Labs
      • Capture Labs
      • Security Center
      • Security News
      • PSIRT
      • Application Catalog
    • Support Widget
      • Custom HTML : Support Content WIdgets
        Support Portal

        Find answers to your questions by searching across our knowledge base, community, technical documentation and video tutorials

      • Support Image Widgets
  • COMPANY
    • Boundless Cybersecurity
    • Press Releases
    • News
    • Events
    • Awards
    • Leadership
    • Press Kit
    • Careers
  • PROMOTIONS
    • SonicWall Promotions
    • Customer Loyalty Program
  • MANAGED SERVICES
    • Managed Security Services
    • Security as a Service
    • Professional Services
  • Contact Sales
  • English English English en
  • BLOG
  • CONTACT SALES
  • FREE TRIALS
  • English English English en
SonicWall
  • Products
      All Products A–Z
      Free Trials
    • Network Security
      • Next-Generation Firewall (NGFW)
      • Network Security Services
      • Network Security Management
      • Secure SD-WAN
    • Threat Protection
      • Advanced Threat Protection Cloud
      • Advanced Threat Protection Appliance
      • Capture Labs
    • Secure Access Service Edge (SASE)
      • Zero-Trust Network Access (ZTNA)
    • Cloud Security
      • Cloud Firewall
      • Cloud App Security
    • Endpoint Security
      • Endpoint Detection & Response (EDR)
    • Email Security
      • Cloud Email Security
      • Hosted Email Security
      • On-Prem Email Security
    • Secure Access
      • Wireless Access Points
      • Network Switch
      • Virtual Private Network (VPN)
    • Wi-Fi 6 Access Points

      SonicWall SonicWave 600 series access points provide always-on, always-secure connectivity for complex, multi-device environments.

      Read More
  • Solutions
    • Industries
      • Distributed Enterprises
      • Retail & Hospitality
      • K-12 Education
      • Higher Education
      • State & Local
      • Federal
      • Healthcare
      • Financial Services
      • Carriers
    • Use Cases
      • Secure SD-Branch
      • Network Segmentation
      • Zero Trust Security
      • Secure SD-WAN
      • Office 365 Security
      • SaaS Security
      • Secure Wi-Fi
    • Solutions Widgets
      • Solutions Content Widgets
        Federal

        Protect Federal Agencies and Networks with scalable, purpose-built cybersecurity solutions

      • Solutions Image Widgets
  • Partners
    • SonicWall Partners
      • Partners Overview
      • Find a Partner
      • Authorized Distributors
      • Technology Partners
    • Partner Resources
      • Become a Partner
      • SonicWall University
      • Training & Certification
    • Partner Widgets
      • Custom HTML : Partners Content WIdgets
        Partner Portal

        Access to deal registration, MDF, sales and marketing tools, training and more

      • Partners Image Widgets
  • Support
    • Support
      • Support Portal
      • Knowledge Base
      • Technical Documentation
      • Community
      • Video Tutorials
      • Product Life Cycle Tables
      • Partner Enabled Services
      • Contact Support
    • Resources
      • Resource Center
      • Events
      • Free Trials
      • Blog
      • SonicWall University
      • MySonicWall
    • Capture Labs
      • Capture Labs
      • Security Center
      • Security News
      • PSIRT
      • Application Catalog
    • Support Widget
      • Custom HTML : Support Content WIdgets
        Support Portal

        Find answers to your questions by searching across our knowledge base, community, technical documentation and video tutorials

      • Support Image Widgets
  • COMPANY
    • Boundless Cybersecurity
    • Press Releases
    • News
    • Events
    • Awards
    • Leadership
    • Press Kit
    • Careers
  • PROMOTIONS
    • SonicWall Promotions
    • Customer Loyalty Program
  • MANAGED SERVICES
    • Managed Security Services
    • Security as a Service
    • Professional Services
  • Contact Sales
  • Menu

Adding Multiple Address Objects Using SonicOS API

12/20/2022 42 People found this article helpful 189,691 Views

    Download
    Print
    Share
    • LinkedIn
    • Twitter
    • Facebook
    • Email
    • Copy URL The link has been copied to clipboard

    Description

    SonicOS API provides an alternative to the SonicOS Command Line Interface (CLI) for configuring selected functions. SonicOS API is disabled by default in SonicOS. Any attempt to access SonicOS API while it is disabled results in an HTTP 403 Forbidden error.

    To use the SonicOS API, you must enable it, either through the SonicOS Management Interface or from the CLI.
    SonicOS API is supported on all platforms running SonicOS 6.5.4 and higher.
    NOTE: Commands for adding IPv6, MAC and FQDN address objects and their supported schema can be found in the SonicOS API 6.5.4 Reference Guide

    Resolution

    You are free to choose Swagger, Postman, Git bash, or any application that allows API calls, if you are using a Linux-based operating system you can execute cURL from the terminal. 

    Please refer to https://sonicos-api.sonicwall.com for the entire list.  

     

    Only the first 2 steps of this article would change, depending on the SonicWall model you use. Commands are the same for both Gen6 and Gen7 SonicWall devices. 

    For this article, I'm using Postman App and will be showing the commands to run on cURL for each step.

    Resolution for SonicOS 7.X

    This release includes significant user interface changes and many new features that are different from the SonicOS 6.5 and earlier firmware. The below resolution is for customers using SonicOS 7.X firmware.




     

    1. Enabling the API Module on the firewall UI.
      Login to the SonicWall management UI. Navigate to Device | Settings | Administration | Audit/SonicOS API  section. Enable the option 'Enable SonicOS API' and 'Enable RFC-2617 HTTP Basic Access authentication' options.
      Image

    2. List of applicable APIs:
      Navigate to MANAGE | API and click on the link https://SonicOS-api.sonicwall.com. Swagger will prepopulate your SonicWalls’s IP, MGMT Port, and Firmware so it can give you a list of applicable APIs.
      Image

    3. Login to the Firewall using Postman
      The following 3 steps need to be performed for every API request in Gen7 devices.

       NOTE: https://IP-address:port/-- Replace this with your SonicWall's Public or private IP address with the right management port number (If the management port is 443, you can directly use https:// followed by the IP address without the port number too).

      a) The HTTP method should be POST and we need to use the URL: https://192.168.168.168/api/sonicos/auth
      Under the authorization tab, select Basic Auth and mention the correct admin credentials.

      Image


      b) Under the settings tab, turn OFF the Enable SSL certificate verification if the firewall is using a self-signed certificate for management.
      Image

      c) Under the headers tab, include application/Json as the value for keys Accept and Content-type.
      Image 

      d) The Gen 7 devices are token-driven. Use the {"override" : true} under the body to override any older tokens. This is used only during login.
      After this, click on the Send button and then you can see the response in the section below. The response should contain a message: "success".

      Image

      e) After this, click on the Send button and then you can see the response on the section below. The response should contain a message: "success".

      Log in
      cURL code:
      curl --location --request POST 'https://192.168.168.168/api/sonicos/auth' \
      --header 'Accept: application/Json' \
      --header 'Content-Type: application/Json' \
      --header 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=
      --data-raw '{"override" : true}'

      Command Output should contain a string: "success": true

    4. Adding Multiple Address objects:

      Postman Add multiple objects

      For GitBash or Linux terminal commands :
      Need to create a JSON file listing all the address objects to be added.
      You can use a notepad and add all the address objects as below and save it as a .JSON file.
      I am using the name add.JSON and saved it in Desktop for this example.

      {
      "address_objects": [
      {
      "ipv4": {
      "name": "Test 1",
      "zone": "LAN",
      "host": {
      "ip": "192.168.168.10"
      }
      }
      },
      {
      "ipv4": {
      "name": "Test 2",
      "zone": "LAN",
      "host": {
      "ip": "192.168.168.20"
      }
      }
      },
      {
      "ipv4": {
      "name": "Test 3",
      "zone": "LAN",
      "host": {
      "ip": "192.168.168.30"
      }
      }
      }
      ]
      }

      NOTE: I have the add.Json file saved on to my desktop and hence I was able to call it into the command, if you have created the Json the file in a different location then make sure you are executing the command from that location.



      curl -k -i -X POST "https://192.168.188.200/api/sonicos/address-objects/ipv4" -H "accept: application/Json" -H "Content-Type: application/Json" -d @add.Json

      Command Output should have success as the message in the info section as below
      Image
    5. Committing all the configurational changes made with APIs:
      pendingConfig

      cURL command:

      curl -L -X POST 'https://192.168.168.168/api/sonicos/config/pending' \
      -H 'Content-Type: application/json' \
      -H 'Accept: application/json' \
      -H 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' \
      --data-raw ''



    6. Log out the SonicWall with API

      Log out

      cURL command:
      curl -L -X DELETE 'https://192.168.168.168:443/api/sonicos/auth' \
      -H 'Authorization: Basic YWRtaW46cGFzc3dvcmQ='

    NOTE: All the address objects need to be of the same type Eg: IPv4, IPv6, MAC, FQDN etc. The commands vary based on the type of objects that you are adding.

     CAUTION: If you miss performing the action in Step 5 and Execute the command in Step 6 you will lose all the configuration changes made in the current session.

    Resolution for SonicOS 6.5

    This release includes significant user interface changes and many new features that are different from the SonicOS 6.2 and earlier firmware. The below resolution is for customers using SonicOS 6.5 firmware.


     

    EXAMPLE: Let us go through the steps for adding three IPv4 host address objects on zone LAN with IP addresses 192.168.168.10, 192.168.168.20 and 192.168.168.30.

    You would need to follow the below steps to add multiple address objects at once using SonicOS APIs.

    1.  Enabling the API Module on the firewall UI
      Login to the SonicWall management UI. Navigate to MANAGE | Appliance | Base Settings and scroll down to SonicOS API section. Enable the option 'Enable SonicOS API' and 'Enable RFC-2617 HTTP Basic Access authentication' option.
      Image
    2. List of applicable APIs
      Navigate to MANAGE | API and click on the link https://SonicOS-api.sonicwall.com. Swagger will prepopulate your SonicWalls’s IP, MGMT Port, Firmware so it can give you a list of applicable APIs.
      TIP: You are free to choose Swagger, Postman, Git bash, or any application that allows API calls, if you are using a Linux based operating system you can execute cURL from the terminal. For this article I am using Git bash on Windows.
      Image
      Image
    3. Log in using Postman:

      Log in

      Login to the Firewall using Git bash. 
      curl -k -i -u "admin:password" -X POST https://192.168.188.200:443/api/sonicos/auth

      "admin:password" – Replace this with your SonicWall's "username : password"
      https://192.168.188.200:443/-- Replace this with your SonicWalls Public or private IP address with the right management port number (If the management port is 443, you can directly use https:// followed by the IP address without the port number too)

      Command Output should contain a string: "success": true
      Image

    4. Adding Multiple Address objects:

      Postman Add multiple objects

      For GitBash or Linux terminal commands :
      Adding all the address objects in the add.JSON file.

      Creating the JSON file listing all the address objects to be added.

      You can use a notepad and add all the address objects as below and save is as a .JSON file. I am using the name add.JSON for this example.
      {
      "address_objects": [
      {
      "ipv4": {
      "name": "Test 1",
      "zone": "LAN",
      "host": {
      "ip": "192.168.168.10"
      }
      }
      },
      {
      "ipv4": {
      "name": "Test 2",
      "zone": "LAN",
      "host": {
      "ip": "192.168.168.20"
      }
      }
      },
      {
      "ipv4": {
      "name": "Test 3",
      "zone": "LAN",
      "host": {
      "ip": "192.168.168.30"
      }
      }
      }
      ]
      }

      NOTE: I have the add.Json file saved on to my desktop and hence I was able to call it into the command, if you have created the Json the file in a different location then make sure you are executing the command from that location.



      curl -k -i -X POST "https://192.168.188.200/api/sonicos/address-objects/ipv4" -H "accept: application/Json" -H "Content-Type: application/Json" -d @add.Json

      Command Output should have success as the message in the info section as below
      Image
      NOTE: Commands for adding IPv6, MAC and FQDN address objects and their supported schema can be found in the SonicOS API 6.5.4 Reference Guide

    5. Committing all the configurational changes made with APIs:

      Commit Pending Config

      curl -k -X POST "https://192.168.188.200/api/sonicos/config/pending" -H "accept: application/Json"

      https://192.168.188.200/-- Replace this with your SonicWall's Public or private IP address
      Image
      We have Only used the POST method in most of the API calls for this Article because we are only Adding things into the configuration, there are other methods Like GET, DELETE, PUT and etc. I recommend that you go through https://SonicOS-api.sonicwall.com for more API commands.

    6. Log out the SonicWall with API
      It is recommended to log out from the SonicWall via API once the desired configuration is committed.
      Log out

      curl -k -i -u "admin:password" -X DELETE https://192.168.188.200/api/sonicos/auth
      Image

    CAUTION: If you miss to perform the action in Step 5 and Execute the command in Step 6 you will lose all the configuration changes made in the current session.

    You can manually log in to the firewall to check the changes made
    Navigate to MANAGE | Objects | Address objects to check for the changes.
    Image

    Related Articles

    • How to force an update of the Security Services Signatures from the Firewall GUI
    • Configure Guest VLAN in the TZ firewall, for guest users to access Internet only.
    • How to Setup the SonicWave 600 series

    Categories

    • Firewalls > NSa Series > Networking
    • Firewalls > TZ Series > Networking

    Not Finding Your Answers?

    ASK THE COMMUNITY

    Was This Article Helpful?

    YESNO

    Article Helpful Form

    Article Not Helpful Form

    Company
    • Careers
    • News
    • Leadership
    • Awards
    • Press Kit
    • Contact Us
    Popular resources
    • Communities
    • Blog
    • SonicWall Capture Labs

    Stay In Touch

    • By submitting this form, you agree to our Terms of Use and acknowledge our Privacy Statement. You can unsubscribe at any time from the Preference Center.
    • This field is for validation purposes and should be left unchanged.
    • Facebook
    • Twitter
    • Linkedin
    • Youtube
    • Instagram

    © 2023 SonicWall. All Rights Reserved.

    • Legal
    • Privacy
    • English
    Scroll to top