【shell脚本】自动生成网卡文件主要内容auto_network_scripts.sh

[root@rhel8 shell]# cat auto_network_scripts.sh 
#!/bin/bash
# Auto Make KVM Virtualization
# Auto config bond scripts
# by author tanbaobao 2020/06/09

NET_NAME=`route -n | sed -n '3p' | awk '{print $8}'`

function ens_bond()
{
    NETWORK=(
        IPADDR=`ifconfig $NET_NAME | egrep -w inet | sed -e 's/^.*inet //g' | sed -e 's/ netmask.*$//g'`
        NATMASK=`ifconfig $NET_NAME | egrep -w netmask | sed -e 's/^.*netmask //g' | sed -e 's/broad.*$//
g'`        
     GETWAY
=`route -n | egrep "UG" | awk '{print $2}'` UUID=`nmcli c | sed -n '2p' | awk '{print $2}'` ) cat > ifcfg-$NET_NAME <<EOF TYPE=Ethernet BOOTPROTO=none NAME=$NET_NAME ${NETWORK[3]} DEVICE=$NET_NAME ONBOOT=yes ${NETWORK[0]} ${NETWORK[1]} ${NETWORK[2]} DNS1=8.8.8.8 DEFROUTE=yes DNS2=114.114.114.114 EOF } ens_bond

 

posted @ 2020-06-09 20:14  HeiDi_BoKe  阅读(310)  评论(0编辑  收藏  举报