Proxmox VE 实现批量增加多网络

前言

实现批量创建多网络,更改主机名称,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 changed

echo "backup network"
mv /etc/network/interfaces /etc/network/interfaces.bak

host_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 -a

auto lo
iface lo inet loopback

auto vmbr0
auto $vmbr_bridge
iface $vmbr_bridge inet manual
iface vmbr0 inet static
    address $vmbr_IP/24
    gateway $vmbr_gateway
    bridge-ports $vmbr_bridge
    bridge-stp off
    bridge-fd 0
  
auto vmbr1
auto eno8403
iface eno8403 inet dhcp
iface vmbr1 inet dhcp
    bridge-ports eno8403
    bridge-stp off
    bridge-fd 0

auto vmbr2
auto ens1f0
iface ens1f0 inet manual
iface vmbr2 inet static
    address 192.168.3.101/24
    bridge-ports ens1f0
    bridge-stp off
    bridge-fd 0

auto vmbr3
auto ens1f1
iface ens1f1 inet manual
iface vmbr3 inet static
    address 192.168.15.2/24
    bridge-ports ens1f1
    bridge-stp off
    bridge-fd 0
    
iface ens1f2 inet manual

iface ens1f3 inet manual

source /etc/network/interfaces.d/*
EOF

echo "hostname change"
echo > /etc/hostname
echo "$host_name_sn" > /etc/hostname

echo "hosts change"
sed -i '2d' /etc/hosts
sed -i "2i\\$vmbr_IP $host_name_sn.8.8.8.8 $host_name_sn" /etc/hosts

echo "issues change"
sed -i '/https:\/\//d' /etc/issue
sed -i "7i\  https://$vmbr_IP:8006/" /etc/issue

echo "change postfix"
sed -i "s/myhostname=.*/myhostname=$host_name_sn/" /etc/postfix/main.cf

echo "restart network"
#service networking restart
systemctl restart networking.service

执行硬件初始化 

bash /proxmox_network_hostname.sh

创建完成的网卡和主机名称的变更 

命令行查看结果

相关推荐

  1. Proxmox VE (PVE) 教学 (2) | 网络配置

    2024-04-21 09:04:04       38 阅读
  2. NetOps-Python实现批量网络设备配置信息的下载

    2024-04-21 09:04:04       46 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-21 09:04:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-21 09:04:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-21 09:04:04       87 阅读
  4. Python语言-面向对象

    2024-04-21 09:04:04       97 阅读

热门阅读

  1. 【python】python基础学习笔记

    2024-04-21 09:04:04       36 阅读
  2. 使用 Cucumber框架进行BDD测试的一些项目

    2024-04-21 09:04:04       30 阅读
  3. 2024年学习计划

    2024-04-21 09:04:04       31 阅读
  4. Stylus 入门使用方法

    2024-04-21 09:04:04       32 阅读
  5. Stylus入门使用方法

    2024-04-21 09:04:04       45 阅读
  6. stylus入门使用方法

    2024-04-21 09:04:04       43 阅读
  7. leetcode748-Shortest Completing Word

    2024-04-21 09:04:04       33 阅读
  8. 游程编码(Run-Length Encoding, RLE)的python实现

    2024-04-21 09:04:04       24 阅读
  9. 吉林教育报社投稿信箱投稿邮箱

    2024-04-21 09:04:04       29 阅读
  10. 面试 Python 基础八股文十问十答第二期

    2024-04-21 09:04:04       41 阅读