B
自动配置ip与主机名脚本
自动配置ip与hostname脚本
脚本内容
iphost.sh
bash
#!/bin/bash#configure ipaddecho"please input ipaddr last 2 column:"readv_ipecho-e"$v_ip">tmp.txtdaoer=`awk -F. '{print $1}' tmp.txt`IPADDR=10.130.`echo $v_ip`NETMASK=255.255.255.0GATEWAY=10.130.$daoer.1Net_conf=eth0sed-i-e'/IPADDR/d'-e'/NETMASK/d'-e'/GATEWAY/d'-e'/ONBOOT/d'/etc/sysconfig/network-scripts/ifcfg-$Net_confsed-i's/dhcp/static/g'/etc/sysconfig/network-scripts/ifcfg-$Net_confecho-e"IPADDR=$IPADDR\nNETMASK=$NETMASK\nGATEWAY=$GATEWAY\nONBOOT=yes">>/etc/sysconfig/network-scripts/ifcfg-$Net_conf#configure hostnameecho"please input hostname:"readhostnamesed-i-e'/HOSTNAME/d'/etc/sysconfig/networkecho-e"HOSTNAME=$hostname">>/etc/sysconfig/networkecho-e"\n$IPADDR$hostname">>/etc/hostshostnamectl--staticset-hostname$hostnamerm-rftmp.txt#rm -rf /etc/udev/rules.d/70-persistent-net.rulesrm-rf$0bash
使用方法
sh iphost.sh
输入ip后2位
输入主机名
重启网络