




#!/bin/bash

sudo apt install network-manager -y

# 获取当前网络接口名称
interface=$(ip route | awk '/^default/ { print $5 }')

# 获取已由DHCP分配的IP地址和掩码
current_ip=$(ip addr show dev "$interface" | awk '$1 == "inet" { sub("/.*", "", $2); print $2 }')
current_mask=$(ip addr show dev "$interface" | awk '$1 == "inet" { print $2 }' | cut -d "/" -f 2)

# 获取当前默认网关
gateway=$(ip route | awk '/^default/ { print $3 }')

# 获取当前DNS服务器
dns=$(nmcli device show "$interface" | awk '/IP4.DNS/ { print $2 }')

# 设置静态IP地址
cp /hive-config/network/20-ethernet.network /hive-config/network/20-ethernet.network.bck
echo "[Match]" >/hive-config/network/20-ethernet.network
echo "Name=e*" >>/hive-config/network/20-ethernet.network
echo "[Network]" >>/hive-config/network/20-ethernet.network
echo "DHCP=no" >>/hive-config/network/20-ethernet.network
echo "Address="$current_ip"/"$current_mask"" >>/hive-config/network/20-ethernet.network
echo "Gateway=$gateway" >>/hive-config/network/20-ethernet.network
echo "DNS=192.168.88.1" >>/hive-config/network/20-ethernet.network
echo "[Dhcp]" >>/hive-config/network/20-ethernet.network
echo "ClientIdentifier=mac" >>/hive-config/network/20-ethernet.network
echo "RouteMetric=10" >>/hive-config/network/20-ethernet.network