4

I have a question about Network Interfaces in LXC container: In my container,I have by default these interfaces:

ubuntu@u5:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3e:b7:de:91 
          inet addr:10.0.3.138  Bcast:10.0.3.255  Mask:255.255.255.0
          inet6 addr: fe80::216:3eff:feb7:de91/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:56 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7230 (7.2 KB)  TX bytes:3500 (3.5 KB)

       lo        Link encap:Local Loopback 
                 inet addr:127.0.0.1  Mask:255.0.0.0
                 inet6 addr: ::1/128 Scope:Host
                 UP LOOPBACK RUNNING  MTU:65536  Metric:1
                 RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                 collisions:0 txqueuelen:0
                 RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

I'd like to add this new interface:

      auto eth1

      iface eth1 inet static
      address 192.168.1.3
      netmask 255.255.255.0
      network 192.168.1.1
      broadcast 192.168.1.255

So,I have modified this file: /etc/network/interfaces

     # This file describes the network interfaces available on your system
     # and how to activate them. For more information, see interfaces(5).

     # The loopback network interface
     auto lo
     iface lo inet loopback

     auto eth0
     iface eth0 inet dhcp

     auto eth1

     iface eth1 inet static
     address 192.168.1.3
     netmask 255.255.255.0
     network 192.168.1.1
     broadcast 192.168.1.255

I have done reboot but it didn't work ! when I use ifconfig, I cant' find the new interface:

      ubuntu@u5:/etc/network$ ifconfig
      eth0      Link encap:Ethernet  HWaddr 00:16:3e:b7:de:91 
                inet addr:10.0.3.138  Bcast:10.0.3.255  Mask:255.255.255.0
                inet6 addr: fe80::216:3eff:feb7:de91/64 Scope:Link
                UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                RX packets:57 errors:0 dropped:0 overruns:0 frame:0
                TX packets:40 errors:0 dropped:0 overruns:0 carrier:0
                collisions:0 txqueuelen:1000
                RX bytes:7337 (7.3 KB)  TX bytes:3500 (3.5 KB)

       lo        Link encap:Local Loopback 
                 inet addr:127.0.0.1  Mask:255.0.0.0
                 inet6 addr: ::1/128 Scope:Host
                 UP LOOPBACK RUNNING  MTU:65536  Metric:1
                 RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                 collisions:0 txqueuelen:0
                 RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Have you an idea please ?

Nidal
  • 8,956
  • The /etc/network/interfaces doesn't add new virtual interfaces to LXC guests. – Pavel Šimerda Dec 26 '14 at 18:45
  • I have done this test: postimg.org/image/gyz6toinb and postimg.org/image/itorx5q4f – researcher Dec 26 '14 at 20:20
  • Can't speak for others but I'd really appreciate details in the text of the answer. Why should I need to go to external links, especially those with entirely undescriptive names. – Pavel Šimerda Dec 26 '14 at 20:56
  • I set the test example as image, because i can't set all the code in this comment zone. I have modified /etc/lxc/default.conf instead of /etc/network/interfaces but it didn't work :( – researcher Dec 26 '14 at 21:06
  • I have this same question for LXD 3.0. Adding a new network interface to a profile or using lxc config device add doesn't add it to /etc/network/interfaces in the container. However, inside the container, ip address does list the additional device except it has no IP address. – Derek Mahar Jun 01 '18 at 21:17

1 Answers1

6

You need to modify your container configuration file in the host, not the guest (you did not specify whether the conf. files are in /etc/lxc or in ~/.config/lxc), adding a new stanza pertaining to the new interface as follows:

 lxc.network.type = veth
 lxc.network.name = eth0
 lxc.network.link = br0
 lxc.network.ipv4 = 10.0.3.138/24
 lxc.network.flags = up

 lxc.network.type = veth
 lxc.network.link = br1
 lxc.network.ipv4 = 192.168.0.63/24
 lxc.network.name = eth1
 lxc.network.flags = up

where the first stanza is what you presumably already have (give or take a few extra options), and the second stanza replicates what already exists for the a new interface within a different subnet. Then reboot the guest, and you should be good to go.

MariusMatutiae
  • 4,372
  • 1
  • 25
  • 36
  • I have modified this file: /etc/network/interfaces in the host. that's it ? – researcher Dec 25 '14 at 20:24
  • I have alsothis file: root@localhost:/etc/lxc# ls default.conf lxc-usernet root@localhost:/etc/lxc# vim default.conf : lxc.network.type = veth lxc.network.link = lxcbr0 lxc.network.flags = up lxc.network.hwaddr = 00:16:3e:xx:xx:xx – researcher Dec 25 '14 at 20:34
  • I have done this test: http://postimg.org/image/gyz6toinb/ and http://postimg.org/image/itorx5q4f/ – researcher Dec 26 '14 at 09:41