Contents


Moving IP address from one Ethernet to another

Comments

Let us say for some reason you want to move the IP address from ent12 to ent14. Here are the steps you have to do to accomplish that:

  1. Save all the information for ent12. If the default route is defined on this Ethernet, then save it as well.
  2. Save all the routes and routing information for ent12. Note that in our case, ent12 is the main Ethernet you use to log on to the server. So, the next steps must be done from the console, as otherwise, you will lose your session and you won't be able to log on except from the console.
  3. Bring down and detach ent12 (at this point your users will not be able to log on to this server).
  4. Define the IP address on ent14.
  5. Define the default route on ent14, if it was defined on ent12 to begin with. At this point, some users might be able to log in, but some might not until completing the next step.
  6. Re-create the routes on ent14 (users should be able to log in after completing this step).
  7. Delete ent12, if needed.

The Using the script section in this article can help in minimizing your down time significantly, especially if you have a lot of routes on ent12. Let us now go over each one of these steps.

Step1: Save all the information for ent12

You can use smit chinet to save the definition of ent12. In this example, ent0 has been used. The output for ent12 would be similar to that of ent0. Figure 1 shows the output of ent0.

Figure 1. Output of smit chinet

Save the information displayed on this page as you will need it later to define them on ent14. The following is the most important information on this page:

Network Interface Name                             en0
INTERNET ADDRESS (dotted decimal)                  [1.22.333.44]
Network MASK (hexadecimal or dotted decimal)       [255.255.255.0]

If you run the command, netstat -rn | grep default, you will get the following entry:

default   222.333.55.1    UG        74   862520865   en12

This entry indicates that the default gateway is defined on en12. This is not surprising because ent12 is the main Ethernet to log in to this server as mentioned earlier. You need to save the gateway 222.333.55.1 ,in order to define it later on ent14.

Step 2: Save all the routes and routing information for ent12

This part is easy. You have to run the netstat -rn command. Refer to Figure 2 for output.

Figure 2. Output of the netstat -rn command

You can make use of the following line from the netstat –rn command to create this route on ent14.

222.333.55/26   222.333.55.16    UHSb        0   0   en12

You need to re-create these routes or some AIX servers might not be able to access this server. I will show you how to create this route on ent14 later in the Step 6: Create Ethernet routes on ent14 section.

Step 3: Bring down and detach ent12

You have to be on the console to bring down and detach ent12 or you will lose your session. Your users won't be able to log in to the server because ent12 is the main Ethernet used for logon until you finish redefining ent14 and make it available along with its routes. To bring down and detach ent12, you have to use smit chinet. Change the Current STATE from up to detach. After detaching ent12, it becomes unavailable for use and all of its routes will no longer be available and will not show up when using the netstat -rn command.

Step 4: Define the IP address on ent14

You have to use the information of ent12 to define the IP address on ent14. You can run smit chinet to define ent14. Use the IP address and network mask of ent12 that you saved in Step1.

Step 5: Define the default gateway on ent14

You can use smit tcpip to select Minimum Configuration & Startup and then ent14 to define the default gateway on ent14. Here is what the entries look like in System Management Interface Tool (SMIT) that you need to change:

Default Gateway
Address (dotted decimal or symbolic name)     []

In this case, you need to type 222.333.55.1 in the Address field and press Enter.

Step 6: Create Ethernet routes on ent14

On ent14, you have to create the routes that were defined on ent12. Here is an example on how you can use the output of the netstat -rn command for ent12 to create these routes on ent14. Refer to the following route that was mentioned in the previous section, Step 2: Save all the routes and routing information for ent12.

222.333.55/26   222.333.55.16    UHSb        0   0   en12

This route was taken from the output of netstat -rn for ent12. Look for ent12 entries in this output. You need to perform the following steps to add it:

  1. Type smit route and press Enter.
  2. Select Add a Static Route and press Enter.
  3. Enter 222.333.55.0 in the Destination Address field (Refer to the section Comparing the route add command and chdev command or smitty on how to derive the IP address.).
  4. Enter 222.333.55.16 in the Gateway Address field.
  5. Enter 255.255.255.192 in the Network Mask field (255.255.255.192 is network mask for /26).
  6. Scroll down to the Select interface option and select PF4 and then select ent14.

To find the network mask corresponding to /26, search in Google for the text "Subnet Mask mapping" and you will get some hits that show you the mapping. Refer to the following data for an example of this mapping.

Pref	  Mask			IPV4
/32    255.255.255.255
/31    255.255.255.254
/30    255.255.255.252
/29    255.255.255.248
/28    255.255.255.240
/27    255.255.255.224
/26    255.255.255.192
/25    255.255.255.128
/24    255.255.255    
/23    255.255.254    
/22    255.255.252    
/21    255.255.248    
/20    255.255.240    
/19    255.255.224    
/18    255.255.192    
/17    255.255.128    
/16    255.255        
/15    255.254        
/14    255.252        
/13    255.248        
/12    255.240        
/11    255.224        
/10    255.192        
/9     255.128        
/8     255            
/7     254            
/6     252            
/5     248            
/4     240            
/3     224            
/2     192

