https://github.com/famousdraw

配置virtual box的redhat虚拟机静态IP地址

配置virtual box的redhat虚拟机静态IP地址
https://marcus.4christies.com/2019/01/how-to-create-a-virtualbox-vm-with-a-static-ip-and-internet-access/

Configuring host-only network
First, make sure that there is a host-only network to connect to. In my case, a default one was already created, called vboxnet0. To check if you already have one, start VirtualBox and then click on the Global Tools button and make sure you are on the Host Manager Network tab.
Take note of the IP Address of the network and the network mask. In the screenshot above, the IP Address is 192.168.99.1 with network mask of 255.255.255.0 which means I can assign IP addresses 192.168.99.2-254 statically. I’ve disabled the DHCP server since I’ll assign IP addresses statically, but in theory you utilize static and dynamic IP assignment (if you do that note that the DHCP server will hand out IP addresses from 100-254 by default, so don’t use those).

 

IPV4地址:192.168.56.1
子网掩码:255.255.255.0

Now add a host-only network adapter to the VM. First, make sure that the VM is shut down. Next, in the VirtualBox app select the VM and click on the Settings button. Click on the Network tab. Adapter 1 should be your NAT adapter. Click on the Adapter 2 subtab, select Host-only Adapter and the name of the host-only network (vboxnet0 in this case).

ip addr

ensp0s8

 

Create a file called ifcfg-enp0s8 in /etc/sysconfig/network-scripts/ and give it the following contents:

DEVICE=enp0s8
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.56.10
NETMASK=255.255.255.0

Where NETMASK should match the settings for your host-only network as obtained above and IPADDR should be an available IP address in the host-only network (again, typically in 2-254 range).

Now run

$ systemctl restart network(不适用redhat)
以下适用redhat
To apply the configuration:
Reload the updated connection files:
# nmcli connection reload
Re-activate the connection:
# nmcli connection up connection_name

 

 

----------------------------------------

如果你认为文章有用,欢迎打赏。

 

posted on 2022-03-29 22:24  红色MINI  阅读(148)  评论(0编辑  收藏  举报

导航