8 First you should have root privileges:
10 .. code-block:: console
14 Then install packages for containers such as lxc:
16 .. code-block:: console
18 # apt-get install bridge-utils lxc
20 As quoted from the `lxc.conf manpage <https://linuxcontainers.org/it/lxc/manpages/man5/lxc.conf.5.html>`_, "container configuration is held in the config stored in the container's directory.
21 A basic configuration is generated at container creation time with the default's recommended for the chosen template as well as extra default keys coming from the default.conf file."
23 "That *default.conf* file is either located at /etc/lxc/default.conf or for unprivileged containers at ~/.config/lxc/default.conf."
25 Since we want to ping between two containers, we'll need to **add to this file**.
27 Look at the contents of *default.conf*, which should initially look like this:
29 .. code-block:: console
31 # cat /etc/lxc/default.conf
32 lxc.network.type = veth
33 lxc.network.link = lxcbr0
34 lxc.network.flags = up
35 lxc.network.hwaddr = 00:16:3e:xx:xx:xx
37 As you can see, by default there is one veth interface.
39 Now you will *append to this file* so that each container you create will have an interface for a Linux bridge and an unconsumed second interface.
41 You can do this by piping *echo* output into *tee*, where each line is separated with a newline character *\\n* as shown below. Alternatively, you can manually add to this file with a text editor such as **vi**, but make sure you have root privileges.
43 .. code-block:: console
45 # echo -e "lxc.network.name = veth0\nlxc.network.type = veth\nlxc.network.name = veth_link1" | sudo tee -a /etc/lxc/default.conf
47 Inspect the contents again to verify the file was indeed modified:
49 .. code-block:: console
51 # cat /etc/lxc/default.conf
52 lxc.network.type = veth
53 lxc.network.link = lxcbr0
54 lxc.network.flags = up
55 lxc.network.hwaddr = 00:16:3e:xx:xx:xx
56 lxc.network.name = veth0
57 lxc.network.type = veth
58 lxc.network.name = veth_link1
61 After this, we're ready to create the containers.
63 Creates an Ubuntu Xenial container named "cone".
65 .. code-block:: console
67 # lxc-create -t download -n cone -- --dist ubuntu --release xenial --arch amd64 --keyserver hkp://p80.pool.sks-keyservers.net:80
70 If successful, you'll get an output similar to this:
72 .. code-block:: console
74 You just created an Ubuntu xenial amd64 (20180625_07:42) container.
76 To enable SSH, run: apt install openssh-server
77 No default root or user password are set by LXC.
80 Make another container "ctwo".
82 .. code-block:: console
84 # lxc-create -t download -n ctwo -- --dist ubuntu --release xenial --arch amd64 --keyserver hkp://p80.pool.sks-keyservers.net:80
87 List your containers to verify they exist:
90 .. code-block:: console
96 Start the first container:
98 .. code-block:: console
100 # lxc-start --name cone
102 And verify its running:
104 .. code-block:: console
107 NAME STATE AUTOSTART GROUPS IPV4 IPV6
114 Here are some `lxc container commands <https://help.ubuntu.com/lts/serverguide/lxc.html.en-GB#lxc-basic-usage>`_ you may find useful:
117 .. code-block:: console
120 sudo lxc-start --name u1 --daemon
121 sudo lxc-info --name u1
122 sudo lxc-stop --name u1
123 sudo lxc-destroy --name u1