【脚本】 【Linux】启动所有网卡

ifup_ethernets.sh

#!/bin/bash

# 过滤网卡名称
ethList=(`ifconfig -a | grep ^[a-z] | awk -F: '{print $1}'`)
for ((i=0; i<${#ethList[@]}; i++))
do
    echo 启动网卡 ${ethList[$i]} ...
    ifconfig ${ethList[$i]} up
done

用法: ./ifup_ethernets.sh
设置系统开机自启:

  • 把文件ifup_ethernets.sh放在目录/lib/ifupdown/下,chmod +x ifup_ethernets.sh赋予可执行权限。
  • 创建服务文件/lib/systemd/system/ifup_ethernets.service
[Unit]
Description=ifup all ethernets
DefaultDependencies=no
After=network.target

[Service]
Type=simple
KillMode=none
ExecStart=/lib/ifupdown/ifup_ethernets.sh

[Install]
WantedBy=network.target
  • 启动服务
systemctl enable ifup_ethernets
systemctl daemon-reload
systemctl start ifup_ethernets

猜你喜欢

转载自blog.csdn.net/hezhanran/article/details/131242193
今日推荐