#!/bin/bash
##################自娱自乐的小工具########################
number="200"
#ehh0 dhcp
#eth1 172.16.ip1.xx
#eth2 172.17.ip2.xx
#eth3 -
#ip前段
ip1="172.16."
ip2="172.17."
#日期
L_data=$(date +%s)
#备份原配置
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /boox/bak/ifcfg-eth0-$L_data
cp /etc/sysconfig/network-scripts/ifcfg-eth1 /boox/bak/ifcfg-eth1-$L_data
cp /etc/sysconfig/network-scripts/ifcfg-eth2 /boox/bak/ifcfg-eth2-$L_data
cp /etc/sysconfig/network-scripts/ifcfg-eth3 /boox/bak/ifcfg-eth3-$L_data
#删除现有配置
#现有配置中MAC地址是错的,删了就删了
rm -f /etc/sysconfig/network-scripts/ifcfg-eth*
#eth0设置为DHCP
nmcli connection add type ethernet con-name eth0 ifname eth0
#这条命令会自动生成ifcfg-eth*文件,其中的HWDDR为当前网卡
#eth0网卡MAC地址的末两位
var=$(ip add show eth0 | awk '{print $2}' | head -n 2 | tail -n 1)
var=${var//:/ }
for element in $var
do
mac=$(echo $element)
done
ip=$(echo $((16#$mac)))
nmcli connection add con-name eth1 ifname eth1 type ethernet ip4 $ip1$number.$ip/16
nmcli connection add con-name eth2 ifname eth2 type ethernet ip4 $ip2$number.$ip/16
hostnamectl set-hostname Centos-$number-$ip
systemctl restart network.service
ip add
阅读(428) | 评论(0) | 转发(0) |