From 86c541373401817437059dc11174e341ff41518b Mon Sep 17 00:00:00 2001 From: darksun Date: Wed, 31 Jan 2018 13:13:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E9=A2=98:=20How=20to=20make=20your=20?= =?UTF-8?q?LXD=20containers=20get=20IP=20addresses=20from=20your=20LAN=20u?= =?UTF-8?q?sing=20a=20bridge?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... addresses from your LAN using a bridge.md | 173 ++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 sources/tech/20180129 How to make your LXD containers get IP addresses from your LAN using a bridge.md diff --git a/sources/tech/20180129 How to make your LXD containers get IP addresses from your LAN using a bridge.md b/sources/tech/20180129 How to make your LXD containers get IP addresses from your LAN using a bridge.md new file mode 100644 index 0000000000..6f26f182b8 --- /dev/null +++ b/sources/tech/20180129 How to make your LXD containers get IP addresses from your LAN using a bridge.md @@ -0,0 +1,173 @@ +How to make your LXD containers get IP addresses from your LAN using a bridge +====== +**Background** : LXD is a hypervisor that manages machine containers on Linux distributions. You install LXD on your Linux distribution and then you can launch machine containers into your distribution running all sort of (other) Linux distributions. + +In the previous post, we saw how to get our LXD container to receive an IP address from the local network (instead of getting the default private IP address), using **macvlan**. + +In this post, we are going to see how to use a **bridge** to make our containers get an IP address from the local network. Specifically, we are going to see how to do this using NetworkManager. If you have several public IP addresses, you can use this method (or the other with the **macvlan** ) in order to expose your LXD containers directly to the Internet. + +### Creating the bridge with NetworkManager + +See this post [How to configure a Linux bridge with Network Manager on Ubuntu][1] on how to create the bridge with NetworkManager. It explains that you + + 1. Use **NetworkManager** to **Add a New Connection** , a **Bridge**. + 2. When configuring the **Bridge** , you specify the real network connection (the device, like **eth0** or **enp3s12** ) that will be **the slave of the bridge**. You can verify the device of the network connection if you run **ip route list 0.0.0.0/0**. + 3. Then, you can remove the old network connection and just keep the slave. The slave device ( **bridge0** ) will now be the device that gets you your LAN IP address. + + + +At this point you would have again network connectivity. Here is the new device, **bridge0**. +``` +$ ifconfig bridge0 +bridge0 Link encap:Ethernet HWaddr 00:e0:4b:e0:a8:c2 + inet addr:192.168.1.64 Bcast:192.168.1.255 Mask:255.255.255.0 + inet6 addr: fe80::d3ca:7a11:f34:fc76/64 Scope:Link + UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 + RX packets:9143 errors:0 dropped:0 overruns:0 frame:0 + TX packets:7711 errors:0 dropped:0 overruns:0 carrier:0 + collisions:0 txqueuelen:1000 + RX bytes:7982653 (7.9 MB) TX bytes:1056263 (1.0 MB) +``` + +### Creating a new profile in LXD for bridge networking + +In LXD, there is a default profile and then you can create additional profile that either are independent from the default (like in the **macvlan** post), or can be chained with the default profile. Now we see the latter. + +First, create a new and empty LXD profile, called **bridgeprofile**. +``` +$ lxc create profile bridgeprofile +``` + +Here is the fragment to add to the new profile. The **eth0** is the interface name in the container, so for the Ubuntu containers it does not change. Then, **bridge0** is the interface that was created by NetworkManager. If you created that bridge by some other way, add here the appropriate interface name. The **EOF** at the end is just a marker when we copy and past to the profile. +``` +description: Bridged networking LXD profile +devices: + eth0: + name: eth0 + nictype: bridged + parent: bridge0 + type: nic +**EOF** +``` + +Paste the fragment to the new profile. +``` +$ cat <