[Script] [Linux] Start all network cards

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

Usage: ./ifup_ethernets.sh .
Set the system to start automatically at boot:

  • Place the file in ifup_ethernets.shthe directory /lib/ifupdown/and chmod +x ifup_ethernets.shgive it executable permissions.
  • Create service file/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
  • Start service
systemctl enable ifup_ethernets
systemctl daemon-reload
systemctl start ifup_ethernets

Guess you like

Origin blog.csdn.net/hezhanran/article/details/131242193