LXC network forward ports (yaml)

I got to my container (target_address) connected using nc -v 5.35.6.44 1234 from the outside world using one of my spare ip addresses (the listen_address)

description: ""
config:
  target_address: 10.103.26.196
ports: []
listen_address: 5.35.6.44
location: none

I just nc -l 1234 from inside the container on the server and I could send messages from my laptop.

But I can’t figure out how to enable a bunch of ports (instead of target_address)

description: ""
config: {}
ports: []
listen_port: 1234,5678
target_port: 1234,5678
listen_address: 5.35.6.44
location: none

I’ve tried different combinations

description: ""
config: {}
ports:
  listen_port: 1234,5678
  target_port: 1234,5678
listen_address: 5.35.6.44
location: none

I get lots of yaml errors when ever I guess.

Config parsing error: yaml: unmarshal errors:
  line 24: cannot unmarshal !!int `1234` into api.NetworkForwardPort
  line 24: cannot unmarshal !!int `5678` into api.NetworkForwardPort
Press enter to open the editor again or ctrl+c to abort change

Config parsing error: yaml: unmarshal errors:
  line 24: cannot unmarshal !!str `1234,5678` into []api.NetworkForwardPort
Press enter to open the editor again or ctrl+c to abort change

Config parsing error: yaml: unmarshal errors:
  line 24: field port not found in type api.NetworkForward
Press enter to open the editor again or ctrl+c to abort change

Config parsing error: yaml: unmarshal errors:
  line 24: field listen_port not found in type api.NetworkForward
  line 25: field target_port not found in type api.NetworkForward
Press enter to open the editor again or ctrl+c to abort change

Config parsing error: yaml: unmarshal errors:
  line 25: cannot unmarshal !!map into []api.NetworkForwardPort
Press enter to open the editor again or ctrl+c to abort change

Config parsing error: yaml: unmarshal errors:
  line 24: field port not found in type api.NetworkForward
Press enter to open the editor again or ctrl+c to abort change

Config parsing error: Failed updating forward: Invalid option "target_port"
Press enter to open the editor again or ctrl+c to abort change

The docs show listen_port/target_port are things I can use but they don’t want to work: How to configure network forwards - LXD documentation

how do I:
A) do it properly?
B) learn the lxc yaml?

Hi @ben,
You can check that link, @stgraber describes the network forwarding concept.
Regards.

https://www.youtube.com/watch?v=B-Uzo9WldMs&t=314s

You can use the lxc network forward port command to add/remove port definitions without needing to edit the yaml, then after using that command you can see/edit the yaml generated using the lxc network forward edit command.

Also, although the API takes JSON rather than YAML, you can get a good idea of the structure required from our API docs, e.g.

1 Like