我想要一个可预测的网桥与 LXD 一起使用,这样我就可以在该网桥上运行 squid 作为代理来处理所有流量,并添加 ebtables 规则来过滤流量。
所以我编辑了 /etc/network/interfaces 来添加网桥:
auto cdplxdbr0
iface cdplxdbr0 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 127.0.0.1
bridge_ports enp0s10f1
#auto enp0s10f1
iface enp0s10f1 inet manual
重新启动时,接口正确出现,如下所示
cdplxdbr0 Link encap:Ethernet HWaddr 00:15:5d:7a:3f:01
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::215:5dff:fe7a:3f01/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1042261 errors:0 dropped:0 overruns:0 frame:0
TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:103937980 (103.9 MB) TX bytes:738 (738.0 B)
enp0s10f0 Link encap:Ethernet HWaddr 00:15:5d:7a:3f:00
inet addr:10.91.128.126 Bcast:10.91.131.255 Mask:255.255.252.0
inet6 addr: fe80::215:5dff:fe7a:3f00/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:445061 errors:0 dropped:417 overruns:0 frame:0
TX packets:11474 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:91505926 (91.5 MB) TX bytes:2185293 (2.1 MB)
enp0s10f1 Link encap:Ethernet HWaddr 00:15:5d:7a:3f:01
inet addr:10.91.130.127 Bcast:10.91.131.255 Mask:255.255.252.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1541116 errors:0 dropped:0 overruns:0 frame:0
TX packets:990 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:237056633 (237.0 MB) TX bytes:43292 (43.2 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:5921 errors:0 dropped:0 overruns:0 frame:0
TX packets:5921 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:490582 (490.5 KB) TX bytes:490582 (490.5 KB)
接下来,我将设备 eth0 添加到默认的 LXD 配置文件中,这也正确显示:
$ lxc profile show default
name: default
config: {}
description: Default LXD profile
devices:
eth0:
name: eth0
nictype: bridged
parent: cdplxdbr0
type: nic
usedby: []
检查配置时:
$ lxc network show cdplxdbr0
name: cdplxdbr0
config: {}
managed: false
type: bridge
usedby: []
我希望为设备分配一个静态 IP 地址并为 IPv4 使用 NAT,所以我做了这样的事情:
$ cat /cdp/endor/scripts/lxd/lxdbr1.yml | lxc network edit cdplxdbr0
error: not found
其中 lxdbr1.yml 的内容是:
name: cdplxdbr0
config:
ipv4.address: 192.168.1.1/24
ipv4.nat: true
ipv6.address: none
managed: false
type: bridge
我不确定这个配置有什么问题。在使用默认配置的网桥时,LXD 本身所做的似乎是正确的。