In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of how to set up the network of CentOS7 in vmware, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to set up the network of CentOS7 in vmware. Let's take a look.
Network Settings of centos 7 in vmware
Due to the need to use linux in work, centos7 is installed in the virtual machine for experimental purposes. There are many problems in the process of use after installation, mainly network problems, and the following conditions appear after installation:
(1) the host network is normal, and the external network cannot be accessed in the centos of the virtual machine.
(2) the host can communicate with ping and can connect with ssh, but cannot telnet the port of virtual machine centos.
(3) centos fixed ip problem
(4) Firewall setting problem
After consulting the relevant information and practice, the network problem is solved, and record it here.
I. Environmental description
Vmware workstation 10
Linunx system: centos7, download address on the official website
II. Installation of centos in vmware
The process of installing centos7 in the vmware virtual machine is not complicated, there are many tutorials online (you can refer to one of them (Baidu experience)), this article will not be repeated, briefly make the following instructions and attention.
Using a typical installation, the installer CD image file
Choose cpu and disk size according to the actual situation of the machine. This machine is i7pare 8g memory, and 2g core is allocated to centos7.
Important: there are three network types you can refer to this article. Because you do not want to occupy the existing ip, choose nat and take the host as the route.
The installation software type can choose the minimum installation, file server, basic web server and so on. Recommended minimum installation, clean.
III. Nat network settings
Use nat network settings and do not take up ip resources. For more information on how to set them, please see this article. Here are some important settings:
(1) set the virtual machine to nat network, and right-click Virtual Machine-> Settings, as shown below:
(2) View the network settings of vmnet8
Control Panel-> Network and internet- > Network connection, you can see two virtual network cards, vmnet1 and vmnet8. View vmnet8, right-click-> property, view ipv4 address, and you can see that vmware has automatically assigned an address. As follows:
(3) shared network
The actual Nic-> right-click-> share, as follows
(3) set up virtual network editor, and edit-> virtual network editor, as follows:
The subnet ip here is the same as the vmnet8 segment, and the vmnet8 is 192.168.31.1, so you can set it to 192.168.31.0 here. The mask is the same as vmnet8.
In addition, "assign ip addresses to virtual machines using local dhcp services" can be checked first, and then unchecked when the ip is fixed later.
(4) nat setting
After setting up, enter the virtual machine, if there is no accident, you can connect to the network normally.
(5) check ip and test
Test with ifconfig, where you can see the virtual ip, whose ip is automatically assigned by dhcp.
[root@localhost sysconfig] # ifconfig
In the virtual machine ping host ip, test whether it is connected:
[root@localhost sysconfig] # ping 192.168.31.1 ``
Ping the virtual machine ip on the host, and test whether it is connected:
[root@localhost sysconfig] # ping 192.168.31.128 "
If it can be connected, it proves that the network setting is complete, and you can use ssh to connect to the virtual machine centos.
Fourth, set up fixed ip
According to the above method, although it can be connected, because it is dynamically allocated using dhcp, it may change after each restart, so it is best to set it to a fixed ip. You can refer to this article
The following points need to be noted:
Uncheck "assign ip addresses to virtual machines using local dhcp services" in the vmware virtual network editor.
Modify the configuration of the corresponding network card at the beginning of ifcfg in / etc/sysconfig/network-scripts/.
Modify / etc/resolv.conf to add domain name resolution.
(1) modify the configuration description of the Nic
Note the name of the current network card. You can see it using ifconfig. The name of the network card installed on this machine is: ifcfg-eno16777736.
Open this file and mainly configure the following items (if not, add it):
Onboot=yes is set to start after boot.
Ipaddr=192.168.31.128 # set a fixed ip here
Netmask=255.255.255.0 # set the mask here
Gateway=192.168.31.2 # set the gateway ip here
Bootproto=static # set to static
As shown below:
(2) modify / etc/resolv.conf to realize domain name resolution
Before this setting is made, ping the public network domain name in the virtual machine will report a unknown host error, such as ping www.baidu.com, report ping: unknown host www.baidu.com.
Add the following settings to / etc/resolv.conf:
Nameserver 192.168.31.2
As shown below:
In this way, the virtual machine can test the public network domain name using ping, which is normal.
5. Set up firewall iptables
Centos7's default firewall is not iptables, but firewall. To use iptables, you need to install it first. Complete installation process there are many tutorials online, refer to this article, after the installation is complete, you can use iptables.
Since mysql is installed on the virtual machine and mysql is started normally, it is found that the host cannot connect to the mysql, but the ping virtual machine is connected, so it is conceivable that it must be a port problem. Try to use telnet this port in the host, but you can't connect. You can ping, but the port cannot telnet. There are two possibilities:
(1) centos does not enable telnet
(2) the firewall does not open port 3306. (mainly this problem)
Let's solve it one by one.
5.1 centos install telnet
(1) first check whether the following two installation packages have been installed: telnet-server and xinetd. The command is as follows:
Rpm-qa | grep telnet-server
Rpm-qa | grep xinetd
If it is not installed, install first.
(2) check the installable packages and installations
Yum list | grep telnet
Yum install telnet-server.x86_64
Yum install telnet.x86_64
Yum list | grep xinetd
Yum install xinetd.x86_64
(3) join boot boot
Systemctl enable xinetd.service
Systemctl enable telnet.socket
(4) start up
Systemctl start telnet.socket
Systemctl start xinetd (or service xinetd start)
After telnet starts, the host telnet is still unable to connect, and continue to set up the iptables.
5.2 Firewall iptables Settings
The iptables file path only opens port 22 in / etc/sysconfig/iptables,centos by default, so you need to add ports to the file that need to be accessed, such as telnet port 23, database port 3306 and so on.
If not, the error "can't connect to mysql server (10060)" will be reported when connecting to the database.
(1) add port rules.
As follows:
-an input-m state-- state new-m tcp-p tcp-- dport 3306-j accept
-an input-p tcp-m state-- state new-m tcp-- dport 23-j accept
Description:
[- ai chain]
"insert" or "accumulate" rules for a chain
-a: add a new rule that is added at the end of the original rule.
-I: insert a rule. If the order of this rule is not specified, the default is to insert to become the first rule.
For example, there are four rules originally. If you use-I, the rule becomes the first one, and the original four become the chain 2-5: input, output, forward, etc.
[- io network interface]
Set the interface specification for packet entry and exit
-I: the network interface into which the packet enters, such as eth0, lo, etc. Need to cooperate with input chain
-o: the network interface that comes out of the packet needs to cooperate with the output chain
[- p tcp,udp]
-p protocol: sets which packet format this rule applies to
The main packet formats are: tcp, udp, icmp and all.
[- m]: some plug-in modules of iptables, the main common ones are:
State: status module
Mac: network card hardware address (hardware address)
[- state]: the status of some packets, mainly including:
Invalid: invalid packet, such as packet status of data corruption
Established: online status that has been online successfully
New: want to create a new packet status online
Related: this is the most commonly used! It means that this packet is related to the packet sent by our host.
[- s source ip/ domain]
[- sport port range]
-sport port range: limit the port number of the source. The port number can be consecutive, for example, 1024
[- dport port range]
-dport port range: limit the port number of the destination.
[- j]: followed by actions, the main actions are accept, drop, reject and log
As shown in the following figure:
Special reminder: the added port rule statement must be placed before the reject rule, otherwise it will not work. That is, if the two port rules added above are put in-a forward-j reect … . After the rule, the port is not open, and telnet does not come in outside.
(2) restart iptables
Service iptables restart
After reboot, use telnet 192.168.31.128 3306 again, normal.
Use navicat to connect to the database, normal.
Six summaries
(1) the host network is normal, and the external network cannot be accessed in the centos of the virtual machine.
Solution: use nat connection mode, correctly set the network card configuration, domain name resolution configuration.
(2) the host can communicate with ping and can connect with ssh, but cannot telnet the port of virtual machine centos.
Solution: install telnet and add firewall port rules.
(3) centos fixed ip problem
Solution: set up ifcfg network card file, domain name resolution configuration.
(4) Firewall setting problem
Solution: install iptables, add port rules, and place them before reject rules.
This is the end of the article on "how to set up the network of CentOS7 in vmware". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to set up the network of CentOS7 in vmware". If you want to learn more knowledge, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.