[ubuntu] ubuntu virtual machine setting static ip--the actual test is effective

[ubuntu] ubuntu virtual machine setting static ip – the actual test is effective

You can set a static ip through the ubuntu interface without modifying various files. Effective

The premise is that the virtual machine can already access the Internet. The network mode generally selected here is NAT mode, and the difference here will not be discussed. To put it simply, NAT mode allows your virtual machine to access the Internet. The simplest configuration does not have so many pitfalls, and it can satisfy the communication between the host and the virtual machine (remote control). The bridge mode of the notebook seems to be unable to access the Internet.

  • 0 Preface
  • 1 The topic is directly opened and corrected

0 Preface

Question 1:

At present, sometimes it is necessary to connect to the virtual machine remotely and treat the virtual machine as a server. If the ip of the virtual machine is constantly changing, every time a remote connection is made, the ip of the connected virtual machine needs to be modified every time when connecting with xftp, xshell, winscp, etc. address, which is sure to be troublesome.

Question 2:

In addition, when searching for the answer, I found that many tutorials were not applicable to my situation. Some files may not be perfectly resolved due to the system version, and even the network card information was lost.

For example these commands:

vi /etc/sysconfig/network-scripts/ifcfg-ens33

for example:

image-20221204183112908

In short, on my virtual machine, either there are no these files, or it is useless to change them.

Of course, using the command line to operate is definitely the best, but I haven't found a suitable method.

1. Open the topic directly

  • 1 First check the ip 192.168.1.128 in nat mode, which is actually assigned automatically and will change after a while

  • image-20221204193127460

    • By default, the virtual machine IP in nat mode is dynamically allocated under a certain subnet. For example, 192.168.1.1-192.168.1.254 are all possible, today and tomorrow may be different

    image-20221204183939261

  • 2 Directly find the subnet ip, subnet mask, and gateway ip assigned by the Vmware software to the nat mode. You will need to manually set the ip based on this later.

    image-20221204184317215

image-20221204184526573

3. Enter ubuntu to modify.

Settings, wired settings, gears.

image-20221204185128401

ipv4, change it to manual, and set the ip address by yourself.

  • In fact, the subnet can also be set by yourself, see the previous screenshot here . mine is 192.168.1.0
  • Address ip, choose one from your own network segment, such as 192.168.130. Or 192.168.131 192.168.254 etc.
  • The subnet mask 255.255.255.0 must match the previous
  • The gateway 192.168.1.2 should also match the previous one.

image-20221204185232145

Restart the network

image-20221204185343769

Check ip, ifconfig, the change has been completed.

image-20221204185430437

go online

image-20221204191521816

2. If you still cannot access the Internet here,

  • It is recommended to try from the following aspects

    • 1. Restore the default settings of the vmware software, the virtual network editor, and then re-operate.
    • image-20221204193545118
    • 2. When changing the static ip, it is recommended to add dns, which is the same as the gateway, and cancel the automatic.
    • image-20221204193508741
    • 3. Restart the virtual machine.

    image-20221204192820940

Guess you like

Origin blog.csdn.net/m0_57168310/article/details/128176238