Update network.sh

This commit is contained in:
spiritLHLS 2023-02-24 14:28:18 +08:00 committed by GitHub
parent e6788ee7d5
commit e8b197b5bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,11 +1,20 @@
#!/bin/bash
#from https://github.com/spiritLHLS/pve
# 打印信息
_red() { echo -e "\033[31m\033[01m$@\033[0m"; }
_green() { echo -e "\033[32m\033[01m$@\033[0m"; }
_yellow() { echo -e "\033[33m\033[01m$@\033[0m"; }
_blue() { echo -e "\033[36m\033[01m$@\033[0m"; }
# 查询信息
interface=$(lshw -C network | awk '/logical name:/{print $3}' | head -1)
ip=$(curl -s ipv4.ip.sb)/24
gateway=$(ip route | awk '/default/ {print $3}')
# 录入网关
if grep -q "vmbr0" /etc/network/interfaces; then
echo "vmbr0 already exists in /etc/network/interfaces"
echo "vmbr0 已存在在 /etc/network/interfaces"
else
cat << EOF | sudo tee -a /etc/network/interfaces
auto vmbr0
@ -17,9 +26,8 @@ iface vmbr0 inet static
bridge_fd 0
EOF
fi
if grep -q "vmbr1" /etc/network/interfaces; then
echo "vmbr1 already exists in /etc/network/interfaces"
echo "vmbr1 已存在在 /etc/network/interfaces"
else
cat << EOF | sudo tee -a /etc/network/interfaces
auto vmbr1
@ -36,5 +44,8 @@ iface vmbr1 inet static
EOF
fi
# 重启配置
service networking restart
systemctl restart networking.service
# 配置DHCP