1

I created a bridge using the following guide on my Ubuntu 14.04 server.

http://www.linux-kvm.org/page/Networking#Public_Bridge

Now I would like to assign a static public IP to my virtual machine. How do I do it?

  • A static ***public*** IP? Ummmm.... you'd have to contact your ISP and ask them to give you a static IP. – You'reAGitForNotUsingGit Sep 09 '16 at 14:57
  • If you meant a static *local* IP, then that's a different story. – You'reAGitForNotUsingGit Sep 09 '16 at 14:58
  • Hey @AndroidDev. I have a static IP which is already leased and ready to be used. I tried manually configuring in the /etc/network/interfaces file. But it doesn't work. – Mohit Vellanki Sep 09 '16 at 14:59
  • see step 3 [here](http://askubuntu.com/questions/638162/kvm-network-bridge-to-assign-static-ip/638269#638269) – Doug Smythies Sep 09 '16 at 14:59
  • Hey @DougSmythies. I tried the same thing earlier. It doesn't seem to work. Thank you – Mohit Vellanki Sep 09 '16 at 15:00
  • Yes, I was writing, and didn't see your comment until after. Read the rest of the link I gave, any help with that? Specifically, did you tell your VM to use the bridge? (Step 2). – Doug Smythies Sep 09 '16 at 15:04
  • @DougSmythies I followed the step 2 also. But do I need to change the mac address as well? The br0 in my case has a different HWaddr when checked in ifconfig. – Mohit Vellanki Sep 09 '16 at 15:10
  • Yes, of course. You need to use your own VM's MAC address, what I listed was just an example taken from one of my VM's. This part has nothing to do with the MAC address of the bridge. – Doug Smythies Sep 09 '16 at 15:36
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/45160/discussion-between-mohit-vellanki-and-doug-smythies). – Mohit Vellanki Sep 09 '16 at 15:38

1 Answers1

0

Editors there is a different question, but fundamentally the same problem I answered here. New to this so not sure if/how to merge - Ping to LXC container

In addition to the bridge, you need ensure you have a dedicated virtual network card on the Linux Container which will then be assigned the IP address on your hosts machine's 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
  • 5