Ubuntu 18.04 static IP configuration

Keywords: network Ubuntu TCP/IP

My Ubuntu is installed with VMware and connected with. nat.
By default, VMware will automatically assign one of the many ip addresses to the virtual machine installed with. nat, that is, the ip address may change.
The steps to configure a static IP address are as follows:
         (1) Open VMware's virtual network editor, click change settings, and select Vmnet8.
         (2) Click NAT settings, and you will see VMware's subnet IP, subnet mask and gateway. Obtain the network number through the subnet mask and subnet IP (for the knowledge of how to obtain the network number through the mask, Baidu). The network number of the virtual machine must be the same as the network number of VMware. The host number behind the network number can be written freely, but do not write 0 or 255, so now you know what the IP address of the virtual machine is, Is the network number. Host number; The gateway of the virtual machine must be the same as that of VMware. You know how to write the gateway of the virtual machine. The subnet mask of VMware is generally 255.255.255.0, and the subnet mask of the virtual machine is the same as that of VMware. You know how to write the subnet mask of the virtual machine again.
Note: you may notice that there is an option to use the local DHCP service to assign IP addresses to the virtual machine. It means that an IP address will be automatically assigned to the virtual machine. This IP address may change, but we can configure the network card in the virtual machine without automatically assigning it to the assigned address.
         (3) To sum up, you already know the following three things:
                 IP address of the virtual machine
                 The subnet mask of the virtual machine
                 Gateway for virtual machines
           Finally, search the Internet for a usable DNS as the DNS of the virtual machine. If DNS is not configured for the virtual machine, the virtual machine can only access the network through the IP address. For example, those configured with DNS can directly use www.baidu.com to access Baidu, and those not configured can only use Baidu's IP address.
         (4)Ubuntu network configuration:
         ifconfig get network card name:

fu@fu-virtual-machine:/etc/netplan$ ifconfig
# ens33 is the name of my network card
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.159.128  netmask 255.255.255.0  broadcast 192.168.159.255
        inet6 fe80::20c:29ff:feb0:3558  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:b0:35:58  txqueuelen 1000  (Ethernet)
        RX packets 471965  bytes 655023318 (655.0 MB)
        RX errors 1129  dropped 0  overruns 0  frame 0
        TX packets 175546  bytes 14636150 (14.6 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 19  base 0x2000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local loopback)
        RX packets 11306  bytes 1126635 (1.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11306  bytes 1126635 (1.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

         cd /etc/netplan, enter the / etc/netplan directory

# Enter directory
fu@fu-virtual-machine:/etc/netplan$ cd /etc/netplan
# ls found the. yaml file
fu@fu-virtual-machine:/etc/netplan$ ls
01-network-manager-all.yaml

         Edit the. yaml file in this directory, sudo nano *.yaml, and write the following contents.

# Note that my Chinese notes should be deleted and the format must be correct
# Indent only one space at a time, never tab
network:
  version: 2
  renderer: NetworkManager
  ethernets:
     ens33:
       dhcp4: no # Indicates that the IPV4 address is not dynamically allocated
       dhcp6: no # Indicates an IPV6 address that is not dynamically allocated
       addresses: [192.168.159.128/24] # It's the IP address you got above. / 24 is the mask. This is a representation of the network. Search the Internet and you'll understand it
       gateway4: 192.168.159.2 # It's the gateway you got above
       nameservers:
         addresses: [180.76.76.76] # dns

         sudo netplan apply, after the command is executed, your network card is configured. Go to the network sign at the top right to switch your configured network card, ping Baidu and test whether it is done well.

The Internet is full of bad configuration methods. I don't tell you why and how to find the configuration data. I always use some previous terms to express the current terms, which makes people confused. After tossing all afternoon, I finally tossed it out. I really hope to write articles clearly. Don't always copy other people's, and you don't understand yourself, so that others don't understand you.

Posted by dave_55 on Tue, 02 Nov 2021 02:50:45 -0700