Ubuntu17.10 setting solid state IP

Time:2020-12-3

This paper was first published inMy blog

After setting the basic environment, you need to set a fixed IP. Otherwise, every time I start, I will change IP, and I will go crazy every time I adjust IP.

In Ubuntu 17.10, a new command is used to configure static IP.

What we need to modify isvim /etc/netplan/01-netcfg.yaml

Let’s first look at the content and format of the document:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: yes

We can see the settings heredhcp4byyes。 It means yesdhcppattern.

OK, now we’re going to modify it. The following is a modified format:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.110.231/24]
      gateway4: 192.168.110.1
      nameservers:
          addresses: [114.114.114.114, 8.8.8.8]

Now let’s explain the changes:

  • dhcp4: automatic allocation of IPv4, set tonoIndicates that the IPv4 address is not assigned automatically
  • dhcp6: automatic allocation of IPv6, set tonoIndicates that the IPv6 address is not assigned automatically
  • addresses: set fixed IP. Here’s one/24We need to talk about this one separately.
  • gateway4: gateway address.
  • nameservers: DNS server.addressesCan be set to more than one.

If someone has set the static IP of windows or the static IP of previous versions of Ubuntu, they may feel that there is one thing missing, that is, the subnet mask.

That’s what this is about/24Yes. It is actually the subnet mask set. The following is the IP address corresponding to the prefix. We can use this to set the response.

Prefix size Subnet mask
/24 255.255.255.0
/25 255.255.255.128
/26 255.255.255.192
/27 255.255.255.224
/28 255.255.255.240
/29 255.255.255.248
/30 255.255.255.252

OK, after we have modified the content of the configuration file according to the actual situation. Execute the following command to deploy:

sudo netplan apply

If there is no problem, the solid-state IP is set successfully. Then we reconfigure the IP address of our xshell login and login again.

Well, isn’t it very simple?