為什么需要修改
因為需要用來做k8s集群,通過克隆出來的虛擬機需要修改Host Name 以及 靜態IP。
操作(Debian10)
修改 Host
- 使用命令
hostnamectl
查看當前系統主機名; - 使用命令
hostnamectl set-hostname 新名
設置新主機名; - 打開 /etc/hosts 文件並用新的主機名替換舊的主機名。
$ nano /etc/hosts
127.0.0.1 localhost
127.0.0.1 新名
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
修改 靜態IP
- 1.使用命令
ip a
查看當前網卡設備名以及IP - 2.打開 /etc/network/interfaces 文件並用修改IP。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
# allow-hotplug ens192 # 設置成這個不知道為什么系統不會自動開啟網口
auto ens192
iface ens192 inet static
address 1.1.1.2/24
gateway 1.1.1.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 8.8.8.8 8.8.4.4 202.96.128.86
網卡參數配置語法:
auto ${網卡名}
iface ${網卡名} inet ${static}
address ${IP}
netmask ${netmask}
gateway ${gateway}
allow-hotplug 與 auto 的區別:
auto: 在系統啟動的時候啟動網絡接口,無論網絡接口有無連接 (插入網線)。如果該接口配置了 DHCP,則無論有無網線,系統都會去獲取 DHCP。並且如果沒有插入網線,則等該接口超時后才會繼續 DHCP。
allow-hotplug: 只有當內核從網絡接口檢測到熱插拔事件后才會啟動該接口。如果系統開機時該接口沒有插入網線,則系統不會啟動該接口。系統啟動后,如果插入網線,系統會自動啟動該接口。
- 3.使用命令
systemctl restart networking
重啟網卡