netplan ubuntu code example

Example 1: netplan file ubuntu

# sudo su
# cp /etc/netplan/01-netcfg.yaml /etc/netplan/01-netcfg.yaml.bak

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

#configuration example
network:
    ethernets:
        ens33:
            dhcp4: true
            optional: true
        ens34:
            dhcp4: false
            addresses: [192.168.231.3/24]
            gateway4: 192.168.231.50
            nameservers:
               addresses: [192.168.231.50, 8.8.8.8]
        ens35:
            dhcp4: true
    version: 2

# netplan try
# netplan apply

Example 2: netplan multiple interfaces

network:
  version: 2
  renderer: networkd
  wifis:
    wlp2s0b1:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.0.21/24]
      gateway4: 192.168.0.1
      nameservers:
        addresses: [192.168.0.1, 8.8.8.8]
      access-points:
        "network_ssid_name":
          password: "**********"