Forum Discussion

Jason_40769's avatar
Jason_40769
Icon for Nimbostratus rankNimbostratus
Nov 14, 2014

Editing Virtual server IPs via script

Hey guys! I have a BIG-IP LTM running version 11.6. I need to create a one time script that I can change all the IP addresses of my Virtual servers quickly. We are changing our IP Block and want to minimize downtime.

 

8 Replies

  • shaggy's avatar
    shaggy
    Icon for Nimbostratus rankNimbostratus

    The TMSH command to modify a virtual server's IP address is:

    modify ltm virtual vs-name destination 1.2.3.4:80

    This might help you generate the commands (run in bash):

    tmsh list ltm virtual destination | tr '\n' ' ' \
    | sed 's/ \+/ /g;s/ltm virtual/\ntmsh modify ltm virtual/g;s/nation 1\.1\.1/nation 2.2.2/g';echo
    

    where 1.1.1 are the old octets being replaced with 2.2.2

  • I'm having trouble with this one. Maybe it's because I'm running version 11.5.1. Here's what I did:

    1. Created a file named bash.sh in the /shared folder.
    2. Ran the following command: chmod 755 /shared/bash.sh
    3. Ran the following command: bash /shared/bash.sh

    The output looked correct, the desired octet was changed:

    modify ltm virtual vs-name { destination 10.10.207.x:80 }

    But, the actual VS destinations were not changed. Below is the contents of the bash.sh file:

    !/bin/bash
    
    tmsh list ltm virtual destination | tr '\n' ' ' \
    | sed 's/ \+/ /g;s/ltm virtual/\nmodify ltm virtual/g;s/nation 10\.10\.206/nation 10.10.207/g';echo
    
    • shaggy's avatar
      shaggy
      Icon for Nimbostratus rankNimbostratus
      the command is meant to generate the commands that can then either be put into a script or run manually. the following should generate a bash script with 'tmsh modify ltm virtual...' commands: echo '!/bin/bash' > /shared/bash2.sh; tmsh list ltm virtual destination | tr '\n' ' ' | sed 's/ \+/ /g;s/ltm virtual/\ntmsh modify ltm virtual/g;s/nation 10\.10\.206/nation 10.10.207/g' >> /shared/bash2.sh; chmod 755 /shared/bash2.sh
  • I'm having trouble with this one. Maybe it's because I'm running version 11.5.1. Here's what I did:

    1. Created a file named bash.sh in the /shared folder.
    2. Ran the following command: chmod 755 /shared/bash.sh
    3. Ran the following command: bash /shared/bash.sh

    The output looked correct, the desired octet was changed:

    modify ltm virtual vs-name { destination 10.10.207.x:80 }

    But, the actual VS destinations were not changed. Below is the contents of the bash.sh file:

    !/bin/bash
    
    tmsh list ltm virtual destination | tr '\n' ' ' \
    | sed 's/ \+/ /g;s/ltm virtual/\nmodify ltm virtual/g;s/nation 10\.10\.206/nation 10.10.207/g';echo
    
    • shaggy's avatar
      shaggy
      Icon for Nimbostratus rankNimbostratus
      the command is meant to generate the commands that can then either be put into a script or run manually. the following should generate a bash script with 'tmsh modify ltm virtual...' commands: echo '!/bin/bash' > /shared/bash2.sh; tmsh list ltm virtual destination | tr '\n' ' ' | sed 's/ \+/ /g;s/ltm virtual/\ntmsh modify ltm virtual/g;s/nation 10\.10\.206/nation 10.10.207/g' >> /shared/bash2.sh; chmod 755 /shared/bash2.sh
  • If you are sure about the result, you can do it "on the fly". Please don´t forget saving to startup config:

    tmsh list ltm virtual destination | tr '\n' ' ' | sed 's/ \+/ /g;s/ltm virtual/\ntmsh modify ltm virtual/g;s/nation 10\.131\.131/nation 10.132.132/g' | bash +x
    
    tmsh save sys config