Trying to setup an LXC container network configuration? We can help you with it.
The network plays an important role in containers. We can configure the network as per our infrastructure.
At Bobcares, we often get requests to configure a network in LXC as part of our Server Management Services.
Today, let’s get into the details and see how our Support Engineers configure the network.
More about LXC Network configuration
LXC creates its own device which is managed by the lxc-net service.
lxc-net is a part of LXC. It allows us to setup a bridge in the container with ipv4.
There are multiple methods to setup a network. And multiple ways to configure it.
Let’s discuss how to configure an additional network interface in LXC. Also, let’s discuss setting up a bridge using lxc-net.
Add an additional network interface in LXC
Recently one of our customers contacted us to add a network in LXC. Let’s see how our Support Engineers add a network interface in LXC.
Initially, we add the entry in the containers configuration file. The file is located at /var/lib/lxc/CONTAINER-NAME/config
The location can change based on the configuration.
When we open the file, already a network interface detail will be present. We duplicate the entry or add the below details.
lxc.network.mtu = 1500
lxc.network.type = XXXX
lxc.network.name = ethx
lxc.network.link = XXX
lxc.network.ipv4 = 1xx.2x.1xx.2x
lxc.network.flags = up
Also, we make sure the details we enter in the second interface are right. After that we save the file.
Then we restart the network service.
Now on checking, two interfaces will be displayed.
Configure a bridge in LXC
By default, the bridge interface is not configured. Let’s discuss how our Support Engineers configure a bridge interface.
We open the file /etc/lxc/default.conf. The file location can change according to the configuration.
lxc.network.type = xxxx
lxc.network.link = Bridge name
lxc.network.flags = up
lxc.network.hwaddr = xx:xx:xx:xx:xx:xx
Now we create the /etc/default/lxc-net file and add the line
USE_LXC_BRIDGE="true"
Then we restart the lxc-net service using the command
systemctl restart lxc-net
Now we check the working using the command
ip -4 -o a show lxcbr0 bridge_name
Finally, we have now configured the bridge for LXC containers.
A common error when configuring network in LXC
Recently one of the customers approached us saying the network configuration fails.
One of the common mistakes is a typo error. On analyzing the configuration, we found that the network configuration in the configuration file was incorrect.
Thus our Support Engineers resolved the error by making the necessary changes in the configuration file.
[Need assistance to set up a network in LXC containers? We’ll help you.]
Conclusion
In short, we’ve discussed the LXC container network configuration. Also, we’ve discussed how our Support Engineers configure and add two network interfaces in LXC, bridge in LXC and common mistakes when configuring a network.
0 Comments