Differences between revisions 2 and 3
Revision 2 as of 2011-12-12 22:58:15
Size: 1833
Editor: GeoffSimmons
Comment: Add DefaultTemplate header.
Revision 3 as of 2011-12-13 20:10:00
Size: 2815
Editor: ?MarcusOsdoba
Comment: re-complete hostdevice-as-bridge example
Deletions are marked like this. Additions are marked like this.
Line 10: Line 10:
 * the container's {{{veth}}} virtual ethernet interface can share the network link on the physical interface of the host (eth0).  * the container's {{{veth}}} virtual ethernet interface can share the network link on the physical interface of the host (eth0). So the container will reside on the same ethernet segment and talks to the same dhcp server as the host does.
Line 26: Line 26:
# address <host IP here, e.g. 10.1.1.2> # address <host IP here, e.g. 192.168.1.20>
Line 28: Line 28:
# network <network IP here, e.g. 10.1.1.0>
# broadcast <broadcast IP here, e.g. 10.1.1.255>
# gateway <gateway IP address here, e.g. 10.1.1.1>
# network <network IP here, e.g. 192.168.1.0>
# broadcast <broadcast IP here, e.g. 192.168.1.255>
# gateway <gateway IP address here, e.g. 192.168.1.1>
Line 32: Line 32:
# dns-nameservers <name server IP address here, e.g. 10.1.1.1> # dns-nameservers <name server IP address here, e.g. 192.168.1.1>
Line 37: Line 37:
 * TODO: provide a sample of the network section in the containers config  * The network section in the container's config may look like this
{{{
## Network
lxc.utsname = containershostname
lxc.network.type = veth
lxc.network.flags = up

# that's the interface defined above in hosts' interfaces file
lxc.network.link = br0

# name of network device inside the container,
# defaults to eth0, you could choose a name freely
lxc.network.name = lxcnet0

lxc.network.hwaddr = 00:FF:AA:00:00:01

# the ip may be set to 0.0.0.0/24 or skip this line
# if you like to use a dhcp client inside the container
lxc.network.ipv4 = 192.168.1.110/24

}}}

 * Completing the example above, the containers {{{/etc/network/interfaces}}} may look like this
{{{
auto lxcnet0
iface lxcnet0 inet dhcp
#iface lxcnet0 inet static
# address <container IP here, e.g. 192.168.1.110>
# all other settings like those for the host
}}}
Line 41: Line 70:
 * the container's {{{veth}}} virtual ethernet interface accesses the network via the bridge device created on the host.  * the container's {{{veth}}} virtual ethernet interface accesses the network via the bridge device created on the host. The container is not visable from outside the host by default.

Translation(s): none


Please find alternative network setups for containers on the LXC mainpage.

In case of bridged or routed network provided by the host, here is an example.

Host device as bridge

  • persisted in host's /etc/network/interfaces

  • the container's veth virtual ethernet interface can share the network link on the physical interface of the host (eth0). So the container will reside on the same ethernet segment and talks to the same dhcp server as the host does.

# The primary network interface
#allow-hotplug eth0
#iface eth0 inet dhcp

auto br0
iface br0 inet dhcp
        bridge_ports eth0
        bridge_fd 0
        bridge_maxwait 0

# uncomment the below and comment the above for static ip setup on the host
#iface br0 inet static
#       bridge_ports eth0
#       bridge_fd 0
#       address <host IP here, e.g. 192.168.1.20>
#       netmask 255.255.255.0
#       network <network IP here, e.g. 192.168.1.0>
#       broadcast <broadcast IP here, e.g. 192.168.1.255>
#       gateway <gateway IP address here, e.g. 192.168.1.1>
#       # dns-* options are implemented by the resolvconf package, if installed
#       dns-nameservers <name server IP address here, e.g. 192.168.1.1>
#       dns-search your.search.domain.here
  • The network section in the container's config may look like this

## Network
lxc.utsname = containershostname
lxc.network.type = veth
lxc.network.flags = up

# that's the interface defined above in hosts' interfaces file
lxc.network.link = br0

# name of network device inside the container,
# defaults to eth0, you could choose a name freely
lxc.network.name = lxcnet0 

lxc.network.hwaddr = 00:FF:AA:00:00:01

# the ip may be set to 0.0.0.0/24 or skip this line
# if you like to use a dhcp client inside the container
lxc.network.ipv4 = 192.168.1.110/24
  • Completing the example above, the containers /etc/network/interfaces may look like this

auto lxcnet0
iface lxcnet0 inet dhcp
#iface lxcnet0 inet static
#       address <container IP here, e.g. 192.168.1.110>
#       all other settings like those for the host

Additonal bridge device instead of changing a host device to br0

  • setup manually with brctl
  • the container's veth virtual ethernet interface accesses the network via the bridge device created on the host. The container is not visable from outside the host by default.

natted

  • TODO

routed

  • TODO

References :