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