Adding second IP to one of VMs of current PROXMOX on HETZNER

BigWeb

Active Member
Jul 6, 2017
23
2
43
Europe
Hi,
I've read and tried probably all possible combinations which where mentioned here on a forum, and none of them worked for me :(

IPs below are faked , but similar to mine

Hetzner gave me Initial IP :

IP: 181.10.106.125
Gateway: 181.10.106.65
Netmask: 255.255.255.192
Broadcast: 181.10.106.127

and additional (to use on VM, i HAVE NOT REQUESTED separate MAC for this yet, should i ?)
IP: 181.10.106.97
Gateway: 181.10.106.65
Netmask: 255.255.255.192
Broadcast: 181.10.106.127

My current config is quite simple with just main IP being on a list:

Code:
auto lo
iface lo inet loopback

iface ens3 inet manual

iface enp35s0 inet manual

default bridge with first default main external IP
auto vmbr0
iface vmbr0 inet static
    address 181.10.106.125/24
    gateway 181.10.106.65
    bridge-ports enp35s0
    bridge-stp off
    bridge-fd 0

Could anyone please amend it , and add second IP, so i could use it on VM directly ?
Thanks
 
OK, belwo is full tutorial which works fine . in that tutorial i have
one MAIN HOST
one VM with one extra single IP
and as a bonus - extra stup which would allow you adding infinite nuber of VMs , anth they will all have internet , plus with some rules you can route external ports to any of those internal VMs.



Very important !:

add forwarding (uncomment and make sure it is =1) into /etc/sysctl.conf for:

net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1

then reboot

notice what interface you have by running ip addr. in my case it is enp35s0

Main server /etc/network/interfaces:

Code:
auto lo
iface lo inet loopback
iface lo inet6 loopback

#The default network configuration. enp35s0 can differ from host to host, so chekc it first with "ip addr" command
auto enp35s0
iface enp35s0 inet static
  address 181.10.106.125
  netmask 255.255.255.255
  gateway 181.10.106.65
  
  #line below was not in original config, add same as gateway
  poitopoint 181.10.106.65


#New confirguration for separate IP (creating virtual bridge):
auto vmbr0
iface vmbr0 inet static
  
  #use same main IP you defined earlier as an address
  address 181.10.106.125
  netmask 255.255.255.255
  bridge_ports none
  bridge_stp off
  bridge_fd 0
  #line below activates SECOND additional IP (can have more line for more ip here
  up ip route add 181.10.106.97/32 dev vmbr0

Also very important in GUEST VM which will be usinng second IP - instead of Gateway that HETZNER porvided i control panel - just use MAIN FIRST IP
1700491652622.png

Bonus info for connecting many other VMs to internet, and forwarding ports from main IP, add this to the end of /etc/network/interfaces described above. Dont forget you have to setup 10.0.20.XXX Ip inside that VM with MAIN SEREVERs IP as a GATEWAY ! :

Code:
#DMZ inner network for any VM would have internet access. Could be used to forward ports on MAIN IP to differnt VMS, so they are accessible from WAN
auto vmbr1
iface vmbr1 inet static
    address 10.0.20.254/24
    bridge-ports none
    bridge-stp off
    bridge-fd 0
    post-up echo 1 > /proc/sys/net/ipv4/ip_forward

    #this is main line to share internet to any VM which will be on 10.0.20.254 network
    post-up iptables -t nat -A POSTROUTING -s '10.0.20.0/24' -o enp35s0 -j MASQUERADE

    #Redirect port 8080 from main IP to inner IP of third VM with ip (you have to assign 10.0.20.3 IP for that VM, plus set GATEWAY to MAIN server IP 181.10.106.125 in that VM)
    post-up iptables -t nat -A PREROUTING -i enp35s0 -p tcp --dport 8080 -j DNAT --to 10.0.20.3:8080
    
    #make SSH access to another VM :
    post-up iptables -t nat -A PREROUTING -i enp35s0 -p tcp --dport 2301 -j DNAT --to 10.0.20.31:22
    
    #turn off on disabling.
    post-down iptables -t nat -D POSTROUTING -s '10.0.20.0/24' -o enp35s0 -j MASQUERADE

1700491733161.png
 
  • Like
Reactions: ww7

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!