Note the following entries from the mapping above.

/17	255.255.128
/10	255.192
/7	254

You need to use the following entries for network mask for these three entries:

/17	255.255.128.0
/10	255.192.0.0
/7	254.0.0.0

As you can see, you will have to add the zeros in this case.

Note that we have only created one route on ent14 from ent12. What if you had 45 routes to create for example? How long would it take you to create these routes in this case? The script in the Using the script section creates 45 routes for you in less than a minute! This can reduce production outage dramatically. The nice thing about this is that there will be no errors and no typos involved. If you create the 45 routes manually and have a couple of typos, it could turn ugly during testing or later in production. The application team would have to determine which routes are having problems and inform you to troubleshoot and fix, and this could take a long time while users are having problems in production. It could be worse if the application team can't determine the routes that are having problems then this could take a lot longer to solve.

Comparing the route add command and chdev command or smitty

If you use the route add command to add a route, you will lose it after a reboot. The route add command does not update the Object Database Manager (ODM) and thus the route will not be re-created after a reboot. To make the route permanent, you need to use the chdev command or smitty to create it. Here is an example of using the chdev command.

chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.0.0,-if,en11,,,,-static,10.137.0.0,345.98.22.4"

255.255.0.0 = Net Mask
en11 = The Ethernet you are defining the route over
10.137.0.0 = is the IP address
345.98.22.4 = is the route

You have to be careful with the IP address. Here is an example of how you can create it. Let us say you got a request to add the following route:

149.131.76/26      121.152.76.16   	on en2

This request says to add a route for IP 149.131.76 with network mask of 26 and the gateway is 121.152.76.16 on Ethernet en2. The IP address 149.131.76 is missing the last extension. In this case you have to add .0 to the end and that would make it 149.131.76.0 which you use in the command chdev or with smitty to add this route. You may have had 149.131/26 in your request instead of 149.131.76/26 and in this case, you would use the IP address of 149.131.0.0 in your chdev command. In this case, your chdev command would be as follow:

chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.192,
-if,en2,,,,-static,149.131.0.0,121.152.76.16"

I have already covered how to create a route using smit in the Step 6: Create Ethernet routes on ent14 section.

Step 7: Delete ent12, if needed

At this point ent12 is detached. I usually wait for a few days or a week before I delete it, just in case for some reason, the application decide to go back to it (ent12) or back out then it will be easy to get it back. For more information about back out, refer to section Back out. In order to delete it, you can use the following command:

rmdev -Rdl ent12

This removes ent12 from the ODM.

Using the script

Run the script on your AIX server. Refer to the delete_or_recreate_static_routes_using_netstat script.

This script creates two scripts called /tmp/route_add and /tmp/route_delete. These two scripts are created from the output of the netstat -rn command. The route_add script re-creates all the routes for all the Ethernets displayed in the netstat -rn command. The route_delete script deletes all the routes for all the Ethernets in this case. You can pick and choose what you want to work with in this case. Refer to the following output of this script.

route add script is in /tmp/route_add. Info derived from "netstat -rn " and NOT from "lsattr -El inet0"
------------------------------------------------------------------------------------------------------
#!/usr/bin/ksh
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en10,,,,-static,10.44.7.0,10.44.7.45"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.0,-if,en10,,,,-static,10.44.7.0,10.44.7.45"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en10,,,,-static,10.44.7.255,10.44.7.45"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.0.0,-if,en11,,,,-static,10.137.0.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.252.0,-if,en11,,,,-static,10.567.16.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.0,-if,en11,,,,-static,10.567.24.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.128,-if,en11,,,,-static,10.567.25.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.128,-if,en11,,,,-static,10.567.25.128,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.240.0,-if,en11,,,,-static,10.208.0.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.240,-if,en11,,,,-static,32.75.241.192,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.128,-if,en11,,,,-static,62.567.25.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.224,-if,en11,,,,-static,62.567.25.160,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.138,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.139,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.140,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.141,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.143,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.146,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.147,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.240,-if,en11,,,,-static,129.35.22.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.248.0,-if,en11,,,,-static,146.89.168.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,345.98.22.0,345.98.22.1"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.248,-if,en11,,,,-static,345.98.22.0,345.98.22.1"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,345.98.22.7,345.98.22.1"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.224,-if,en11,,,,-static,345.98.128.224,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.0.0,-if,en11,,,,-static,172.29.0.0,345.98.22.4"
route delete script is in /tmp/route_delete. Info derived from "netstat -rn" and NOT from "lsattr -El inet0"
------------------------------------------------------------------------------------------------------------
#!/usr/bin/ksh
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en10,,,,-static,10.44.7.0,10.44.7.45"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.0,-if,en10,,,,-static,10.44.7.0,10.44.7.45"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en10,,,,-static,10.44.7.255,10.44.7.45"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.0.0,-if,en11,,,,-static,10.137.0.0,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.252.0,-if,en11,,,,-static,10.567.16.0,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.0,-if,en11,,,,-static,10.567.24.0,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.128,-if,en11,,,,-static,10.567.25.0,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.128,-if,en11,,,,-static,10.567.25.128,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.240.0,-if,en11,,,,-static,10.208.0.0,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.240,-if,en11,,,,-static,32.75.241.192,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.128,-if,en11,,,,-static,62.567.25.0,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.224,-if,en11,,,,-static,62.567.25.160,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.138,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.139,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.140,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.141,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.143,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.146,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.147,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.240,-if,en11,,,,-static,129.35.22.0,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.248.0,-if,en11,,,,-static,146.89.168.0,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en11,,,,-static,345.98.22.0,345.98.22.1"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.248,-if,en11,,,,-static,345.98.22.0,345.98.22.1"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,,-if,en11,,,,-static,345.98.22.7,345.98.22.1"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.255.224,-if,en11,,,,-static,345.98.128.224,345.98.22.4"
chdev -l inet0 -a delroute="net,-hopcount,0,-netmask,255.255.0.0,-if,en11,,,,-static,172.29.0.0,345.98.22.4"
route add script is in /tmp/route_add. Info derived from "netstat -rn" and NOT from "lsattr -El inet0"
route delete script is in /tmp/route_delete. Info derived from "netstat -rn" and NOT from "lsattr -El inet0"

