📅  最后修改于: 2023-12-03 15:03:09.834000             🧑  作者: Mango
Netplan is a network configuration tool introduced in Ubuntu 17.10 as a replacement for the traditional ifupdown tool. It uses YAML syntax to define network interfaces and their configuration. Static IP configuration is one of the common use cases solved by Netplan.
To configure a static IP address for a network interface, you need to define the following in a YAML file:
Here's an example YAML configuration file for a static IP configuration:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
addresses: [192.168.1.10/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
In the above configuration file:
version
defines the Netplan configuration file version.renderer
specifies the renderer to use. In this case, we're using networkd.ethernets
is a map of network interfaces.enp0s3
is the name of the network interface to configure.addresses
defines the IP address and subnet mask in CIDR notation.gateway4
specifies the default gateway.nameservers
defines DNS server addresses.Once you have created the configuration file, you can apply it with the following command:
sudo netplan apply
Here are some additional options that you can use in a Netplan configuration file:
To configure an IPv6 address for a network interface, you can use the following syntax:
ethernets:
enp0s3:
addresses:
- 192.168.1.10/24
- "2001:db8::2/64"
To define static routes, you can use the routes
option:
ethernets:
enp0s3:
addresses: [192.168.1.10/24]
routes:
- to: 0.0.0.0/0
via: 192.168.1.1
To configure link-level settings for a network interface, you can use the optional
section:
ethernets:
enp0s3:
addresses: [192.168.1.10/24]
optional:
mtu: 1500
Netplan provides an easy and efficient way to configure static IP addresses and other network settings in Ubuntu. With the help of YAML syntax, you can easily define complex network configurations.