Linux Ubuntu set static ip

1. Problem background

Since the blogger needs to use the docker-compose file to generate the docker container in his own virtual machine, every time the ip address is changed, the docker.yaml file must be changed, which is too troublesome, so set a static ip to fix it , the province has been changing in the future. The personal test is successful, now share it!

2. Local network settings

Go to Control Panel->Network and Internet->Change Adapter Options and enter this page:

 Find this VMnet8, then right-click Properties -> find an IPv4 setting item:

Click to configure:

 3. Set up VMware

Click VMware Edit -> Virtual Network Editor:

 Click to change settings:

 

At the same time, here are the NAT settings  :

 4. Set up a specific virtual machine (mine is Ubuntu18.04)

Use NAT mode to enter Ha!

Power on the virtual machine: 

Because after the Ubuntu17 version, it is no longer necessary to set a static ip in /etc/network/interfaces

Use the netplan method to set up, so we need to find the configuration file of netplan

He is in /etc/netplan/, the file name of each virtual machine is different, so you must find this file under your own virtual machine:

This is the name in my machine, next we modify this file:

sudo vim /etc/netplan/01-network-manager-all.yaml 

The folder is set like this:

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    ens33:   #网卡名字
      dhcp4: no  #禁用DHCP
      addresses: [192.168.235.132/24] #设置本机IP和掩码
      gateway4: 192.168.235.1 #设置v4网关
      nameservers:
        addresses: [192.168.235.1, 8.8.8.8, 114.114.114.114] #设置DNS

After setting: wq! Save

Restart the network card after setting

sudo netplan apply

Then check whether the configuration is successful

ip addr

It can be seen that the configuration is indeed successful

 Then to be safe, we can reboot to restart the virtual machine.

After restarting, let's ping Baidu to see:

success! 

=========================================================================

There is a point here, since I mainly use the docker service in the virtual machine

When the ip docker service is changed, it needs to be restarted! ! ! ! Otherwise, you will not be able to access!

To restart the Docker service, you can follow the steps below:

1. View the status of the Docker service: Run the following command to check the current status of the Docker service:

systemctl status docker

This will display the running status and related information of the Docker service.

2. Stop the Docker service: If the Docker service is running, you can stop it with the following command:

sudo systemctl stop docker

This will stop the Docker service and shut down the associated containers.

3. Start the Docker service: Use the following command to start the Docker service:

sudo systemctl start docker

This will restart the Docker service up and running.

4. Verify the status of the Docker service: Run the following command to verify that the Docker service has started successfully:

systemctl status docker

Make sure the status shows "active (running)", which means the Docker service has restarted successfully.

Through the above steps, you can restart the Docker service. Make sure to perform these operations as a user with appropriate privileges, usually using the `sudo` command.

Guess you like

Origin blog.csdn.net/Wannabe_hacker/article/details/131211440