Friday, August 29, 2014

Remotely Change IP on Cisco Router/Switch

A project I was working on required an IP address update for a remote site. Usually, the protocol would be to call out a local tech and have them console into the device and either update the configuration or I would RDP into their machine and complete the same task. This works great, but costs money for an on-site visit. I figured there must be a way to perform this remotely and save a little cash in the process.

Most Cisco routers and switches allow you to upload a .txt file to local storage, usually Flash:, with which you can copy the contents of the .txt to the running-config. The beauty of this method is that the commands in the .txt are run from the local CLI and not a VTY line. This will allow you to update an IP address completely as compared to being disconnected half-way through.

In the example below, I'll demonstrate how to change the IP address and default gateway on a switch:

   1.  Create a .txt file with the commands you wish to run, e.g. Change01.txt

        interface vlan1
        no ip address 192.168.0.2 255.255.255.0
        ip address 10.0.0.2 255.255.255.0
       !
       no ip default-gateway 192.168.0.1
       ip default-gateway 10.0.0.1
       !

   2. Upload the .txt file to the switch

        copy tftp://192.168.0.10/Change01.txt Flash:/Change01.txt

   3. Important! As a precaution, since you will be performing this remotely, set the switch to automatically reload in case something does not go correctly. You can cancel the scheduled reload afterwards if everything goes as planned. The command below will automatically reload the switch in 15 minutes if not cancelled.

        reload in 15

   4. Copy the changes in the .txt file to the running-config

        copy Flash:/Change01.txt running-config
 
   5. At this point your remote session to the switch will drop and you'll need to establish a new session to the switch with the new address. If you are able to remote to the switch with the new IP and accept the changes, then you can cancel the reload and save your changes.

        reload cancel

       copy running-config startup-config
 
   6. Optional - If your changes did not go as planned and you're locked out or unable to remote back in, don't fret, the switch will automatically reload at the end of the timer you configured in step 3 and the original configuration will be loaded.