When cloning a system of versions earlier than RHEL6.0 through VCenter, you cannot use advanced options to specify IP addresses. The following describes how to change the IP address when logging on to a linux host remotely. do not miss it if you need it.
Problem analysis:
According to the response of developers, when cloning systems of versions earlier than RHEL6.0 through VCenter, advanced options cannot be used to specify IP addresses, therefore, the specified IP address for the new instance through CloudStack cannot be implemented, and the DHCP server cannot be used to solve the problem. Otherwise, the IP address of the new virtual machine is inconsistent with the specified IP address, it may also lead to chaotic IP address allocation throughout the system.
Solution:
Specify a fixed reserved IP address for the templates created by the system below RHEL6.0, for example, 192.168.3.240 ~ 192.168.3.250 to this template system.
Whether you clone a virtual machine through VCenter or create an instance using CloudStack, as long as all virtual machines started through the fixed IP address, the VM will be successfully started with the original IP address and communicate with other IP addresses in the network segment normally, make sure that templates of the same IP address cannot be started at the same time.
The system with the fixed IP address as 10.196.18.250 in the template will be resolved on the control node, such as the cloudstackmanagement node/etc/hosts:
10.196.18.250 vm250
1. start vm250 and check whether it is successfully started through the detection mechanism. in the program, perform a simple connection test on 10.196.18.250 and ping it.
2. when the instance is started, write the IP address information to the local directory and save the information in the following format:
Assume the file name is: ifcfg-eth0.001, the content is as follows
DEVICE = eth0
ONBOOT = on
BOOTPROTO = static
IPADDR = 10.196.28.208
NETMASK = 255.255.255.0
GATEWAY = 10.196.28.254
3. call the script file ChangeIP. sh, which completes two tasks:
[1] copy the ifcfg-eth0.Id to the vmId specified directory and rename it as a ifcfg-eth0
[2] log on to vmId through cloudstack management and restart the network service to bring the new network configuration file into effect.
Usage:./ChangeIP. sh id_of_ifcfg-eth0 id_of_vm
For example:./ChangeIP. sh 001 250, copy the ifcfg-eth0.001 file into the vm250 system and restart the network service so that the final IP address of the new instance is 10.196.28.208
Copy codeThe code is as follows:
#! /Bin/bash
# Description: change ip on instances
# Usage:./ChangeIP. sh fileId vmId
# Flush the caches of remote hosts
> ~ /. Ssh/known_hosts
# Define the network configfile location
Dist =/etc/sysconfig/network-scripts/ifcfg-eth0
# Define a function which copy the new ifcfg-eth0 file
# From cloudstack management or from other host to new
# Instance boot from vm_fixip without interactive
Function scp_file (){
CT-c"
Set timeout-1
Spawn-noecho scp $1 $2
CT "yes/no"
Send "yesr"
Reset CT "password :"
Send "passwordr"
CT eof
"
}
Scp_file ifcfg-eth0. $1 root @ vm $2: $ dist
# This function named res_new means restart network
# On new instance loading from new network config file
# Without interactive
Function res_net (){
CT-c"
Set timeout-1
Spawn-noecho ssh $1 $2
Reset CT "password :"
Send "passwordr"
CT eof
"
}
Res_net root @ vm $2 "service network restart>/dev/null 2> & 1 &"
Sleep 2
Exit 0