如何创建非nat lxd网桥(使用lxd网络)?

如何创建非nat lxd网桥(使用lxd网络)?

如何创建非nat lxd网桥?

我尝试了以下网络配置,然后针对相关容器运行sudo service networking reloadlxc stop运行lxc start。我无法10.1.1.1/24使用非 NAT 桥接器让主机和容器都位于子网上。当使用默认的lxdbr0NAT 时,一切正常。

我尝试了以下配置。首先不分配子网:

config:
  ipv4.nat: "false"
  ipv6.address: none
description: ""
name: testbr0
type: bridge
used_by:
- /1.0/containers/test
managed: true

分配子网:

config:
  ipv4.address: 10.1.1.1/24
  ipv4.nat: "false"
  ipv6.address: none
description: ""
name: testbr0
type: bridge
used_by:
- /1.0/containers/test
managed: true

当使用上述配置时,主机失去网络连接。

如何创建非nat lxd网桥(使用lxd网络)?

答案1

如果您不使用 NAT,则必须在网桥中包含外部接口。您可以像在 Ubuntu 中创建网桥一样执行此操作,但 LXD 3.0 有一个配置选项。它是bridge.external_interfaces。我还在桥接接口上将 ipv4.address 设置为 none。如果您想要这种行为,这将阻止您的 LXD 主机在桥接接口上获取 IP。

config:
  bridge.driver: native
  bridge.external_interfaces: eth5
  ipv4.address: none
  ipv4.firewall: "true"
  ipv4.nat: "false"
  ipv6.address: none
  ipv6.nat: "false"

LXD 3.0 网络 API有关可在您的配置中包含的内容的更多详细信息。

以下是添加此配置后 brctl 命令的输出:

root@lxd01:~# brctl show rtmp
bridge name     bridge id               STP enabled     interfaces
rtmp            8000.ba657ffc1473       no              eth5

答案2

以下是 MWE:

$ lxc network create nonnatbr                                                                                  
Network nonnatbr created

$ lxc network set nonnatbr ipv4.nat false

$ lxc profile create testprofile
Profile testprofile created

$ lxc profile edit testprofile

$ lxc profile show testprofile

config:
  user.user-data: |
    #cloud-config
    ssh_authorized_keys:
      - ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDB4rJv3i6pgeuv62kmXWhscrteOnkEtU0vV3f12O+Ap
description: Default LXD profile
devices:
  eth0:
    name: eth0
    nictype: bridged
    parent: nonnatbr
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: testprofile
used_by: []

$ lxc launch --profile testprofile ubuntu:18.04 test1

Creating test1
Starting test1

$ lxc launch --profile testprofile ubuntu:18.04 test2

Creating test2
Starting test2

$ lxc list

+---------------+---------+-----------------------+-----------------------------------------------+------------+-----------+
|     NAME      |  STATE  |         IPV4          |                     IPV6                      |    TYPE    | SNAPSHOTS |
+---------------+---------+-----------------------+-----------------------------------------------+------------+-----------+
| test1         | RUNNING | 10.136.201.157 (eth0) | fd42:ece1:b474:82be:216:3eff:fe78:854f (eth0) | PERSISTENT | 0         |
+---------------+---------+-----------------------+-----------------------------------------------+------------+-----------+
| test2         | RUNNING | 10.136.201.158 (eth0) | fd42:ece1:b474:82be:216:3eff:fe96:d195 (eth0) | PERSISTENT | 0         |
+---------------+---------+-----------------------+-----------------------------------------------+------------+-----------+

$ ssh [email protected]                                                                                                   

ubuntu@test1:~$ ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
^C
--- 1.1.1.1 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1008ms

ubuntu@test1:~$ ping 10.136.201.158
PING 10.136.201.158 (10.136.201.158) 56(84) bytes of data.
64 bytes from 10.136.201.158: icmp_seq=1 ttl=64 time=0.255 ms
64 bytes from 10.136.201.158: icmp_seq=2 ttl=64 time=0.107 ms
^C
--- 10.136.201.158 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1028ms
rtt min/avg/max/mdev = 0.107/0.181/0.255/0.074 ms

相关内容