use*_*537 9 server networking netplan
我有几个 Ubuntu Server 16 安装,其中 NIC 使用interface:X
/etc/network/interfaces 文件中的语法获取静态地址和 dhcp 地址。
auto eno1
iface eno1 inet static
address 172.16.12.18
netmask 255.255.252.0
network 172.16.12.0
broadcast 172.16.15.255
gateway 172.16.12.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 172.16.0.3 172.16.8.7 8.8.8.8
auto eno1:1
iface eno1:1 inet static
address 172.16.13.18
netmask 255.255.252.0
network 172.16.12.0
broadcast 172.16.15.255
gateway 172.16.12.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 172.16.0.3 172.16.8.7 8.8.8.8
auto eno1:0
iface eno1:0 inet dhcp
Run Code Online (Sandbox Code Playgroud)
这导致上面的服务器获得下面的两个静态地址和一个 DHCP 地址。
$ ip addr show eno1
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 48:0f:cf:63:09:91 brd ff:ff:ff:ff:ff:ff
inet 172.16.12.18/22 brd 172.16.15.255 scope global eno1
valid_lft forever preferred_lft forever
inet 172.16.13.18/22 brd 172.16.15.255 scope global secondary eno1:1
valid_lft forever preferred_lft forever
inet 172.16.15.27/22 brd 172.16.15.255 scope global secondary eno1:0
valid_lft forever preferred_lft forever
Run Code Online (Sandbox Code Playgroud)
我昨天安装了 Ubuntu Server 18,发现 netplan 是首选的网络管理器。我能够在 yaml 配置中为 netplan 添加多个 IP,但地址都是静态的。我想获得一个静态地址和一个 DHCP 地址。
# cat /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eno1:
addresses: [ 172.16.9.250/22 , 172.16.10.250/22 ]
gateway4: 172.16.8.1
nameservers:
search: [ staff.example.com , example.com ]
addresses:
- "172.16.8.7"
- "172.16.0.3"
Run Code Online (Sandbox Code Playgroud)
我想要静态和动态的原因是我在几年前设置的 NFS 服务器上找到的修复程序的保留。一台旧的 Solaris 机器无法连接到上面的 12.18 地址,所以我会添加另一个静态地址 - 稍后配置 NFS 服务器以获取 DHCP 地址 - 不稳定的 Solaris 服务器可以将 NFS 卷挂载到额外的 IP 上.
是否可以配置 netplan 以获取 DHCP 地址并在同一接口上分配静态地址?
小智 11
解决方案非常简单,只需设置一个静态 IP 地址并启用 DHCP。基本上你只需要添加dhcp4: yes
到你的配置中。
此配置为我提供了一个主要静态 IP 地址和一个辅助 DHCP 分配的 IP 地址:
network:
version: 2
renderer: networkd
ethernets:
enp0s3:
dhcp4: yes
dhcp6: no
addresses:
- 10.1.2.15/24
gateway4: 10.1.2.1
nameservers:
search:
- example.com
addresses: [10.1.2.10]
Run Code Online (Sandbox Code Playgroud)
结果ip address show enp0s3
给了我:
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:ab:cd:ef brd ff:ff:ff:ff:ff:ff
inet 10.1.2.15/24 brd 10.0.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet 10.1.2.96/24 brd 10.0.1.255 scope global secondary dynamic enp0s3
valid_lft 3224sec preferred_lft 3224sec
inet6 fe80::a00:27ff:fe20:2c40/64 scope link
valid_lft forever preferred_lft forever
Run Code Online (Sandbox Code Playgroud)
地址 10.1.2.96 是secondary dynamic
关键字指示的辅助 DHCP 分配地址。
归档时间: |
|
查看次数: |
11976 次 |
最近记录: |