[NOTE] Vmvare静态地址相关问题

VMware配置集群的过程中,集群机器重启之后往往会重新分配ip,解决如下。

CentOS

yum install net-tools

  • NAT模式

    • 子网地址
    • 子网掩码
    • 网关地址
  • 进入虚拟机vi /etc/sysconfig/network-scripts/ifcfg-eth0也可能是ens33
  • 配置信息如下:
1
2
3
4
5
6
7
8
9
10
11
12
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="00:0C:29:F4:7E:C9"
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUID="2a76c2f8-cd47-44af-936d-11559b3a498d"
IPADDR="192.168.73.100"
NETMASK="255.255.255.0"

GATEWAY="192.168.73.2"
  • 若无法连接外网,加入网关地址xxx.xxx.xxx.2,共享物理机网络,或用114.114.114.114
  • systemctl restart network.service

Ubuntu

step by step

  • sudo vi /etc/network/interfaces

  • edit the configurations

    1
    2
    3
    4
    5
    6
    auto ens33
    iface ens33 inet static
    address 192.168.81.137
    netmask 255.255.255.0
    gateway 192.168.81.2
    dns-nameservers 10.0.208.1
  • sudo ip addr flush ens33

  • sudo systemctl restart networking.service

  • sudo /etc/init.d/networking restart

:

  • 网关为.2,有的博客写的是.1,实测不行
  • dns 114.114.114.114或42.120.21.30
  • 不要开本地dhcp自动分发地址

配置自己网段DNS

  • sudo vi /etc/resolv.conf 迷幻!

    暂时没啥好方法搞定这个,新建个resolv.conf在一个安全的目录,填上:

    1
    2
    3
    nameserver 114.114.114.114
    nameserver 8.8.8.8
    nameserver 8.8.4.4

    碰到问题了就直接cat ./resolv.conf > /etc/resolv.conf

    然后systemctl restart networking.service

    就是这么暴力

    解决方法

Ubuntu 18 LTS server

/etc/netplan/50-cloud-init.yaml

1
2
3
4
5
6
7
8
9
network:
ethernets:
ens33:
addresses: [192.168.1.197/24]
gateway4: 192.168.1.1
nameservers:
addresses: [192.168.1.1]
dhcp4: no
optional: true

netplan apply