Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of setting static IP in Virtual Machine Linux bridging Mode

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you the example analysis of setting static IP in virtual machine Linux bridging mode, I believe most people still don't know how to understand, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go and understand it together!

Details are as follows.

NAT mode has been used before, when the android side remotely accessed the mysql of the virtual machine during the test, it was found that it could not connect, but the mysql of the virtual machine copied by the classmate succeeded. I think the reason is the bridge mode he set. About the difference between the two modes, you can find a lot of articles on the Internet, popular point, NAT mode, virtual machine subordinate to the host, that is, access to the external network must be accessed through the host, so the virtual machine IP only the host can identify. In bridge mode, the virtual machine and host are parallel, sharing a network card (using multiple interfaces of the network card) and can directly access the external network.

Therefore, remote access to the virtual machine's mysql requires bridging mode rather than NAT mode. However, the IP of bridge mode will generally change. In order to avoid resetting IP every time remote connection, it is set to static IP here.

Step 1: Check IP under Linux

I am here Ubuntu 16.04, there are 2 items, the following item is lo (local loopback) can be ignored, the above item is the need to configure. Note that my virtual network card here is ens33, which will be modified later. Many configuration tutorials on the Internet do not have ens33 network card names for their Linux systems (for example, some are eth0).

Step 2: Set up a virtual network

VMware menu, Edit-> Virtual Network Editor

Modify "Bridge to" in VMnet information to NIC adapter, default is automatic.

Step 3: Check the IP information of the host (here windows).

The command is ipconfig /all. The reason why the/all option is added after it is to see the description of the network card.

Note that the description of Qualcomm Atheros here is consistent with the name of the NIC selected in step 2. 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 exact path varies from system to system) and set ens33 to the 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, 192.168.5.63 and 255.255.0 are calculated and 192.168.5.0 is obtained. For specific knowledge, refer to the IP part of the computer network textbook)

Lines 5 to 10 are edited manually by me. You can see that gateway and netmask are consistent with those on the host, only address has been modified.

Step 5: Set up DNS

xyz@ubuntu:~$ sudo vim /etc/resolvconf/resolv.conf.d/head

Then restart the virtual machine network service (practice proves that this step is useless, although I don't know why, or honestly restart the system...)

xyz@ubuntu:~$ sudo /etc/init.d/networking restart [ ok ] Restarting networking (via systemctl): networking.service.

Now check if the configuration is wrong

Check IP, it has changed to 192.168.5.64

Try ping a URL

xyz@ubuntu:~$ ping www.baidu.comPING www.a.shifen.com (180.97.33.108) 56(84) bytes of data.bytes from 180.97.33.108: icmp_seq=1 ttl=54 time=40.5 msbytes from 180.97.33.108: icmp_seq=2 ttl=54 time=35.9 msbytes from 180.97.33.108: icmp_seq=3 ttl=54 time=38.6 msbytes from 180.97.33.108: icmp_seq=4 ttl=54 time=35.5 ms^C--- www.a.shifen.com ping statistics ---packets transmitted, 4 received, 0% packet loss, time 3006msrtt min/avg/max/mdev = 35.582/37.696/40.584/2.056 ms

Try host ping virtual machine

But the virtual machine ping host failed

xyz@ubuntu:~$ ping 192.168.5.63PING 192.168.5.63 (192.168.5.63) 56(84) bytes of data.^ C--- 192.168.5.63 ping statistics ---4 packets transmitted, 0 received, 100% packet loss, time 2999ms

The reason is that the host has turned on the firewall and turned off the firewall of the public network.

ping the host again is successful.

xyz@ubuntu:~$ ping 192.168.5.63 PING 192.168.5.63 (192.168.5.63) 56(84) bytes of data.bytes from 192.168.5.63: icmp_seq=1 ttl=128 time=0.931 msbytes from 192.168.5.63: icmp_seq=2 ttl=128 time=0.719 msbytes from 192.168.5.63: icmp_seq=3 ttl=128 time=0.411 msbytes from 192.168.5.63: icmp_seq=4 ttl=128 time=0.448 ms^C--- 192.168.5.63 ping statistics ---packets transmitted, 4 received, 0% packet loss, time 3000msrtt min/avg/max/mdev = 0.411/0.627/0.931/0.212 ms above is "Example analysis of setting static IP in virtual machine Linux bridge mode" All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report