title: Need help to modify a Shell Script to change ip addresses on CentOS
body: <p>I have a shell script to change IP address (on a CentOS), instead of changing it manually. Here is the script:</p>
  
  <pre><code>#!/bin/bash
  # changeip.sh
  
  usage(){
      clear
      echo "Usage: $0 newip"
      echo "Example: $0 127.0.0.1"
      exit 1
  }
  
  new_ip_value=$1
  local_ip_value=$(ifconfig eth0|awk '/inet addr/ {split ($2,A,":"); print A[2]}')
  
  # call usage() function if filename not supplied
      [[ $# -eq 0 ]] &amp;&amp; usage
  
  
  echo "/etc/hosts"
  echo "----------------------------------------------------------"
  sed -ie 's/'$local_ip_value'/'$new_ip_value'/g' /etc/hosts
  sed 's/'$local_ip_value'/'$new_ip_value'/g' /etc/hosts
  echo ""
  echo "/etc/sysconfig/network-scripts/ifcfg-eth0"
  echo "----------------------------------------------------------"
  sed -ie 's/'$local_ip_value'/'$new_ip_value'/' /etc/sysconfig/network-scripts/ifcfg-eth0
  sed 's/'$local_ip_value'/'$new_ip_value'/' /etc/sysconfig/network-scripts/ifcfg-eth0
  echo "The IP of $local_ip_value has successfully been changed to $new_ip_value."
  service network restart
  
  exit
  </code></pre>
  
  <p>I need to add further parameters like:</p>
  
  <ol>
  <li>BOOTPROTO</li>
  <li>ONBOOT</li>
  <li>GATEWAY</li>
  <li>DNS1</li>
  </ol>
  
  <p>and so on.</p>
  
  <p>Could any body let me know how i should modify the script to add these details? My ifcfg-eth0 should ultimately like this:</p>
  
  <pre><code># vi /etc/sysconfig/network-scripts/ifcfg-eth0
  DEVICE="eth0"
  BOOTPROTO=none
  NM_CONTROLLED="yes"
  ONBOOT=yes
  TYPE="Ethernet"
  IPADDR=192.168.1.2
  GATEWAY=192.168.1.1
  </code></pre>
  
  <p>Any help is appreciated!</p>
  
  <p>Thanks!</p>