#!/bin/bash
addr="10.1.1.81"
gateway="10.1.1.2"
dns="10.1.1.2"
HOST_IF="$(ip route|grep default|head -n1|cut -d' ' -f5)"
# 网卡配置
nmcli connection modify "${HOST_IF}" autoconnect yes ipv4.method manual ipv4.gateway 10.1.1.2 ipv4.dns 10.1.1.2 ipv4.addr ${addr}/24
sed -ri "s/^UUID=.*$/UUID=$(uuidgen)/g" /etc/sysconfig/network-scripts/ifcfg-"${HOST_IF}"
nmcli connection reload "${HOST_IF}" && nmcli connection up "${HOST_IF}"
基于ip配置hostname
HOST_IP=$(ip a|grep "$HOST_IF$"|head -n1|awk '{print $2}'|cut -d'/' -f1)
HOST_NAME=k8s-${HOST_IP//./-}
hostnamectl set-hostname $HOST_NAME
grep "$HOST_IP $HOST_NAME" /etc/hosts || echo "$HOST_IP $HOST_NAME" >> /etc/hosts
标签:10.1,NAME,1.2,ip,虚拟机,HOST,ipv4,固定
From: https://www.cnblogs.com/xwjh/p/17141816.html