davidfavor
(David Favor)
December 10, 2021, 3:30pm
1
Trying to get a static IP working for an Alpine container running on an Ubuntu Focal machine.
With Ubuntu containers, this is trivial by creating an /etc/netplan config file.
Someone pass along to me the equivalent config file setup for Alpine.
Current networking shows…
net13 # lxc list net13-template-alpine-315
+---------------------------+---------+-----------------------+----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+---------------------------+---------+-----------------------+----------------------------------------------+-----------+-----------+
| net13-template-alpine-315 | RUNNING | 10.130.226.112 (eth0) | fd42:f1b:cbe0:23be:216:3eff:fee6:a01e (eth1) | CONTAINER | 0 |
| | | | fd42:f1b:cbe0:23be:216:3eff:fe4f:1767 (eth0) | | |
+---------------------------+---------+-----------------------+----------------------------------------------+-----------+-----------+
Thanks!
tomp
(Thomas Parrott)
December 10, 2021, 5:41pm
2
Assuming the Alpine instance is using DHCP, you can create a static DHCP allocation using:
lxc config device override <instance> <interface> ipv4.address=n.n.n.n
davidfavor
(David Favor)
December 14, 2021, 4:35pm
3
Never have gotten any lxd config device syntax to work with any container, which is why I use /etc/netplan in Ubuntu containers.
Here’s error…
net13 # lxc config device override net13-template-alpine-315 eth0 ipv4.address=192.99.135.210
Error: The device already exists
davidfavor
(David Favor)
December 14, 2021, 4:36pm
4
Be great if someone can tell me how to do this inside the container, maybe through /etc/network/interfaces syntax.
tomp
(Thomas Parrott)
December 14, 2021, 4:42pm
5
Use set
rather than override
, as you can only override a device coming from a profile, but in this case the device must already be in the instance directly:
lxc config device set net13-template-alpine-315 eth0 ipv4.address=192.99.135.210
davidfavor
(David Favor)
December 14, 2021, 4:49pm
6
net13 # lxc config device set net13-template-alpine-315 eth0 ipv4.address=192.99.135.210
Error: Invalid devices: Device validation failed for "eth0": Device IP address "192.99.135.210" not within network "lxdbr0" subnet
tomp
(Thomas Parrott)
December 14, 2021, 4:51pm
7
Yep, thats probably true
You can’t instruct LXD to create a static DHCP allocation for an IP outside of the parent network’s subnet.
What does lxc network show lxdbr0
show?
davidfavor
(David Favor)
December 14, 2021, 6:16pm
8
config:
ipv4.address: 10.130.226.1/24
ipv4.nat: "true"
ipv6.address: fd42:f1b:cbe0:23be::1/64
ipv6.nat: "true"
description: ""
name: lxdbr0
type: bridge
used_by:
- /1.0/instances/net13-david-favor
- /1.0/instances/net13-david-favor
- /1.0/instances/net13-david-favor-fixdeliver
- /1.0/instances/net13-david-favor-fixdeliver
- /1.0/instances/net13-dns-ns12-focal
- /1.0/instances/net13-dns-ns12-focal
- /1.0/instances/net13-fixdeliver-mta
- /1.0/instances/net13-fixdeliver-mta
- /1.0/instances/net13-hivelocity
- /1.0/instances/net13-hivelocity
- /1.0/instances/net13-jasites-author-projects
- /1.0/instances/net13-jasites-author-projects
- /1.0/instances/net13-jasites-health-projects
- /1.0/instances/net13-jasites-health-projects
- /1.0/instances/net13-joymta-v1
- /1.0/instances/net13-joymta-v1
- /1.0/instances/net13-joymta-v2
- /1.0/instances/net13-joymta-v2
- /1.0/instances/net13-template-alpine-315
- /1.0/instances/net13-template-alpine-315
- /1.0/instances/net13-template-focal
- /1.0/instances/net13-template-focal
- /1.0/instances/net13-website-tester
- /1.0/instances/net13-website-tester
- /1.0/profiles/default
managed: true
status: Created
locations:
- none
davidfavor
(David Favor)
December 14, 2021, 6:17pm
9
Also here’s the routing table…
net13 # route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 54.39.133.254 0.0.0.0 UG 100 0 0 eno1
10.130.226.0 0.0.0.0 255.255.255.0 U 0 0 0 lxdbr0
54.39.133.0 0.0.0.0 255.255.255.0 U 0 0 0 eno1
54.39.133.254 0.0.0.0 255.255.255.255 UH 100 0 0 eno1
142.44.168.80 0.0.0.0 255.255.255.240 U 0 0 0 lxdbr0
192.99.135.208 0.0.0.0 255.255.255.240 U 0 0 0 lxdbr0
tomp
(Thomas Parrott)
December 14, 2021, 6:28pm
10
192.99.135.210 is not in the lxdbr0 subnet 10.130.226.0/24
davidfavor
(David Favor)
December 14, 2021, 6:30pm
11
Correct.
What’s required is 192.99.135.210 being set as the container’s static IP.
This is trivial with Ubuntu, just create an /etc/netplan file.
What I’m asking about is a similar trivial config for Alpine containers, which run old V1 networking, so /etc/network/interfaces is likely file to modify.
davidfavor
(David Favor)
December 15, 2021, 5:51pm
12
The following /etc/network/interfaces seems to work.
Someone let me know if this is the correct approach or there’s a better way.
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
hostname $(hostname)
auto eth1
iface eth1 inet static
address 192.99.135.210
netmask 255.255.255.0
gateway 10.130.226.1
Thanks!
davidfavor
(David Favor)
March 28, 2024, 1:38pm
13
Best fix seems to now be changing /etc/network/interfaces to the following…
auto eth0
iface eth0 inet dhcp
auto eth0
iface eth0 inet static
address 198.50.215.210
netmask 255.255.255.0
For this to work host level routing must match LXD standard practices, so…
ip -4 route add 198.50.215.208/28 dev lxdbr0
So route + IP match…