Linux – Need a bash script to replace static IP with a new IP address

bashcentoslinuxnetworkingscripting

I would like to have a bash script for Centos machine.
I want the script to show me the current IP Address /subnet mask / Default GW.
and give me option to enter a new IP Address /subnet Mask / Default GW.
It should do it for ETH0.

Can someone have an idea how to do it?

Thanks!!

Best Answer

I'm not going to write it all for you, but here's something that works in Ubuntu:

ifconfig eth0 | grep "inet addr:" | awk -F: '{ print $2 }' | awk '{ print $1 }'

That will echo the current ip address in eth0.