Virtual machine Linux CentOS bridge mode and NAT mode configure static IP


Bridge Mode

1. First set this linux network adapter to bridge mode:

network adapter

2. View the host network configuration

Ctrl + R to open and run, enter cmd, and then enter ipconfig:

 

IP information

 

Remember IPv4 address and default gateway

3. The virtual machine opens the first configuration file:

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

The last eth0 is that the network card name is not fixed. After opening, modify as follows:

DEVICE=eth0
BOOTPROTO=static #静态IP的关键
HWADDR=00:0C:29:17:01:FC
ONBOOT=yes 启动时加载
TYPE=Ethernet
IPADDR=192.168.1.220  #自己设置静态IP,不冲突就可以
NETMASK=255.255.255.0
GATEWAY=192.168.1.1 #在主机配置中看到的默认网关
BROADCAST=192.168.1.255
DNS1=192.168.1.1 #设置和网关一样的值
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
NM_CONTROLLED=yes

4. Modify the second configuration file:

[root@localhost ~]# vim /etc/sysconfig/network

Modify as follows:

NETWORKING=yes
NETWORKING_IPV6=no #关掉IPv6
HOSTNAME=localhost.localdomain
GATEWAY=192.168.1.1 #默认网关地址

5. Modify the third configuration file:

[root@localhost ~]# vim /etc/resolv.conf

Modify as follows:

search localdomain
nameserver 8.8.8.8 #DNS域名解析地址(首选)
nameserver 192.168.1.1 #(备用)可以写成其它比如114.114.114.114

6. Restart the network service after the modification:

[root@localhost ~]# service network restart

NAT mode

1. Similarly, first set the network adapter of the virtual machine to NAT mode:

network adapter

2. Modify VMware's "Virtual Network Editor":

Click Edit-> Virtual Network Editor:

 

edit

 

After opening, first click on NAT mode, then uncheck the DHCP below, then click on NAT settings:

 

Virtual network adapter


NAT is set to 110 network segments by default. This can be modified. If it is modified, it must be modified uniformly and not dropped. Don't modify it without special requirements.
After opening the NAT settings panel, remember the IP in the red box below:

NAT settings

3. After the settings are completed, start the virtual machine and modify the first configuration file. This time, configure according to the IP in the NAT settings:

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0

Change as follows:

DEVICE=eth0
BOOTPROTO=static
HWADDR=00:0C:29:17:01:FC
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.110.128 #网段限制在110所以IP地址变了
NETMASK=255.255.255.0
GATEWAY=192.168.110.2 #按照NAT设置中的网关地址设置
BROADCAST=192.168.110.255
DNS1=192.168.110.2
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
NM_CONTROLLED=yes

4. Modify the second configuration file:

[root@localhost ~]# vim /etc/sysconfig/network

Change as follows:

NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain
GATEWAY=192.168.110.2

5. Modify the third configuration file:

[root@localhost ~]# vim /etc/resolv.conf

Change as follows:

search localdomain
nameserver 8.8.8.8
nameserver 192.168.110.2

6. Restart the network service after the modification:

[root@localhost ~]# service network restart



Author: Nine saury
link: https: //www.jianshu.com/p/161d78e7d12e
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.

Published 15 original articles · praised 7 · 10,000+ views

Guess you like

Origin blog.csdn.net/qq_40938267/article/details/84562091