欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

虚拟机VMWare CentOs7 配置静态IP

程序员文章站 2022-05-27 13:39:41
...


最近学习Zookeeper需要用到Linux静态IP, 特在此备忘操作.

系统启动后没有IP

虚拟机VMWare CentOs7 配置静态IP
感谢未干的咸鱼分享解决方案.

设置静态IP

[aaa@qq.com ~]# clear
[aaa@qq.com ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:42:52:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.101.30/24 brd 192.168.101.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe42:527a/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

备份ens33

cp /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-ens33_bak

配置静态ID

vi /etc/sysconfig/network-scripts/ifcfg-ens33
----------------------------------------------------------
DEVIE=eth1
# Machine Code
HWADDR=00:0C:29:42:52:7A
TYPE=Ethernet
# 开机时启动网络服务
ONBOOT=yes
NM_CONTROLLED=yes
# 使用静态IP
BOOTPROTO=static
# 前三位要和主机的ip地址一致,后一位为255
BROADCAST=192.168.101.255
DNS1=202.101.172.35
# 虚拟机的IP地址,前三位与主机的一致
IPADDR=192.168.101.30
NETMASK=255.255.255.0
# 主机的默认网关地址
GATEWAY=192.168.101.1
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes

重启网络服务

[aaa@qq.com ~]# sudo service network restart
Restarting network (via systemctl):                        [  确定  ]


[aaa@qq.com ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
# 可以看到IP地址已经设置为 192.168.101.30
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:42:52:7a brd ff:ff:ff:ff:ff:ff
    inet 192.168.101.30/24 brd 192.168.101.255 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe42:527a/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

查看虚拟机Mac

虚拟机VMWare CentOs7 配置静态IP

查看Windows IP

ipconfig

虚拟机VMWare CentOs7 配置静态IP

感谢分享

  1. hongdada - CentOS7.2 设置静态ip
  2. lurunxiu - 虚拟机下Centos7如何设置静态IP地址
  3. 一路前行1 - centOS 7下无法启动网络(service network start)错误解决办法