首先,我对网络不太有经验。我的系统中有三个网卡。
我的 netplan 设置:
network:
ethernets:
enp5s0:
dhcp4: true
enp3s0:
dhcp4: false
addresses: [X.X.X.251/32]
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
routes:
- to: 0.0.0.0/0
via: X.X.X.249
on-link: true
enp2s0:
dhcp4: false
addresses: [X.X.X.252/32]
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
routes:
- to: 0.0.0.0/0
via: X.X.X.249
version: 2
路由表
default via X.X.X.249 dev enp3s0 proto static onlink
default via 192.168.10.1 dev enp5s0 proto dhcp src 192.168.10.99 metric 100
10.0.0.0/16 dev lxdbr0 proto kernel scope link src 10.0.0.1 linkdown
192.168.10.0/23 dev enp5s0 proto kernel scope link src 192.168.10.99
192.168.10.1 dev enp5s0 proto dhcp scope link src 192.168.10.99 metric 100
enp5s0连接到本地路由器。enp3s0是我默认想要通过其路由的公共 IP。
enp2s0是我想要设置 IP XXX252 并希望将其与特定的 lxc 容器连接起来的那个。
如果我想通过 ssh 进入 XXX252 或其他流量,我想进入 lxc 容器。
我怎样才能在这里做到这一点?
$ lxc network list
+--------+----------+---------+-------------+---------+
| NAME | TYPE | MANAGED | DESCRIPTION | USED BY |
+--------+----------+---------+-------------+---------+
| enp2s0 | physical | NO | | 0 |
+--------+----------+---------+-------------+---------+
| enp3s0 | physical | NO | | 0 |
+--------+----------+---------+-------------+---------+
| enp5s0 | physical | NO | | 0 |
+--------+----------+---------+-------------+---------+
| lxdbr0 | bridge | YES | | 1 |
+--------+----------+---------+-------------+---------+
如果我把它附到容器上,
$ lxc network attach enp2s0 container eth0
$ lxc list
+--------+---------+-----------------------+------+------------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+--------+---------+-----------------------+------+------------+-----------+
| container | RUNNING | 192.168.11.241 (eth0) | | PERSISTENT | 0 |
+--------+---------+-----------------------+------+------------+-----------+
它不起作用,而是通过本地网络进行路由。
请指导我我应该在哪里以及进行什么更改?
答案1
在设备上禁用静态地址和 DHCP 后为容器分配静态地址的示例。
lxc stop container
lxc config device add contianer eth0 nic nictype=routed parent= enp2s0 ipv4.address= X.X.X.252
lxc start container
然后一旦它开始了..
lxc exec container -- ip a show dev eth0
2: eth0@if27: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet X.X.X.252/32 brd 255.255.255.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 blah..
然后您需要设置默认的正确的默认路由。