Home > Article > System Tutorial > Steps to configure static IP in Linux bridge mode
Introduction | I have been using NAT mode before. During the test, when the android terminal remotely accessed the mysql of the virtual machine, I found that it could not connect. However, I successfully accessed the mysql of the virtual machine Linux copied by my classmate. I thought about the reason because it was set by him. bridge mode. |
Regarding the difference between the two modes, you can search a lot of articles on the Internet. In layman's terms, in NAT mode, the virtual machine is subordinate to the host, that is, access to the external network must be accessed through the host, so the IP of the virtual machine is only Only the host can identify it. In bridge mode, the virtual machine and the host are in a parallel relationship, share a network card (using multiple interfaces of the network card), and can directly access the external network. Therefore, if you want to remotely access the MySQL of the virtual machine, you need to use bridge mode instead of NAT mode. However, the IP in bridge mode generally changes. In order to avoid resetting the IP for each remote connection, it is set to a static IP here.
The first step is to check the IP under Linux This is Ubuntu 16.04. There are 2 items here. The lower one is lo (local loopback) and can be ignored. The upper one needs to be configured. Note that my virtual network card here is ens33, and the one I will modify later is also ens33. There are many configuration tutorials on the Internet where the network card name of their Linux system is not ens33 (for example, some are eth0). The second step is to set up the virtual network In the VMware menu, Edit->Virtual Network Editor Modify "Bridge to" in the VMnet information to the network card adapter. The default is automatic. The third step is to check the IP information of the host (here is windows) The command is ipconfig /all. The reason why the /all option is added at the end is to view the description of the network card. Note that the description here of Qualcomm Atheros is the same as the name of the network card selected in the second step. Remember the three important items of the host. IPv4 address: 192.168.5.63 Subnet mask: 255.255.255.0 Default gateway: 192.168.5.1 Step 4: Modify the Linux network interface configuration $ sudo vim /etc/network/interfaces Modify the file (the specific path varies with the system) and set ens33 to a new IP under the same network segment. Here I set it to 192.168.5.64. (The IP calculation method for the same network segment is that the IP and subnet mask AND operation results are consistent. For example, if 192.168.5.63 and 255.255.255.0 are ANDed, 192.168.5.0 is obtained. For specific knowledge, please refer to the IP part of the computer network textbook) Lines 5 to 10 were manually edited by me. You can see that the gateway and netmask are the same as those on the host, and only the address has been modified. Step 5: Set DNS xyz@ubuntu:~$ sudo vim /etc/resolvconf/resolv.conf.d/head Then restart the virtual machine network service (practice has proven that this step is useless, although I don’t know why, just restart the system honestly.) xyz@ubuntu:~$ sudo /etc/init.d/networking restart [ ok ] Restarting networking (via systemctl): networking.service. Now check if the configuration is correct. Check the IP and it has changed to the set 192.168.5.64 Try pinging a URL: Try the host pinging the virtual machine: But the virtual machine failed to ping the host: The reason is that the firewall is turned on on the host and the firewall on the public network is turned off. Pinging the host again is successful:The above is the detailed content of Steps to configure static IP in Linux bridge mode. For more information, please follow other related articles on the PHP Chinese website!