Virtual machine CentOS 7 fixed IP connection provided optimal configuration (reproduced)

Source: Virtual Machine CentOS 7 fixed IP connection provided optimal configuration ( https://my.oschina.net/panhongju/blog/826814 )

Reprinted Description: This is a virtual machine I have read many articles written most clearly static IP configuration, the article is actually available, thanks to the original author.

 

original:


 

Description: Internet search, many articles are similar, are not fully resolved I wanted a fixed IP to achieve an effect

1, the notebook is set to automatically obtain IP host, no matter what the circumstances, the virtual machine is not affected, as long as the connection outside the network can access the Internet;

2, as long as the normal notebook host can access the network, start the virtual machine CentOS 7 system can normally access the Internet without any further settings;

3, the virtual machine is set to a fixed IP, no matter what the host in the network environment, the environment is off the network, or connected to any network environment to access external networks, IP virtual machines are fixed, and the use of terminal connections, not always variable, normally connected;

4, the virtual machines can be arbitrarily set in accordance with a fixed IP they want to set the IP address of the network, for example, I wanted to set a fixed IP address is 192.168.2.2.

More than 4:00, I did not find a post online can achieve the effect I asked, after I study this period of time, after various attempts, during the emergence of various problems, test stability, summarized as follows for everyone to share, we want to help detours.

 

A way as to NAT mode + fixed IP model, and why in this way can be found in the following articles of theoretical knowledge:

http://blog.sina.com.cn/s/blog_601bc5cf0101d32z.html

Configure the environment Description: Home Edition host win10, virtual machine VMware Workstation 12 Pro Chinese version of the virtual machine linux system is CentOS 7 64 bits.

 

1. Set the virtual machine network connection:

Can be set according to the control settings as shown, English

 

2. NAT mode virtual machine's configuration parameters specific address:

(1) Edit - Virtual Network Editor - Change settings

(2) Select VMnet8-- uncheck DHCP-- provided using local IP subnet gateway IP-- set (set here to remember, to use the back), following FIG.

说明:修改子网IP设置,实现自由设置固定IP,若你想设置固定IP为192.168.2.2-255,比如192.168.2.2,则子网IP为192.168.2.0;若你想设置固定IP为192.168.1.2-255,比如192.168.1.2,则子网IP为192.168.1.0;

(3)网关IP可以参照如下格式修改:192.168.2.1

 

3.配置笔记本主机具体VMnet8本地地址参数:

说明:第6步中的IP地址随意设置,但是要保证不能跟你要设置虚拟机的固定IP一样。

 

4.修改虚拟机中的CentOS 7系统为固定IP的配置文件:

(1)进入centos7命令行界面,修改如下内容:

#cd /etc/sysconfig/network-scripts/
#vi ifcfg-eno16777736

说明:

#将IPV6…..协议都注释;
BOOTPROTO=static        #开机协议,有dhcp(动态)及static(静态);
ONBOOT=yes              #设置为开机启动;
DNS1=114.114.114.114    #这个是国内的DNS地址,是固定的;
IPADDR=192.168.2.2     #你想要设置的固定IP,理论上192.168.2.2-255之间都可以,请自行验证; NETMASK=255.255.255.0   #子网掩码,不需要修改; GATEWAY=192.168.2.1   #网关,这里是你在“2.配置虚拟机的NAT模式具体地址参数”中的(2)选择VMnet8--取消勾选使用本地DHCP--设置子网IP--网关IP设置。

(2)重启网络服务

#service network restart

 

5.检验配置是否成功

(1)查看修改后的固定IP为192.168.2.2,配置正确;

#ifconfig

(2)测试虚拟机中的CentOS 7系统是否能连外网,有数据返回,说明可以连接外网;

#ping www.baidu.com

(3)测试本机是否能ping通虚拟机的固定IP,有数据返回,说明可以使用终端工具正常连接;

鼠标放到开始菜单右键,选择命令提示符(管理员),打开命令操作界面:

#ping 192.168.2.2

 

6.远程终端连接

(1)遇到问题,若连接失败是因为CentOS 7的防火墙端口没有打开,比如开启80,3306端口,最后一定要重启防火墙;

#查看防火墙状态
systemctl status firewalld  
#开启80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent  
#开启3306端口 firewall-cmd --zone=public --add-port=3306/tcp --permanent #重启防火墙: firewall-cmd --reload 

(2)连接成功

以上要求的效果全部达到,且完全可以将虚拟机中的CentOS 7做为服务器,在上面部署各种服务啦!!!

若有不对的地方,还请多多指教,互相学习成长。

Guess you like

Origin www.cnblogs.com/144823836yj/p/11111710.html