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.sh
the directory/lib/ifupdown/
andchmod +x ifup_ethernets.sh
give 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