LinuxCommandLibrary

lxc-network

Manage LXC virtual network devices

TLDR

List all available networks

$ lxc network list
copy

Show the configuration of a specific network
$ lxc network show [network_name]
copy

Add a running instance to a specific network
$ lxc network attach [network_name] [container_name]
copy

Create a new managed network
$ lxc network create [network_name]
copy

Set a bridge interface of a specific network
$ lxc network set [network_name] bridge.external_interfaces [eth0]
copy

Disable NAT for a specific network
$ lxc network set [network_name] ipv[4].nat false
copy

SYNOPSIS

lxc-network {start|stop|restart|create|destroy} [options]

PARAMETERS

start
    Brings up a network bridge.

stop
    Brings down a network bridge.

restart
    Restarts a network bridge (stop then start).

create
    Creates a new network bridge.

destroy
    Deletes a network bridge. WARNING: can cause network issues if containers are using the bridge.


    The name of the network bridge to operate on (e.g., lxcbr0, mybridge).

--address
    Specifies the IP address for the bridge (used with create).

--netmask
    Specifies the netmask for the bridge (used with create).

--dhcp-range
    Specifies the DHCP range for the bridge (used with create).

--with-dhcpns
    Creates a private network namespace for DHCP (used with create).

DESCRIPTION

The `lxc-network` command provides a central interface for managing network configurations within LXC (Linux Containers). It allows users to create, modify, and delete network bridges used by LXC containers. This command greatly simplifies the process of setting up networking for containers by abstracting away the complexities of manually configuring network interfaces and bridges.

The main purpose is to manage bridges used by LXC. Bridges facilitate network communication between containers and the host system, as well as between containers themselves. `lxc-network` enables creation of bridges, defines IP addresses, DHCP ranges, and other critical network settings. By using this tool, users can ensure consistent and reproducible network configurations for their containers, making container deployments and management more efficient and reliable. It supports creating default lxcbr0, and new custom bridge networks for advanced network isolation and separation.

CAVEATS

Deleting a bridge that is in use by containers can cause network connectivity issues for those containers.

Ensure appropriate network configurations are applied when creating new bridges, considering IP address ranges, and potential conflicts.

Some features might depend on the available kernel modules and networking tools.

EXAMPLES

Create a network bridge named `mybridge`:
`lxc-network create mybridge --address 10.0.3.1 --netmask 255.255.255.0 --dhcp-range 10.0.3.2,10.0.3.254`

Start the bridge `mybridge`:
`lxc-network start mybridge`

Stop the bridge `mybridge`:
`lxc-network stop mybridge`

Destroy the bridge `mybridge`:
`lxc-network destroy mybridge`

NETWORK CONFIGURATION FILES

Bridge configuration can be configured in /etc/lxc/default.conf or /etc/default/lxc.
The `lxc-net` service utilizes these config files for creating the default bridge lxcbr0 during the system boot. This service must be enabled.

HISTORY

The `lxc-network` command was developed as part of the LXC project to simplify network management for containers. It evolved alongside LXC itself, becoming an essential tool for creating and managing network bridges in a containerized environment. It originally started from shell scripts, with the aim of removing complexity from network bridge creation.

SEE ALSO

lxc(1), ip(8), brctl(8)

Copied to clipboard