In the following examples we assume that the following IPs are used:
IP Host: 10.0.1.100/24
IP Gateway: 10.0.1.1
IP VM: 10.0.2.100/32
In your virtualizing software you need to create a bridged setup for your virtual machine. On VMware vSphere your vSwitch needs to be "connected" to the NIC of your server. When using most other virtualization environments, like Proxmox or Solus VM, this is default when you chose bridged-setup.
the base-installation needs to be done offline from an installation-medium, because installers usually do not allow the setup which is needed. After installation hostrouting can be configured using configuration-files:
On Debian or Ubuntu you need to setup the NIC of your virtual machine as follows:
auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 10.0.2.100 netmask 255.255.255.255 pointopoint 10.0.1.1 gateway 10.0.1.1
On CentOS network is configured in /etc/sysconfig/network-scripts. Two files need to be created here. Notice, that also the MAC-address of your NIC (see "ifconfig")
DEVICE="eth0" BOOTPROTO="static" HWADDR="00:11:22:33:44:55" IPADDR=10.0.2.100 NETMASK=255.255.255.255 NM_CONTROLLED="no" ONBOOT="yes" SCOPE="peer 10.0.1.1" GATEWAY="10.0.1.1"
default via 10.0.1.1 dev eth0
on openSUSE two files need to be created as well,
BOOTPROTO='static' STARTMODE='auto' NAME='82540EM Gigabit Ethernet Controller' BROADCAST='' ETHTOOL_OPTIONS='' IPADDR='10.0.2.100/32' MTU='' NETWORK='' REMOTE_IPADDR='' USERCONTROL='no'
10.0.1.1 - 255.255.255.255 eth0 default 10.0.1.1 - eth0
sorry, for explaiOn FreeBSD, everything can be setup in /etc/rc.conf:
interface_re0="inet 10.0.2.100 netmask 255.255.255.255" static_routes="gateway default" route_gateway="10.0.1.1 -iface re0" route_default="default 10.0.1.1"
Windows saves the right configuration after issuing the following command (notice, that "Local Area Network" might be localized):
netsh interface ip set address name=“Local Area Network“ static 10.0.2.100 255.255.255.255 10.0.1.1 1
You can also use the configuration-assistant, but you will get a warning when applying configuration - this warning can be ignored, setup will work.