DHCP for VM

anhnv

Active Member
Jan 31, 2018
7
0
41
35
Hello,

I just installed Promox with latest version. Current i have 1 IP managerment and 1 subnet.
I have one server with 4 port. And i want to config like bellow

Port 1: using static IP
Port 4: for VM with dhcp in my range (example 10.10.0.0/24, gateway 10.10.0.254)

How can i config for this ?
 
You can make it easiest by editing your / etc / network / interfaces to edit your subnet on vmbr0 then create a network script and enter in the network script all the ip addresses you want to use have done that myself 10 minutes ago ^ ^
 
  • Like
Reactions: anhnv
My /etc/network/interfaces:


auto lo
iface lo inet loopback
iface lo inet6 loopback

# device: eth0
auto eth0
iface eth0 inet static
address 138.201.x.x
netmask 255.255.255.248
gateway 138.201.x.1
# default route to access subnet
up route add -net 138.201.x.0 netmask 255.255.255.248 gw 138.201.x.1 eth0

iface eth0 inet6 static
address 2a01:4f8:171:xxx::2
netmask 128
gateway fe80::1

auto vmbr0
iface vmbr0 inet static
address 138.201.x.x
netmask 255.255.255.248
bridge_ports none
bridge_stp off
bridge_fd 0
pre-up brctl addbr vmbr0
up /root/netzwerksetup.sh up
down /root/netzwerksetup.sh down
#
iface vmbr0 inet6 static
address 2a01:4f8:171:xxxx::2
netmask 64


By address 138.201.x.x
and
netmask 255.255.255.248
must stand the previous values.
Gateway dito.
The vmbr0 becomes the bridge to which all IPs are routed, which you want to use in the Proxmox VMs / containers.




The netzwerksetup.sh Script is used to set the routes. This keeps the network / interfaces file clear. Do not forget to make chmod 750 on the script:

#!/bin/bash

CMD=$1

#
#Enter all the IPs you want to route here. Each line has a (!) IP address. It does not matter if single IP or any IP from the subnet.
IPS="138.201.xxx.xxx
138.201.xxx.xxx
138.201.xxx.xxx"

if [ -z $CMD ]
then
echo "No command given"
exit 1
fi

date >> /var/log/netzwerksetup.log
echo "$CMD" >> /var/log/netzwerksetup.log

if [ $CMD == 'up' ]
then
while read -r line; do
echo $line >> /var/log/netzwerksetup.log
/sbin/ip route add $line/32 dev vmbr0 2>&1 >> /var/log/netzwerksetup.log
done <<< "$IPS"
echo 1 > /proc/sys/net/ipv4/ip_forward
fi

if [ $CMD == 'down' ]
then
while read -r line; do
echo $line >> /var/log/netzwerksetup.log
/sbin/ip route del $line/32 dev vmbr0 2>&1 >> /var/log/netzwerksetup.log
done <<< "$IPS"
fi
 
  • Like
Reactions: anhnv
Thanks for reply, i have about more than 200 IP so i'm trying find other best way to do this :(
 
and look like your way is not DHCP, DHCP that mean while you have install VM, you choose DHCP network, then you have once IP
 

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!