Have a dedicated Ubuntu Server host with a single network interface but with two ip address:
root@server:~# cat /etc/netplan/50-cloud-init.yaml
network:
version: 2
ethernets:
eno3:
dhcp4: true
match:
macaddress: 00:00:00:00:00:00
set-name: eno3
addresses: [IP-A/24, IP-B/32]
When IP-A
is the native ip address assigned to the server and IP-B
is an additional ip address that I have contracted. When configuring using netplan apply
everything works very well, the WEB server exits through the IP address IP-A
and from curl I can see how it is possible to access the internet from IP-B
:
wget -qO- http://checkip.dyndns.com/ --bind-address IP-A
... Current IP Address: IP-A
wget -qO- http://checkip.dyndns.com/ --bind-address IP-B
... Current IP Address: IP-B
The problem is that I also have a virtual machine with kvm
(virsh
), how can I make the virtual machine go out to the internet using IP-B
and not IP-A
as it does by default?
My network interfaces:
root@yhojann:~# ip addr
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
2: eno3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 11:11:11:11:11:11 brd ff:ff:ff:ff:ff:ff
inet IP-A/24 brd x.x.x.255 scope global dynamic eno3
valid_lft 63801sec preferred_lft 63801sec
inet IP-B/32 scope global eno3
valid_lft forever preferred_lft forever
inet6 ffff::fff:ffff:ffff:ffff/64 scope link
valid_lft forever preferred_lft forever
3: eno4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 22:22:22:22:22:22 brd ff:ff:ff:ff:ff:ff
17: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 33:33:33:33:33:33 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
18: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 44:44:44:44:44:44 brd ff:ff:ff:ff:ff:ff
20: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master virbr0 state UNKNOWN group default qlen 1000
link/ether 44:44:44:44:44:44 brd ff:ff:ff:ff:ff:ff
I have tried to find out if it is possible to configure the kvm network using virsh net-edit default
but I have not found any reference that allows to make use of a specific egress ip address of the main host without having to use a new virtual interface and redirect packets with iptables, since this causes a great latency in the connectivity.
Is there a more "native" way to tell kvm to use the specific IP?
The ip addresses and mac addresses shown are for reference only. I make use of ufw to manage the connections.