I want to bridge y.y.4.36 to my Virtual machine.
I can configure y.y.4.36 on Host. So routing to Host works and I can ping y.y.4.36
from the internet:
$ ifconfig
eno2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet x.x.41.32 netmask 255.255.255.0 broadcast x.x.41.255
inet6 fe80::5a20:b1ff:fe07:b375 prefixlen 64 scopeid 0x20<link>
ether 58:20:b1:07:b3:75 txqueuelen 1000 (Ethernet)
RX packets 2851252 bytes 241129524 (241.1 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6722211 bytes 9634863759 (9.6 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0x92c00000-92cfffff
eno2:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet y.y.4.36 netmask 255.255.255.224 broadcast y.y.4.63
ether 58:20:b1:07:b3:75 txqueuelen 1000 (Ethernet)
device memory 0x92c00000-92cfffff
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 x.x.41.1 0.0.0.0 UG 0 0 0 eno2
x.x.41.0 0.0.0.0 255.255.255.0 U 0 0 0 eno2
Note there is no default gateway for y.y.4.36.
I can easily set the VM to used Bridged Network, and set its address to y.y.4.36. But how do I make it reachable from the internet?
I expect I have to remove eno2:0 and then some how tell the virtual machine that it should use y.y.4.36 as its address and x.x.41.1 as its default gateway.
But how do I do that?
This does not work:
$ route add -net default gw x.x.41.1
SIOCADDRT: Network is unreachable
because the VM does not have an address on x.x.41.*.
Edit
I have made a workaround. On Virtual Machine add another interface with host networking. Then:
ifconfig enp0s8 192.168.56.2
ifconfig eth0 y.y.4.36 netmask 255.255.255.224
route add -net default gw 192.168.56.1
# Force the src address to be y.y.4.36 and not 192.168.56.2
ip route replace default via 192.168.56.1 dev enp0s8 src y.y.4.36
On Host:
route add -host y.y.4.36 gw 192.168.56.2
So I route traffic through VirtualBox's host network (192.168.56.0/24).
It seems to work, but I believe there is a more conventional way to do accomplish giving y.y.4.36 to the VM.