Telnet to the Linux host and replace the IP address in a non-interactive manner

Source: Internet
Author: User
Tags file copy reserved ssh cloudstack

Problem Analysis:

According to the development team colleague, It is not possible to use advanced options for IP-specific operations by vcenter the RHEL6.0 of systems with the following version, which is not possible by assigning IP to a new instance by Cloudstack, and it is not possible to use a DHCP server to resolve the problem, or it will cause the new virtual machine IP address to Inconsistent, it can also cause confusion in the allocation of IP addresses throughout the system.
Solution Idea:

A fixed reserved IP address is specified for the RHEL6.0 of the following systems, such as 192.168.3.0/24 network segments, reserved 192.168.3.240~192.168.3.250 to such template systems.

Whether through the Vcenter clone virtual machine or Cloudstack new instance, as long as all the virtual machines that are started through the fixed IP address will successfully start with the original IP address, and normally communicate with other IP addresses in the network segment, you need to ensure that the same IP address template is not allowed to start at the same time.

The following is a template fixed IP: 10.196.18.250 system, in the control node, such as the Cloudstackmanagement node above/etc/hosts resolution:

10.196.18.250 vm250

1. Start vm250, through the detection mechanism to determine the success of its start-up, the program to 10.196.18.250 a simple connection test, ping pass.

2. In the process of starting the instance, the IP address information is also written to the local directory, and is saved in the following format:

Suppose the file name is: ifcfg-eth0.001, and the contents are as follows

Device=eth0

Onboot=on

Bootproto=static

ipaddr=10.196.28.208

netmask=255.255.255.0

gateway=10.196.28.254

3. Invoke script file: changeip.sh, the script file accomplishes two tasks:

"1" will ifcfg-eth0. Id Copy to vmid specified directory, renamed to Ifcfg-eth0

"2" Through the Cloudstack management landing Vmid, restart network services, making the new network configuration file effective.

How to use:./changeip.sh id_of_ifcfg-eth0 ID_OF_VM

such as:./CHANGEIP.SH 001 250, will ifcfg-eth0.001 file copy paper vm250 system, and restart network services, so that the final IP address of the new instance is 10.196.28.208

#!/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 () {
Expect-c "
Set Timeout-1
Spawn-noecho SCP $
Expect "yes/no"
Send \ "Yes\r\"
Expect "Password:"
Send \ "Password\r\"
Expect EOF
"
}
Scp_file ifcfg-eth0.$1 root@vm$2: $dist
# This function named Res_new means restart network
# on the new instance loading from New network config file
# without Interactive
function Res_net () {
Expect-c "
Set Timeout-1
Spawn-noecho SSH $ $
Expect "Password:"
Send \ "Password\r\"
Expect EOF
"
}
Res_net root@vm$2 "Service network restart >/dev/null 2>&1 &"
Sleep 2
Exit 0

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.