Linux: Netplan configuration guide to see when you want to fix the IP address

I wrote it because I had a hard time unexpectedly when I tried to fix the IP address from the terminal by just touching Linux as a hobby.

This time, I set it in a Wi-Fi environment, but I also consider the difference from a wired connection.

important point

――I have no knowledge about networks. Therefore, this article may also have serious mistakes and flaws. --My environment is Zorin OS 15.3. Since it is based on Ubuntu and has a lot in common, I think that it can be set in the same way on Ubuntu. However, it has not been verified. --It can be set relatively easily from the GUI. [Reference link 1](#Reference link) --This time, it is set using a command. ――As I wrote above, the main method is to write the configuration file in a Wi-Fi environment. [Reference links 4, 6](#reference links) is recommended for detailed wired settings.

procedure

  1. [Check network settings](# 1-Check network settings)
  2. [Create configuration file](# 2-Create configuration file)
  3. [Apply Settings](# 3-Apply Settings)

1. Check network settings

This is a preparation for fixing the IP address.

1-1. [Check IP address / interface name](# 1-1-Check ip address interface name) 1-2. [Check the address of the default gateway](# 1-2-Check the address of the default gateway) 1-3. [Check DNS address](# 1-3-Check dns address)

1-1. Check the IP address / interface name

What IP address should be fixed? It should be easy to understand. Anything that is not used in other devices will do. You can check what kind of IP address you have now with the following command.

$ ip address

Also check which interface is used. (I don't know how to distinguish it .. It may be the one with more lines than others ..)

By the way, you can also narrow down the output to a specific interface.

$ip address show interface name

1-2. Find out the address of the default gateway

You can check it with ʻip route. To output only the default one with grep`, it is as follows.

$ ip route | grep default

1-3. Look up the DNS address

I see a statement that you should refer to /etc/resolv.conf directly, but this seems to be a mistake. In the first place, this file is generated by systemd-resolved, and it seems to use systemd-resolved --status when you want to know the details. [Reference 2](#Reference link)

$ systemd-resolved --status

The number in DNS Servers in the interface item examined above is the target address.

2. Creating a configuration file

Create it in / etc / netplan /. The file name is 99_config.yaml. It seems that editing the existing XX_config.yaml is deprecated. [Reference 3,4](#Reference link)

/etc/netplan/99_config.yaml


network:
  version: 2
  renderer: networkd
  wifis:
Interface name:
      dhcp4: no
      dhcp6: no
      addresses:
        - 192.168.XXX.XXX/24
      gateway4: 192.168.XXX.XXX
      nameservers:
        addresses:
          - 192.168.XXX.XXX
      access-points:
        "accessPoint1":
          password: "password"
        "accessPoint2":
          password: "password"

Netplan seems to support two backends, networkd and Network Manager. When I was researching, many sites used networkd, but if you use Network Manager, use renderer: NetworkManager.

The 4th line is wifis:, but for wired connection, please use ʻethernets:`.

The interface name should be the one in [1-1. Check the IP address / interface name](# 1-1-Check the IP address interface name).

Line 9 -192.168.XXX.XXX/24 should be the IP address you want to fix.

Line 10 gateway4: 192.168.XXX.XXX should be the one in [1-2. Find the default gateway address](# 1-2-Check the default gateway address).

The -192.168.XXX.XXX on the 13th linenameservers:> ʻaddresses:` should be the one in [1-3. Look up DNS addresses](# 1-3-look up dns addresses).

After the 14th line ʻaccess-points:`, only Wi-Fi connection is set. Please note that the access point name (SSID) and password should be enclosed in double quotation marks. You can have one or three or more access points.

3. Apply settings

It's scary to apply the settings suddenly, so use the netplan try command. After applying the settings temporarily, if the Enter key is not pressed, it will automatically return to the original settings in 120 seconds. You can change it to any number of seconds with the --timeout option. [Reference 5](#Reference link)

$ sudo netplan try --timeout 180

During this time, reconnect to the network and then try searching the net to see if it connects properly. It is also a good idea to set up another terminal and check with ʻip address` to see if the IP address is actually fixed.

If successful, press Enter and you're done!

Even if it times out, it can be applied with the apply command.

$ sudo netplan apply

Finally

In the first place, I had too little knowledge of networks to look up terms, but I had a lot of trouble because the websites that hit the search were old and the methods varied from site to site. First of all, it took time to get to the point of "using Netplan". When I first wrote 99_config.yaml, I didn't know the try command and just ʻapply`. As a result, I was disappointed because I couldn't connect ... I made a mistake in the description, but I didn't notice it at first, so I moved the configuration file, restarted the PC, and did various things. The night before I wrote this, I was depressed, saying, "I have to re-install the OS tomorrow ...", even after correcting the mistake. When I started up my PC this morning, I was happy that the Wi-Fi was connected (although I couldn't fix the IP address), but I was confused because I didn't understand the reason. After that, when I set it by looking at the Netplan official [(Reference 6)](#Reference link), it succeeded in fixing. After all the formula is great. Recommended with [Reference 4](#Reference link) for wired and more complicated network environments.

This is a poor article, but thank you for reading to the end.

Reference link

  1. How to set a fixed IP address in Ubuntu 18.04 LTS [Desktop]
  2. networking - What DNS servers am I using? - Unix & Linux Stack Exchange
  3. [Ubuntu] Stop editing /etc/netplan/50-cloud-init.yaml-Qiita
  4. Network - Configuration | Server documentation | Ubuntu
  5. [Set fixed IP address on Ubuntu 20.04 LTS-Qiita](https://qiita.com/zen3/items/757f96cbe522a9ad397d#try%E3%82%B3%E3%83%9E%E3%83%B3% E3% 83% 89)
  6. Netplan | Backend-agnostic network configuration in YAML

Recommended Posts

Linux: Netplan configuration guide to see when you want to fix the IP address
When you want to update the chrome driver.
When you want to use python2.x on modern Gentoo Linux
[Linux] I want to know the date when the user logged in
When you want to save the result of the callback function somewhere
What to do when you get "I can't see the site !!!!"
When you want to adjust the axis scale interval with APLpy
Python Note: When you want to know the attributes of an object
When you want to change the HTTP headers of Flask's test client
Linux: Fix the address returned by malloc
I made you to express the end of the IP address with L Chika
I want to be notified when the command operation is completed on linux!
Added firewalld to Amazon Linux 2 (IP address restrictions)
Do you want me to fix that copy?
[Linux] When you want to search for a specific character string from multiple files
When the variable you want to superscript with matplotlib is two or more characters
What to do if you get the error ʻERR_FEATURE_UNAVAILABLE_ON_PLATFORM` when using ts-node-dev on Linux
I want to see the file name from DataLoader
Settings when you want to run python-mecab with travis
When you want to filter with Django REST framework
When you want to play a game via Proxy
When you want to plt.save in a for statement
The programming language you want to be able to use
If you want Linux to boot even if the disk mount fails, add the nofail option to fstab.
[Python] When you want to import and use your own package in the upper directory
A site to see when you want to read a machine learning paper but it seems difficult
Solution when you want to use cv_bridge with python3 (virtualenv)
[Django] A memorandum when you want to communicate asynchronously [Python3]
[AWS] What to do when you want to pip with Lambda
You who color the log to make it easier to see
When you want to register Django's initial data with relationships
[AWS EC2] Settings you want to do on Amazon Linux 2
If you want your colleagues to use the same language
When you want to hit a UNIX command on Python
When you want to use multiple versions of the same Python library (virtual environment using venv)