#!/bin/bash
interface1=`ls /sys/class/net|grep en|awk 'NR==1{print}'`
interface2=`ls /sys/class/net|grep en|awk 'NR==2{print}'`
interface_file1="/etc/sysconfig/network-scripts/ifcfg-$interface1"
interface_file2="/etc/sysconfig/network-scripts/ifcfg-$interface2"
echo $interface_file1
echo $interface_file2
while getopts "i:g:n:I:G:N:" opt; do
case $opt in
i)
ip1=$OPTARG
;;
g)
gateway1=$OPTARG
;;
n)
netmask1=$OPTARG
;;
I)
ip2=$OPTARG
;;
G)
gateway2=$OPTARG
;;
N)
netmask2=$OPTARG
;;
?)
;;
esac
done
#判断grub文件是否修改net.ifname信息
new_grub=`cat /etc/default/grub|grep -c "net.ifnames"`
if [ $new_grub -eq 0 ];then
sed -i '1,$s/quiet/quiet net.ifnames=0 biosdevname=0/g' /etc/default/grub
fi
grub2-mkconfig -o /boot/grub2/grub.cfg
mv $interface_file1 /etc/sysconfig/network-scripts/ifcfg-eth0
mv $interface_file2 /etc/sysconfig/network-scripts/ifcfg-eth1
cat >/etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=$ip1
GATEWAY=$gateway1
NETMASK=$netmask1
DNS1=114.114.114.114
EOF
cat >/etc/sysconfig/network-scripts/ifcfg-eth1 <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=eth1
DEVICE=eth1
ONBOOT=yes
IPADDR=$ip2
GATEWAY=$gateway2
NETMASK=$netmask2
DNS1=114.114.114.114
EOF
reboot