大网数据广告活动
服务器运维问答

NetPlan not applying static IP for VLAN

· 52CE 我爱测

I setup a new Ubuntu 18.04 server and spend some time fighting with netplan . I only need a very simple network config, but for some reason it does not work and I have no idea what is wrong. I need a VLAN with a static IP . The p…

问题原文

原帖链接 · Pungrammer · CC BY-SA 4.0

I setup a new Ubuntu 18.04 server and spend some time fighting with netplan. I only need a very simple network config, but for some reason it does not work and I have no idea what is wrong.

I need a VLAN with a static IP.

The problem: As soon as I configure any static IP (either on the physical interface or the VLAN) I loose any connection.

This is my current (not working) yaml (it is the only yaml, so there is no other config interfering)

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0: #the physical interface
    match:
      macaddress: "xx:xx:xx"
    dhcp4: no

    #this is the same IP I would get with dhcp
    addresses: [ "10.1.0.1/24" ]
    gateway4: 10.1.0.254
vlans:
  lab1:
    id: 10
    link: eth0
    dhcp4: no
    addresses: [ "10.1.10.100/24" ]

After applying the config I got following IF<->IP:
eth0 <-> 10.1.0.1
lab1 <-> 10.1.0.1

And I was unable to connect to the server via ssh or ping it at this IP.

Configuration after running netplan generate:

10-netplan-eth0.network

[Match]
MACAddress=xx:xx:xx

[Network]
Address=10.1.0.1/24
Gateway=10.1.0.254
VLAN=lab1

10-netplan-lab1.network

[Match]
Name=lab1

[Network]
Address=10.1.10.100/24

10-netplan-lab1.netdev

[NetDev]
Name=lab1
Kind=vlan

[VLAN]
Id=10

If I change both to dhcp4: yes and remove the addresses/gateway, I get the same addresses as statically configured above from DHCP and ssh/ping work for the VLAN address.

If I change eth0 to dhcp4: yes and leave the static config for lab1, lab1 gets a DHCP assigned address.

Why is the static address for lab1 ignored?

Note: I was assured the switching/routing is correctly configured, but I am willing to check this again.

已采纳解答

原帖链接 · sarlacii · CC BY-SA 4.0

Since this question may get other views, I thought I'd quickly answer.

The syntax of the YAML file must be correct in order for the items to be configured. Check the file with "netplan --debug generate" to see issues, else the generate and apply will configure whatever is valid, and ignore the rest (to be resilient - something is better than nothing).

In this case, the OP's indentation of the vlan section is incorrect. It must line up with the "ethernets" heading, indented from the "network" heading. Should be:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0: #the physical interface
    match:
      macaddress: "xx:xx:xx"
    dhcp4: no

    #this is the same IP I would get with dhcp
    addresses: [ "10.1.0.1/24" ]
    gateway4: 10.1.0.254
  vlans:
    lab1:
      id: 10
      link: eth0
      dhcp4: no
      addresses: [ "10.1.10.100/24" ]

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-08-13)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。