CentOS修改动态ip

虚拟机上安装lnmp后经常重启使用xshell无法连接

vim /etc/sysconfig/network-scripts/ifcfg-enp0s3

# 将BOOTPROTO值修改为 static
# 该处选项为: static dhcp none
BOOTPROTO=static
#同时在后面新加
#静态ip
IPADDR=192.168.0.250
#子网掩码
NETMASK=255.255.254.0
#网关
GATEWAY=192.168.0.2
# DNS
DNS1=114.114.114.114
DNS2=8.8.8.8

如图:

保存退出

# 重启网络
service network restart
# This is the network config written by 'subiquity'
network:
  ethernets:
    eno1:
      dhcp4: false
      addresses:
        - 192.168.1.12/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [114.114.114.114,8.8.8.8]
    eno2:
      dhcp4: true
    eno3:
      dhcp4: true
    eno4:
      dhcp4: true
  version: 2