Procedure for connecting from a virtual machine to an external network via a proxy server (VirtualBox, Windows10, CentOS7)

Since we built the virtual machine environment, we will leave the procedure as a memorandum. This is the procedure for connecting to the network between the host OS and guest OS and connecting to the external network. It is assumed that VirtualBox is already installed.

environment

Virtual machine: VirtualBox Host OS: Windows 10 Guest OS: CentOS7

CentOS download

Download from the following page. https://www.centos.org/download/

When downloading an older version, follow the steps below

Old version then click here> Tree of the desired version of Archive Versions (7.6 this time)> http://archive.kernel.org/centos-vault/ >7.6.1810/ >isos>x 86 6 4>centos-7x86_64-DVD-1810.iso

There are various types of files such as DVD, Everything, and Minimal, but it seems that you should choose DVD. Please check the reference article for the differences between them.

https://shsm385.hatenablog.com/entry/2018/08/10/160345

VirtualBox settings

The setting part of VirtualBox is almost the same as the following article, so you may want to take a look there.

https://shsm385.hatenablog.com/entry/2018/08/10/160345

Start VirtualBox and create and set up a virtual machine.

Creating a virtual machine

Name and operating system Enter your name. This time I chose CentOS.7. Type is Linux, version is RedHot (64-bit)

Memory size The memory is 2048. hard disk Check Create virtual hard disk.

Virtual hard disk settings

File location The default is ok.

Face size About 80GB is required.

Be careful about memory and storage size. If the storage size is too small, you will stumble when installing the programs required for later environment construction.

It seems that the storage size can be changed later, but that didn't work and I had to recreate the virtual machine from scratch ...

Hard disk file type Select VDI.

Storage on the physical hard disk Select variable size.

Create a virtual machine with the above settings.

Virtual machine settings

After creating the virtual machine, configure the settings.

Settings> General> Advanced A> Clipboard sharing and drag & drop bidirectional

Settings> Storage> Empty> Attributes> Disk icon to the right of the optical drive> Virtual optical disk file selection> Select and open the downloaded CentOS file> Save with OK

CentOS installation

When you start the created virtual machine, the CentOS installer will start. Select Install CentOS 7 and enter. Select Japan in the language selection and continue. Moves to the installation summary screen.

Enable GUI

Let's enable the GUI from the beginning. Click Select Software> Check Server (GUI Specification) and Development Tools> Done

Click Start Installation.

Create ROOT password and user

Create a ROOT password and user during installation. Click Reboot when the installation is complete.

You will be taken to the initial setup screen, so click LICENSING, check I accept the license agreement, and click Finish.

This completes the CentOS settings. Since the GUI is enabled, it takes a long time to install.

network settings

Next, set up the network. I got stuck here quite a bit.

There are two networks that need to be configured.

① Network connection between host OS and guest OS ② Connection to external network

VirtualBox settings

Settings> Network> Adapter 1> Check Enable Network Adapter> Assign NAT> Adapter 2> Check Enable Network> Assign Host-Only Adapter> Name VirtualBox Host-Only Ethernet Adapter> ok

Set NAT for adapter 1 and host-only adapter for adapter 2.

With NAT, the guest OS (CentOS) can connect to the Internet via the host OS (Windows), and the host OS and guest OS can be connected with the host-only adapter.

By making these two settings, you can connect to the network ①②.

For more details, check out this article. https://qiita.com/feifo/items/0fde474005589afcff68

CentOS settings

In the following, I wrote the GUI settings and NetworkManager settings, but only one of them should be sufficient. Please set it by either method you like. I think the GUI is easier to understand.

GUI settings

Applications> System Tools> Settings> Network ・ Enp0s3> Automatic connection ・ Check that other users can use it ・ Enp0s8> Automatic connection ・ Check that other users can use it -Network proxy> Manual check, HTTP proxy http: // proxy server address 8080

enp0s3: Default NAT connection enp0s8: Host-only adapter connection

https://qiita.com/9ryuuuuu/items/c604d8d086f62aaf2362

Settings in NetworkManager

The above GUI settings should be fine, but in some cases you may need to set them in NetworkManager, so I summarized it briefly as background knowledge.

Meaning of IPv4 CONFIGURATION settings

Automatic -Use a DHCP server for IP address, gateway, and DNS settings ・ No need to set IP address, gateway, DNS Manual -Fix the IP address, gateway, and DNS -Enter each item of IP address, gateway, DNS by yourself

What is DHCP -Protocol for automatically making basic settings for communication in an IPv4 network -By using DHCP, each host can obtain the information required for various settings by inquiring to the DHCP server and can perform the settings automatically.

https://www.server-memo.net/centos-settings/network/nmtui.html https://server-setting.info/centos/network-config-c7.html https://www.unix-power.net/networking/post-676 https://www.nic.ad.jp/ja/basics/terms/dhcp.html

procedure

$ nmtui #Start NetworkManager Make the following settings for both Enp0s3 and enp0s8.

Automatically connect -Enable NIC when OS starts ·check

Available to all users ・ All users can use the NIC ·check

Proxy settings

Since we will use a proxy server this time, we will set the proxy. There are three minimum registration requirements: ・ Bash ・ Yum ・ Git

https://qiita.com/egnr-in-6matroom/items/5b9c0ce91d4d203c8ede

~/.bashrc


PROXY=http://Proxy server address:8080

export http_proxy=$PROXY
export HTTP_PROXY=$PROXY
export https_proxy=$PROXY
export HTTPS_PROXY=$PROXY

/ets/yum.conf


PROXY=http://Proxy server address:8080

export http_proxy=$PROXY
export HTTP_PROXY=$PROXY
export https_proxy=$PROXY
export HTTPS_PROXY=$PROXY

~/.gitcinfig


[http "https://github.com" ]
    proxy=http://Proxy server address:8080

You should now be able to connect to the external network from your virtual machine. Thank you for your hard work.