Configure eth0 on a new container

bdunbar

New Member
Aug 23, 2013
10
0
1
What's the best method to configure eth0 for a new container? It's easy enough to do this via GUI but I really want to do this by script.

So far I can create nodes using pvesh. Assuming I want a container ID of '101'

pvesh create /nodes/prox_host_1/openvz -vmid 101 -hostname bob (redacted for clarity)

I then add eth0 using vzctl

vzctl set 101 --netif_add eth0,,,,vmbr0 --save

Next IP address ...

vzctl set 101--ipadd 10.10.3.101 --nameserver 8.8.8.8


Issues

This doesn't seem to populate the container's /etc/network/interfaces. Am I supposed to write directly to /var/lib/vz/root/101/etc/network/interfaces?

When I tell it to use parameter --gateway I'm told 'unrecognized option'. So how DO I add a gateway?

I feel like I'm so _close_ to getting this thing understood but I'm missing something obvious.
 
seems you use venet interfaces - in this case you only can assign an ip address from the host interfaces subnet;
with the use of veth (bridged mode) you can use networking inside the container as on a regular pc;

i use only veth interfaces with my containers and thats how it looks like in the config:
NETIF="ifname=eth0,bridge=vmbr0,mac=BE:DD:D6:23:19:42,host_ifname=veth121.0,host_mac=00:18:51:D3:67:E8"

in your script you need then generate for each container the /etc/network/interfaces file and copy it into the container
 
Excellent! Thank you.

FWIW my process is
script as outlined in post
script uses predefined IP/gateway/netmask info to build a temp file - /tmp/scriptname.txt
script executes scp to copy /tmp/scriptname.txt > hypervisor:/var/lib/vz/root/${VMID}/etc/network/interfaces
script reboots container using vzctl restart

I've tested this on a node, seems to work clean.

Works, I'm happy, now on to building stuff.

If there is a better / cleaner / elegant way to get this up and running, I'd be interested!
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!