Skip to content

Netplan

The network configuration abstraction renderer

Netplan is a utility for easily configuring networking on a linux system. You simply create a YAML description of the required network interfaces and what each should be configured to do. From this description Netplan will generate all the necessary configuration for your chosen renderer tool.

Categories

How does it work?

Netplan reads network configuration from /etc/netplan/*.yaml which are written by administrators, installers, cloud image instantiations, or other OS deployments. During early boot, Netplan generates backend specific configuration files in /run to hand off control of devices to a particular networking daemon.

Netplan currently works with these supported renderers

How do I use it?

Configuration

Without configuration, Netplan will not do anything. The simplest configuration snippet (to bring up things via DHCP on workstations) is as follows:

network:
  version: 2
  renderer: NetworkManager

This will make Netplan hand over control to NetworkManager, which will manage all devices in its default way (i.e. any ethernet device will come up with DHCP once carrier is detected).

When individual interface configurations are given, it will not let devices automatically come up using DHCP, but each interface needs to be specified in a file in /etc/netplan/ with its explicit YAML settings for the networkd or NetworkManager backend renderers.

Commands

Netplan uses a set of subcommands to drive its behavior:

  • netplan generate: Use /etc/netplan to generate the required configuration for the renderers.
  • netplan apply: Apply all configuration for the renderers, restarting them as necessary.
  • netplan try: Apply configuration and wait for user confirmation; will roll back if network is broken or no confirmation is given.

Ubuntu 17.10 이전

우분두는 17.10 부터 netplan을 사용하기 시작함. 그 이전 버전은 ifupdown 패키지 기 반인 /etc/network/interfaces 파일 사용. 관련 내용은 Debian:NetworkConfiguration 페이지 참조.

설정 파일 위치

/etc/netplan/*.yaml

해당 위치에 인터페이스 설정이 가능하고 NetworkManager와 networkd 두개의 렌더러를 사용할 수 있다.

NetworkManger 렌더러를 사용하는 경우에는 X Window 환경에서만 사용하고 나머지 경우는 networkd 렌더러를 사용하면 된다.

정적 IP 설정 방법

Open a terminal and edit the Netplan configuration file

vi /etc/netplan/01-network-manager-all.yaml

2. Modify the file as follows. Refer to the comments to understand the function of each line.

# Let NetworkManager manage all devices on this system
network:
  version: 2
  renderer: NetworkManager
  ethernets:
    ens18:  # 여기서 ens18은 실제 사용 중인 인터페이스 이름
      addresses: # 변경 후 IP 주소:
        - 192.168.0.90/24
      routes:
        - to: 0.0.0.0/0  # 모든 트래픽에 대한 기본 경로
          via: 192.168.0.1  # 게이트웨이 IP 주소
      nameservers:
        addresses: [192.168.0.1, 8.8.8.8, 8.8.4.4]

Check IP after applying IP change

sudo netplan apply

ip addr 또는 ifconfig 으로 확인 가능.

DNS 주소를 직접 지정하는 방법

sudo nano /etc/netplan/01-netcfg.yaml

파일 수정:

network:
  version: 2
  ethernets:
    eth0:  # 실제 인터페이스 이름으로 변경
      dhcp4: true
      dhcp4-overrides:
        use-dns: false
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]

적용:

sudo netplan apply

Troubleshooting

Netplan configuration should NOT be accessible by others

** (generate:12390): WARNING **: 21:47:13.631: Permissions for /etc/netplan/01-network-manager-all.yaml are too open. Netplan configuration should NOT be accessible by others.

This warning indicates that the permissions on the Netplan configuration file are too broad, which could pose a security risk. Because the Netplan configuration file can contain sensitive information, it's recommended that you restrict read/write permissions for general users and groups. Here's how to modify the permissions. You can change the permissions using the following command in the terminal.

sudo chmod 600 /etc/netplan/01-network-manager-all.yaml

See also

Favorite site