Centos7 network configuration and ping failure in VMware virtual machine

After installing the VMware virtual machine and installing the Centos7 system, we need to configure the network.

Because in the experimental environment, it is necessary to fix the IP to facilitate the use of various environments.

We can use VMware's NET mode for network configuration.

Below, we enter the configuration process:

 

1. Configure VMware's NET network mode

1. Shut down the virtual machine whose configuration needs to be changed at present.

2. Click Edit Virtual Machine Settings-Network Adapter-NAT Mode (N): Used to share the Jurassic IP address, OK.

ad445bbf2b48f883895df60fdb60a742.png-wh_

3. In the VMware virtual machine task bar-Edit (E)-Virtual Network Editor-VMnet8-Uncheck the Use local DHCP service to assign the IP address to the virtual machine Directly let the virtual machine assign IP-change the subnet IP to: 192.168.137.0 #Because this network segment is the network segment assigned to VMnet8 by window-OK

f1bd8d7724e8bb08fcd3ab442437c531.png-wh_

 

Second, configure the Internet connection sharing of the window

1. My computer-right-click property in the blank-control panel home page-network and internet-network and sharing center-change adapter settings-Ethernet (or local network) right-click property-sharing-select Home network connection (H): VMware Network Adapter VMnet8-Checked: Allow other network users to connect through this computer's internet connection-OK

1e57b5f7066c0accf566b0bbbb4d5d04.png-wh_

 

 

Third, manually configure the network configuration in the Centos7 system

cd /etc/sysconfig/network-scripts
ls #找到当前网络配置文件为ifcfg-ens32
sudo vim ifcfg-ens32
#修改如下网络配置
BOOTPROTO=static #以静态方式获取IP
IPADDR=192.168.137.7 #IP地址为192.168.137.7(192.168.137.0网段内)
NETMASK=255.255.255.0
GATEWAY=192.168.137.1 #网关需要与IP在一个网段内
DNS1=192.168.137.1
ONBOOT=yes #开机启动网卡
:wq #保存退出

b93bc0a0446a87c0857848467a900468.png-wh_

sudo systemctl restart network #重启网卡
sudo systemctl enable network #开机启动网卡

 

Four, test

ifconfig #查看网卡信息
ping www.baidu.com #能PING通就是联网成功

a05712486f23dc5b5781dbc29136864a.png-wh_

 

V. Common problems

1. Occasionally, after entering the window host, you cannot access the Internet after entering Centos7

bestlope: You can try to share the network-allow other network users to connect through this computer's internet connection to uncheck and confirm, then check again, basically Centos7 can be connected to the Internet.

1e57b5f7066c0accf566b0bbbb4d5d04.png-wh_

2. The sudo command cannot be used and an error is reported:

xxx is not in the sudoers file.This incident will be reported.

solution:

① Switch to root user:

Excuting an order:

his -

Enter the super administrator password.

② Add the write permission of the sudo file, the command is:
chmod u + w / etc / sudoers

③ Edit the sudoers file
vi / etc / sudoers to
find this line root ALL = (ALL) ALL, add xxx ALL = (ALL) ALL under him (where xxx is your username)

ps: Here you can add any one of the following four lines to sudoers
youuser ALL = (ALL) ALL
% youuser ALL = (ALL) ALL
youuser ALL = (ALL) NOPASSWD: ALL
% youuser ALL = (ALL) NOPASSWD: ALL

The first line: allow the user youuser to execute the sudo command (requires a password). The
second line: allow the users in the user group youuser to execute the sudo command (require the password). The
third line: allow the user youuser to execute the sudo command Do not enter the password at the time. The
fourth line: allow users in the user group youuser to execute the sudo command, and do not enter the password when executing.

④ Revoke the sudoers file write permission, command:
chmod uw / etc / sudoers

So ordinary users can use sudo.

 

Published 210 original articles · praised 37 · 170,000 views +

Guess you like

Origin blog.csdn.net/u012757419/article/details/105431254