1

I want to connect to VM1 (192.168.122.101) from/to the internet, i.e., Internet (x.x.5.5/ens3:4) <-> VM1 (192.168.122.101) without impacting the other networks (ens3, ens3:0->3).

The problem is my VPS has only one physical NIC. Other IPs are aliases as displayed in the diagram below. If I bridge ens3, won't the aliases be brought down?

I followed this guide to the letter, but ssh to the VM (@x.x.5.5) connects to the main NIC/host (@88.88.88.88). ssh to the local IP (@192.168.122.101) connects to the VM.

How should I configure the network on the VPS to make it assign for each VM (presently one VM) a private IP that can connect to the Internet and act as a webserver? If the desired setup isn't possible with Ubuntu 16.04, would an upgrade to 18/20.04 do it?

Config:

  • OVH VPS
  • Ubuntu 16.04
  • KVM
  • ufw
  • virtualmin / webmin

Network (simplified):

Internet
   \
   |
   +------------------------+
   | Ubuntu server          | virbr0 (192.168.122.1/24)
   +------------------------+ NAT
   | ens3: 88.88.88.88      |                    Static IP for VM
   +----------------+-------------+------------+-----------------+
   | ens3:0 x.x.1.1 |             | site1.com  | Virtualmin->www
   +----------------+-------------+------------+-----------------+
   | ens3:1 x.x.2.2 |             | site2.com  | Virtualmin->www
   +----------------+-------------+------------+-----------------+
   | ens3:2 x.x.3.3 |             | site3.com  | Virtualmin->www
   +----------------+-------------+------------+-----------------+
   | ens3:3 x.x.4.4 |             | site4.com  | Virtualmin->www
   +----------------+-------------+------------+-----------------+
   | ens3:4 x.x.5.5 |             | VM1/Ubuntu | 192.168.122.101
   +----------------+-------------+------------+-----------------+

Current IP config:

root:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fa:06:3f:2c:05:3b brd ff:ff:ff:ff:ff:ff
    inet 88.88.88.88/32 brd 88.88.88.88 scope global ens3
       valid_lft forever preferred_lft forever
    inet x.x.1.1/32 brd x.x.1.1 scope global ens3:0
       valid_lft forever preferred_lft forever
    inet x.x.2.2/32 brd x.x.2.2 scope global ens3:1
       valid_lft forever preferred_lft forever
    inet x.x.3.3/32 brd x.x.3.3 scope global ens3:2
       valid_lft forever preferred_lft forever
    inet x.x.4.4/32 brd x.x.4.4 scope global ens3:3
       valid_lft forever preferred_lft forever
    inet x.x.5.5/32 brd x.x.5.5 scope global ens3:4
       valid_lft forever preferred_lft forever
3: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 51:52:00:c9:9b:7d brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 51:52:00:c9:9b:7d brd ff:ff:ff:ff:ff:ff
6: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master virbr0 state UNKNOWN group default qlen 1000
    link/ether 50:54:00:46:ea:7c brd ff:ff:ff:ff:ff:ff

root:~# ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether fa:06:3f:2c:05:3b brd ff:ff:ff:ff:ff:ff

virsh config:

root:~# virsh net-dumpxml default
<network connections='1'>
  <name>default</name>
  <uuid>54b584b8-b2f5-45cb-a8e1-8d75540dc1a8</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='51:52:00:c9:9b:7d'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
  <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

root:~# virsh domifaddr dpcloud
 Name       MAC address          Protocol     Address
-------------------------------------------------------------------------------
 vnet0      50:54:00:46:ea:7c    ipv4         192.168.122.101/24

root:~# ssh user@192.168.122.101
...

root:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:46:ea:7c brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.101/24 brd 192.168.122.255 scope global dynamic ens2
       valid_lft 3470sec preferred_lft 3470sec
    inet6 fe80::5054:ff:fe46:ea7c/64 scope link 
       valid_lft forever preferred_lft forever
lucasart
  • 123
  • 1
  • 9
  • 1
    There is no such thing as interface aliases anymore. All of the IPs are on the named interface. – Michael Hampton Aug 14 '20 at 02:54
  • @MichaelHampton I believe it's a misunderstanding of the terminology on the OP's part. I believe he was referring to *subinterfaces*, however has unintentionally referred to them as aliases, as the term has been around for only God knows how long. – Christopher H Aug 14 '20 at 03:12
  • 1
    @ChristopherH There are still thousands of tutorials out there that refer to interface aliases as if it is actually a current thing, when it's not been for over a decade. And people are still writing them. It's a total mess because it just ends up confusing people. – Michael Hampton Aug 14 '20 at 03:21
  • @MichaelHampton: yes, I was referring to _subinterfaces_ — I didn't know up until now they differred from aliases. [added _ip link_ output] – lucasart Aug 14 '20 at 03:35
  • Could [this](https://serverfault.com/questions/954052/assign-ethernet-alias-to-kvm-guest) be the only solution? — 1/ remove aliases - 2/ setup a bridge and add physical NIC to it - 3/ setup kvm VMs with bridged network - 4/ inside the guest, configure ipv4 to use other IPs – lucasart Aug 14 '20 at 08:01

1 Answers1

0

I ended up following @ChaoxiangN's advice here:

  1. Remove aliases
  2. Setup a bridge (br0) and add other IPs to it
  3. Setup KVM VMs with its own bridged network (virbr0)

Then, instead of "4/ inside the guest, configure ipv4 to use other IPs", I enabled NAT with iptables:

root:~# iptables -t nat -I PREROUTING -p tcp -d 111.122.133.144 --dport 1:65535 -j DNAT --to-destination 192.168.122.88:1-65535
root:~# iptables -I FORWARD -m state -d 192.168.122.0/24 --state NEW,RELATED,ESTABLISHED -j ACCEPT

Note: 111.122.133.144 = public IP, 192.168.122.88 = VM1 IP

ssh user@111.122.133.144
...

user@VM1:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:32:00:11:20:88 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.88/24 brd 192.168.122.255 scope global dynamic enp1s0
       valid_lft 3576sec preferred_lft 3576sec
    inet6 fe80::5054:ff:fe73:2096/64 scope link 
       valid_lft forever preferred_lft forever
lucasart
  • 123
  • 1
  • 9