前言
实现批量创建多网络,更改主机名称,hosts解析
初始化网卡,主机名称,hosts解析,重启网卡
- 我的主机六个网卡,使用的有四个网卡,以下一键创建和初始化
- 主机名称我是以硬件的SN号最为主机的名称,实际环境看主机的需求进行更改
- 变量host_name_sn获取主机SN号
- 变量vmbr_IP获取vmbr0 IP地址
- 变量vmbr_gateway获取vmbr0 网关地址
- 变量vmbr_bridge桥接的实际网卡接口名称
- 桥接网卡名称定义必须要以vmbr0.100这样,参考这里,不要自定名称,不支持哦
- 其它参考官网
- Proxmox ve 中文参考文档
vim /proxmox_network_hostname.sh
#!/bin/bash
# -*- coding: utf-8 -*-
# Author: make.han
# Email: CIASM@CIASM
# Date: 2024/04/16
# pve The NIC was initially configured, the host name changed, and host issues changedecho "backup network"
mv /etc/network/interfaces /etc/network/interfaces.bakhost_name_sn=`dmidecode -s system-serial-number`
vmbr_IP=`ip addr show vmbr0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'`
vmbr_gateway=`ip route show | grep default | awk '{print $3}'`
vmbr_bridge=`brctl show vmbr0 | awk 'NR==2{print $4}'`echo "Example Initialize the default NIC "
cat <<EOF>>/etc/network/interfaces
# network interface settings; autogenerated
# Please do NOT modify this file directly, unless you know what
# you're doing.
#
# If you want to manage parts of the network configuration manually,
# please utilize the 'source' or 'source-directory' directives to do
# so.
# PVE will preserve these directives, but will NOT read its network
# configuration from sourced files, so do not attempt to move any of
# the PVE managed interfaces into external files!
# restrat netwrok service networking restart or systemctl restart networking.service or ifreload -aauto lo
iface lo inet loopback# Admin Config network
auto vmbr0
auto $vmbr_bridge
iface $vmbr_bridge inet manual
iface vmbr0 inet staticaddress $vmbr_IP/24gateway $vmbr_gatewaybridge-ports $vmbr_bridgebridge-stp offbridge-fd 0# SRP Local network
auto vmbr1
auto eno8403
iface eno8403 inet dhcp
iface vmbr1 inet dhcpbridge-ports eno8403bridge-stp offbridge-fd 0# SRP Remote network
auto vmbr2
auto ens1f0
iface ens1f0 inet manual
iface vmbr2 inet staticaddress 192.168.3.101/24bridge-ports ens1f0bridge-stp offbridge-fd 0# LC Module network
auto vmbr3
auto ens1f1
iface ens1f1 inet manual
iface vmbr3 inet staticaddress 192.168.15.2/24bridge-ports ens1f1bridge-stp offbridge-fd 0iface ens1f2 inet manualiface ens1f3 inet manualsource /etc/network/interfaces.d/*
EOFecho "hostname change"
echo > /etc/hostname
echo "$host_name_sn" > /etc/hostnameecho "hosts change"
sed -i '2d' /etc/hosts
sed -i "2i\\$vmbr_IP $host_name_sn.8.8.8.8 $host_name_sn" /etc/hostsecho "issues change"
sed -i '/https:\/\//d' /etc/issue
sed -i "7i\ https://$vmbr_IP:8006/" /etc/issueecho "restart network"
#service networking restart
systemctl restart networking.service
执行硬件初始化
bash /proxmox_network_hostname.sh