This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Modify Host Definition and enable/disable NAT rule via command line

Hi,

is it possible to modify the IP address of an existing host definition via command line? 
Additionally is it possible to enable/disable NAT rules via command line?
Could it be done via cc?

EDIT: Reason: I need to change these values automatically through a script.


Thanks in advance

Dino


This thread was automatically locked due to age.
  • Hi,

    It's probably possible, but not documented.

    Why not use Static Mappings to lock a host to an IP?

    Barry
  • Dino,

    Please explain your motivation.  Maybe there's another way to skin the cat - a different way to define the problem and find a different approach.

    Cheers - Bob
     
    Sophos UTM Community Moderator
    Sophos Certified Architect - UTM
    Sophos Certified Engineer - XG
    Gold Solution Partner since 2005
    MediaSoft, Inc. USA
  • Hi Bob,

    "skin the cat"... ROFL... never heard of that idiom [:D]

    Hmm, how to explain my scenario...

    We got one Domain from a customer which points to a server located at a datacenter with a fixed ip. Then we have a second server which is "moving" across Europe to different event locations. This server get's a new IP on every event. When the second server at the event boots up, it syncronizes with the datacenter server and becomes the main server, so the domain traffic should be routed to this server.

    Normally we would do this by changing the DNS, but we have no control over the DNS, let the customer do this takes hours to days, and it takes time until all DNS Servers are updated.

    So we changed plans and put a UTM in front. The UTM also got an official IP address and the DNS was changed to this IP. At the UTM we created two FULL-NAT rules. One rule for all incoming traffic to the first server and one rule for all traffic to the second server. We only have to change the host definition to the new IP of the second server and then we disable rule A and enable rule B. This takes only seconds and really works like a charm.

    Yes, we could do this with only one rule and change only the host definition, but as the IP of the datacenter server never changes we want to have a clear fixed rule for that.

    And now we want to do these three things by running a script. Changing IP address of the host definition, disable rule A and enable rule B.

    Can we do this?

    cu,
      Dino
  • This seems like an ideal situation for a RED.  Just use a single DNAT rule with destination changed to an Availability Group containing, in order {Traveling Server} and {Datacenter Server}.

    If it needs to synchronize first, it can use a different IP until it's ready to take over the traffic, at which time, you would change it to the one used in the {Traveling Server} definition.

    The advantage of all this is that it can all be done automatically.  When the Traveling Server is available, traffic will be sent to it.

    Can that approach work for you?

    Cheers - Bob
     
    Sophos UTM Community Moderator
    Sophos Certified Architect - UTM
    Sophos Certified Engineer - XG
    Gold Solution Partner since 2005
    MediaSoft, Inc. USA
  • Unfortunately not, because when the second server is online, no one should be able to use server one. So I cannot use the availability groups.

    If I had a master-master sync between the servers, I wouldn't need this NAT-rule construction or your RED-solution at all.

    Dino
  • Proceed at your own risk, or at the very least none to me.  Make backups, work within your change management processes and maintenance windows after testing in an appropriate environment.

    Changing host definition IP address from the command line.

    Find the desired REF by IP address (10.0.0.1 used as example)
    cc get_objects_filtered '$_->{data}->{address} eq "10.0.0.1"'


    Change IP for desired REF (10.0.0.2 used as example address).
    cc change_object REF_NetHosWhatever address '10.0.0.2'



    NAT rule enabling/disabling from the command line.

    Get the REFs for your NAT rules.
    cc get nat rules


    Verify each NAT REF is what you think it is.
    cc get_object REF_PacNatWhatever


    Disable desired NAT rule by REF:
    cc change_object REF_PacNatWhatever status 0


    Enable desired NAT rule by REF:
    cc change_object REF_PacNatWhatever status 1



    Please let me know how these work for you.
  • Ipzipzap, That's the way an Availability Group works.  If the first IP is available it is used exclusively.  The second is used only when the first is not available.

    Cheers - Bob
     
    Sophos UTM Community Moderator
    Sophos Certified Architect - UTM
    Sophos Certified Engineer - XG
    Gold Solution Partner since 2005
    MediaSoft, Inc. USA
  • BAlfson, noted and corrected the missing ' - thank you.
  • Cool - Thanks, teched!  I played a little with the new (to me) get_objects_filtered command.  Instead of using cc get nat rules and having to look at each rule, I found the REF for the Axis Camera that plays receptionist with:
    cc get_objects_filtered '$_->{data}->{comment} eq "Axis Camera"'

    Cheers - Bob
     
    Sophos UTM Community Moderator
    Sophos Certified Architect - UTM
    Sophos Certified Engineer - XG
    Gold Solution Partner since 2005
    MediaSoft, Inc. USA
  • Ipzipzap, That's the way an Availability Group works.  If the first IP is available it is used exclusively.  The second is used only when the first is not available.

    Cheers - Bob


    Hi Bob,

    when the first server ist running, the second server must never be used, even when the first server ist not reachable. Thats my problem.
    If I use an availability group and there are network problems on the event (and there are some on every event) the second server would be used. So I can't use an availability group, because this would lead to database inconsistencies.

    Dino