I’m trying to do the same thing here, and I cannot figure out how to make the container to communicate with the outside world. I have the same need: only a single IPv4 public ip address assigned to the host interface, and I do not want to setup a new host interface (bridge) for connecting the container to the outside world.
Host OS: Alpine Linux 3.15 running lxc-4.0.11
Guest OS: Alpine Linux 3.15
First it seems that $LXC_NET_PEER env var isn’t set, even though I’ve added lxc.hook.version = 1:
lxc-start test-packer 20220120094058.398 INFO conf - conf.c:run_script_argv:337 - Executing script "/usr/share/lxc/hooks/lxc-router-up" for container "test-packer", config section "net"
lxc-start test-packer 20220120094058.400 DEBUG conf - conf.c:run_buffer:310 - Script exec /usr/share/lxc/hooks/lxc-router-up test-packer net up veth bond0.104 vethrN8BT4 produced output: LXC_NET_PEER not set
lxc-start test-packer 20220120094058.400 ERROR conf - conf.c:run_buffer:321 - Script exited with status 1
This is not a big deal, I’ve performed manually the lxc-router-up script changes on the host (only IPv4 changes, not using IPv6 in the container).
The problem is the container’s network, what should be the network config? After the container started eth0 has no IP address assigned. I’ve manually added the IP specified in the lxc config. Is this supposed to be done manually or automatically? What should look like the container’s routing table? Adding eth0 as default route allows the container to ping the host’s veth IP address, but nothing beyond that of course. The container was created using the download template. Posting all lxc and network configs.
Host:
cat /var/lib/lxc/test-packer/config
# Distribution configuration
lxc.include = /usr/share/lxc/config/common.conf
lxc.arch = linux64
# Container specific configuration
lxc.hook.version = 1 # require for the script
lxc.rootfs.path = dir:/var/lib/lxc/test-packer/rootfs
lxc.uts.name = test-packer
# Network configuration
lxc.net.0.type = veth
lxc.net.0.veth.mode = router
lxc.net.0.link = bond0.104
lxc.net.0.ipv4.address = 192.168.1.10/32
lxc.net.0.ipv4.gateway = 169.254.0.1
lxc.net.0.name = eth0
lxc.net.0.flags = up
lxc.net.0.l2proxy = 1
#lxc.net.0.script.up = /usr/share/lxc/hooks/lxc-router-up
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
link/ether d8:9d:67:6a:bc:a8 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
link/ether d8:9d:67:6a:bc:a8 brd ff:ff:ff:ff:ff:ff permaddr d8:9d:67:6a:bc:ac
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether d8:9d:67:6a:bc:a8 brd ff:ff:ff:ff:ff:ff
inet6 fe80::da9d:67ff:fe6a:bca8/64 scope link
valid_lft forever preferred_lft forever
8: bond0.104@bond0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether d8:9d:67:6a:bc:a8 brd ff:ff:ff:ff:ff:ff
inet <redacted>/27 scope global bond0.104
valid_lft forever preferred_lft forever
inet6 <redacted>/64 scope global
valid_lft forever preferred_lft forever
inet6 fe80::da9d:67ff:fe6a:bca8/64 scope link
valid_lft forever preferred_lft forever
53: vethNMy6RD@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether fe:a6:95:cd:a1:e7 brd ff:ff:ff:ff:ff:ff link-netnsid 15
inet 169.254.0.1/32 scope global vethNMy6RD
valid_lft forever preferred_lft forever
ip r
default via <redacted> dev bond0.104
<redacted>/27 dev bond0.104 proto kernel scope link src <redacted>
192.168.1.10 dev vethNMy6RD scope link
sysctl net.ipv4.conf.bond0.104.forwarding
net.ipv4.conf.bond0/104.forwarding = 1
sysctl net.ipv4.conf.vethNMy6RD.proxy_arp
net.ipv4.conf.vethNMy6RD.proxy_arp = 1
Container:
test-packer:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0@if53: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP qlen 1000
link/ether 3a:2d:4f:d5:ca:fa brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/32 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::382d:4fff:fed5:cafa/64 scope link
valid_lft forever preferred_lft forever
test-packer:/# ip r
test-packer:/#