2

Please, I try to do ping 10.0.3.8 (ip of LXC container) from VMB but it didn’t work ! Have you an idea please ?

Here is an explanation of what I want do: (red arrow)

The blue arrows means that the ping works correctly. The red arrow means that there is a problem: i try from VMB (192.168.1.7) to ping 10.0.3.8 i have this message blocked : ping 10.0.3.8 PING 10.0.3.8 (10.0.3.8) 56(84) bytes of data. --- 10.0.3.8 ping statistics --- 68 packets transmitted, 0 received, 100% packet loss, time 67214ms –

enter image description here Thanks a lot.

Best Regards.

researcher
  • 230
  • 2
  • 3
  • 12

1 Answers1

2

When you create a Linux Container it exists within its own network space. That is why the IP addresses look so different. Your Virtual Machines have 192.168.1.x while your Linux Containers are assigned 10.0.3.x.

One way of solving this is to create a dedicated virtual network card on the Linux Container which will then pull an address from the 192.168.1.x network.

Below are the core instructions, but detailed steps and background come from this Bonsai Framework article.

Create a Permanent macvlan on the Host

Add to the bottom of the /etc/network/interfaces file of the host,

# Creates a macvlan interface called macvlan0 without an IP address  
iface mvlan0 inet manual  
   pre-up ip link add mvlan0 link eth0 address 8a:38:2a:cc:d7:aa type macvlan mode bridge  
   post-down ip link del macvlan0  
auto mvlan0  

Reboot your system to have the change take effect. You will notice a mvlan0 now when viewing your network devices with ifconfig -a.

Connect Container to macvlan on Host by modifying the config file located in /var/lib/lxc/[container]/config.

The entries to add for your new network card,

# macvlan for external IP  
lxc.network.type = macvlan   
lxc.network.macvlan.mode = bridge  
lxc.network.flags = up  
lxc.network.link = mvlan0  
lxc.network.hwaddr = 00:16:3e:8d:4f:51  
lxc.network.name = eth0  

For the hwaddr, generate a unique locally administered unicast MAC Address via a free website like helion.org.

Finally, adjust the interfaces file within the container to bind via static or if you prefer use dynamic.

In my case, I adjust my home router so that 192.168.0.1 to 192.168.0.20 are not dynamically assigned and use static in my LXC.

So I modify my containers interfaces file as follows,

auto eth0  
iface eth0 inet static  
address 192.168.0.12  
gateway 192.168.0.1  
netmask 255.255.255.0  

auto eth1  
iface eth1 inet dhcp  

Restart your Linux container.

phamti
  • 49