LXD Private-Public Network: Difference between revisions
(Created page with "== Creating a Private-Public Network with LXD using Cloud-init == With this method, a private network provides an IP that can be used by another device on the same network, such as 192.168.0.122, while a public network provides an IP that can be used by the same device hosting the container, such as 10.0.1.122. Note that this method has not been tested on wifi. To create a "ppnet" profile for private-public networking, you will need to know the name of your network int...") |
|||
(One intermediate revision by the same user not shown) | |||
Line 16: | Line 16: | ||
Then, view the newly created "ppnet" profile using the following command:<br> | Then, view the newly created "ppnet" profile using the following command:<br> | ||
<code>lxc profile show ppnet</code><br> | <code>lxc profile show ppnet</code><br> | ||
<div class="toccolours mw-collapsible mw-collapsed"> | |||
OutPut:<code>lxc profile show ppnet</code> | |||
<div class="mw-collapsible-content"> | |||
<pre> | |||
config: {} | |||
description: Default LXD profile | |||
devices: | |||
eth0: | |||
name: eth0 | |||
network: lxdbr0 | |||
type: nic | |||
root: | |||
path: / | |||
pool: default | |||
type: disk | |||
name: default | |||
used_by: [] | |||
</pre> | |||
</div> | |||
</div> | |||
<br> | <br> | ||
To configure the "ppnet" profile, edit it using the following command:<br> | To configure the "ppnet" profile, edit it using the following command:<br> | ||
Line 60: | Line 80: | ||
<code>lxc launch ubuntu:20.04 gitea2 --profile ppnet</code><br> | <code>lxc launch ubuntu:20.04 gitea2 --profile ppnet</code><br> | ||
<br> | <br> | ||
==References== | |||
https://blog.simos.info/how-to-add-both-a-private-and-public-network-to-lxd-using-cloud-init/<br> |
Latest revision as of 22:02, 29 March 2023
Creating a Private-Public Network with LXD using Cloud-init
With this method, a private network provides an IP that can be used by another device on the same network, such as 192.168.0.122, while a public network provides an IP that can be used by the same device hosting the container, such as 10.0.1.122. Note that this method has not been tested on wifi.
To create a "ppnet" profile for private-public networking, you will need to know the name of your network interface. You can find this information by running the following command in a terminal:
ip route show default
This will display output similar to:
default via 192.168.0.1 dev enp0s25 proto dhcp metric 100
In this example, the network interface is "enp0s25".
To create a copy of the "default" profile and rename it to "ppnet", run the following command:
lxc profile copy default ppnet
Then, view the newly created "ppnet" profile using the following command:
lxc profile show ppnet
OutPut:lxc profile show ppnet
config: {} description: Default LXD profile devices: eth0: name: eth0 network: lxdbr0 type: nic root: path: / pool: default type: disk name: default used_by: []
To configure the "ppnet" profile, edit it using the following command:
lxc profile edit ppnet
This will open a text editor where you can modify the profile's configuration. Replace the existing configuration with the following:
config: user.network-config: | version: 1 config: - type: physical name: eth0 subnets: - type: dhcp ipv4: true - type: physical name: eth1 subnets: - type: dhcp ipv4: true description: Default LXD profile devices: eth0: name: eth0 parent: lxdbr0 type: nic eth1: name: eth1 nictype: macvlan parent: enp0s25 type: nic root: path: / pool: default type: disk name: ppnet used_by:
Note that you should replace "enp0s25" with the name of your network interface, and adjust the subnets as needed.
Finally, launch a new container with the "ppnet" profile using the following command:
lxc launch ubuntu:20.04 gitea2 --profile ppnet
References
https://blog.simos.info/how-to-add-both-a-private-and-public-network-to-lxd-using-cloud-init/