shell脚本-快速配置网卡参数
2011-05-20 11:35
477 查看
闲来无事,想想做测试的时候配置IP地址很麻烦,写了个简单的脚本。自己觉得还是比较烂吧,能用就行。
#!/bin/bash
#config network value by simple style.
#the system version is RHEL5.6
intdir=/etc/sysconfig/network-scripts
tempfile=/tmp/netconfig.tmp.txt
read -p "which interface you want to config?($(ls ${intdir} | grep ifcfg | cut -d- -f2 | grep -v lo) or? ): " interface
IPADDR=`cat $intdir/ifcfg-${interface} | grep IPADDR | cut -d= -f2`
NETMASK=`cat $intdir/ifcfg-${interface} | grep NETMASK | cut -d= -f2`
GATEWAY=`cat $intdir/ifcfg-${interface} | grep GATEWAY | cut -d= -f2`
function viewconfig
{
echo "current config is:"
echo "IPADDR=$IPADDR"
echo "NETMASK=$NETMASK"
echo "GATEWAY=$GATEWAY"
read -p "Are you sure?(y/n):" confirm
}
viewconfig
while [ $confirm != y ]
do
#read value
read -p "please input a value IPv4 address: " IPADDR
read -p "please input a value netmask: " NETMASK
read -p "please input a value IPv4 address of the default gateway: " GATEWAY
cat $intdir/ifcfg-${interface} | grep -v IPADDR | grep -v NETMASK | grep -v GATEWAY | grep -v BOOTPROTO > $tempfile
viewconfig
if [ $confirm != y ]
then continue
fi
done
#load config
echo "BOOTPROTO=static" >> $tempfile
echo "IPADDR=$IPADDR" >> $tempfile
echo "NETMASK=$NETMASK" >> $tempfile
echo "GATEWAY=$GATEWAY" >> $tempfile
cat $tempfile > ${intdir}/ifcfg-${interface}
rm -rf $tempfile
read -p "Do you want to config the DNS Server address?(y/n)" confirm
if [ $confirm = y ]
then
read -p "please input a IPv4 address of first dnsserver: " nameserver1
echo "nameserver $nameserver1" > /etc/resolv.conf
read -p "Do you want to config the second DNS Server address?(y/n)" confirm
if [ $confirm = y ]
then
read -p "please input a IPv4 address of second dnsserver: " nameserver2
echo "nameserver $nameserver2" >> /etc/resolv.conf
fi
fi
/sbin/ifdown $interface
/sbin/ifup $interface
#by Kaiser
本文出自 “凯旋之歌” 博客,请务必保留此出处http://kaiserwu.blog.51cto.com/697390/569438
#!/bin/bash
#config network value by simple style.
#the system version is RHEL5.6
intdir=/etc/sysconfig/network-scripts
tempfile=/tmp/netconfig.tmp.txt
read -p "which interface you want to config?($(ls ${intdir} | grep ifcfg | cut -d- -f2 | grep -v lo) or? ): " interface
IPADDR=`cat $intdir/ifcfg-${interface} | grep IPADDR | cut -d= -f2`
NETMASK=`cat $intdir/ifcfg-${interface} | grep NETMASK | cut -d= -f2`
GATEWAY=`cat $intdir/ifcfg-${interface} | grep GATEWAY | cut -d= -f2`
function viewconfig
{
echo "current config is:"
echo "IPADDR=$IPADDR"
echo "NETMASK=$NETMASK"
echo "GATEWAY=$GATEWAY"
read -p "Are you sure?(y/n):" confirm
}
viewconfig
while [ $confirm != y ]
do
#read value
read -p "please input a value IPv4 address: " IPADDR
read -p "please input a value netmask: " NETMASK
read -p "please input a value IPv4 address of the default gateway: " GATEWAY
cat $intdir/ifcfg-${interface} | grep -v IPADDR | grep -v NETMASK | grep -v GATEWAY | grep -v BOOTPROTO > $tempfile
viewconfig
if [ $confirm != y ]
then continue
fi
done
#load config
echo "BOOTPROTO=static" >> $tempfile
echo "IPADDR=$IPADDR" >> $tempfile
echo "NETMASK=$NETMASK" >> $tempfile
echo "GATEWAY=$GATEWAY" >> $tempfile
cat $tempfile > ${intdir}/ifcfg-${interface}
rm -rf $tempfile
read -p "Do you want to config the DNS Server address?(y/n)" confirm
if [ $confirm = y ]
then
read -p "please input a IPv4 address of first dnsserver: " nameserver1
echo "nameserver $nameserver1" > /etc/resolv.conf
read -p "Do you want to config the second DNS Server address?(y/n)" confirm
if [ $confirm = y ]
then
read -p "please input a IPv4 address of second dnsserver: " nameserver2
echo "nameserver $nameserver2" >> /etc/resolv.conf
fi
fi
/sbin/ifdown $interface
/sbin/ifup $interface
#by Kaiser
本文出自 “凯旋之歌” 博客,请务必保留此出处http://kaiserwu.blog.51cto.com/697390/569438
相关文章推荐
- Shell脚本自动修改Linux网卡地址、IP地址配置、主机名修改
- 快速配置DHCP中继(shell脚本)
- linux下shell脚本获取网卡参数
- 用shell脚本快速安装、配置bind
- shell脚本自动配置双网卡绑定
- shell 脚本 统一参数配置
- Shell脚本实现动态配置IP与路由:解决嵌入式Android/Linux有线和无线网卡双网共存问题
- Shell脚本自动修改Linux网卡地址、IP地址配置、主机名修改
- shell 脚本中传递参数3种方法的比较
- shell脚本 简单的从命令行读取参数
- linux脚本快速克隆虚拟机(多虚拟网卡)
- 用命令行配置网卡参数
- shell脚本参数
- shell脚本实现Linux日志服务配置Edition 2
- shell调用php脚本,并传递参数
- shell 脚本传入参数
- yum源配置以及开机自动挂载shell脚本
- 小黑的日常折腾-快速建立私有CA的shell脚本 推荐
- 验证用户输入的参数合法性的shell脚本
- Shell脚本中判断输入参数个数的方法