Note the following statement at the top of the output which precede the route_add script.

route_add script is in /tmp/route_add. Info derived from netstat -rn and NOT from lsattr -El inet0.

This is just a reminder that the output from the script comes from netstat command and not lsattr and that it is saved in /tmp/route_add. A similar statement also precedes the route_delete script.

The route_add script has two Ethernets ent10 and ent11. The netstat command output has only these two Ethernets. This script is made up of only chdev commands that can create only static routers. Let us say now that you want to move the Ethernet ent11 to a new Ethernet ent12. In this case, run the command grep en11 /tmp/route_add and you will get the following output.

chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.0,-if,en11,,,,-static,10.567.24.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.128,-if,en11,,,,-static,10.567.25.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.128,-if,en11,,,,-static,10.567.25.128,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.240.0,-if,en11,,,,-static,10.208.0.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.240,-if,en11,,,,-static,32.75.241.192,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.128,-if,en11,,,,-static,62.567.25.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.224,-if,en11,,,,-static,62.567.25.160,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.138,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.139,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.140,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.141,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.143,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.146,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,62.567.128.147,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.240,-if,en11,,,,-static,129.35.22.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.248.0,-if,en11,,,,-static,146.89.168.0,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,345.98.22.0,345.98.22.1"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.248,-if,en11,,,,-static,345.98.22.0,345.98.22.1"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,,-if,en11,,,,-static,345.98.22.7,345.98.22.1"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.255.224,-if,en11,,,,-static,345.98.128.224,345.98.22.4"
chdev -l inet0 -a route="net,-hopcount,0,-netmask,255.255.0.0,-if,en11,,,,-static,172.29.0.0,345.98.22.4"

These are the set of commands you will use to create the routes on ent12 that come from ent11. All you have to do is, change ent11 to ent12 and you have all the commands that you need. You can put these commands into a script named route_add_ent12 and run it when you have to create the routes on ent12. That would be step 6. In step 6 we have created only one route on ent14 in the example under the heading, Create Ethernet Routes on ent14. Normally, I create four scripts as follow for ent11 and ent12 in this case:

  • route_delete_ent11 (script to delete ent11 routes)
  • route_add_ent12 (script to re-create routes from ent11 on ent12)
  • route_delete_ent12 (script to delete ent12 routes used in case of a back out)
  • route_add_ent11 (script to re-create ent11 routes in case of a back out)

Note that I don't normally use the script route_delete_ent11 and I did not use it in the above example. Instead, detaching ent11 has the effect of removing the routes from ent11 and they won't show in the output of netstat -rn anymore. In case of a back out, instead of using route_add_ent11 to re-create the routes for ent11, I just change ent11 from detach to up using smit chinet and that re-instates its routes. Refer to the Back out section for complete instructions on back out. However, I like to save these scripts so that just in case problems occur at a later time, they will give me a very good idea of what ent11 and ent12 were before and after moving the IP address. They can also delete or re-add any routes on any Ethernet if needed. To create these four scripts, you can use the grep command with route_add and route_delete the same way I used it above to create route_add_ent12.

Back out

If for some reason, the application group decide to back out then you can bring down and detach ent14. This should remove the routes for ent14 and make them unavailable. Verify using netstat -rn, to make sure that the routes and ent14 are not showing. You can now change the Current STATE of ent12 to up using smit chinet. This makes ent12 available and reinstates its routes. Verify and make sure all the routes are defined on ent12 at this point using netstat -rn. If you run into unexpected problems, you can always use the four route scripts created in the previous section to fix them. These scripts can help to solve the problem. They will make adding or deleting the routes very easy.

Resources


Downloadable resources


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=AIX and UNIX
ArticleID=993080
ArticleTitle=Moving IP address from one Ethernet to another
publish-date=12242014