How to Handle Host IP Change for Proxy Reconfiguration: A Comprehensive Guide

I. Introduction

There are actually many tutorials like this online. The author has also reviewed these tutorials, but most of them have issues. The primary issue is: when the host IP changes, the proxy IP needs to be reconfigured. Therefore, I am writing this article to document the process for others to reference.

[Supplement 2024-12-29] If the host uses proxy software to route traffic, like clash, you can use the Tun mode directly. In Tun mode, the proxy software creates a virtual network card, and network requests from processes on the host (including virtual machines) are redirected to this virtual network card. This mode intercepts network requests from all processes, as some processes do not follow system proxy settings, such as terminals, pip, docker, etc. Tun mode is especially effective for these.

Chapter References:

For using the system proxy mode, refer to Chapters 2 to 7. Previous tutorials followed this mode, and as long as environment variables like http_proxy are configured, processes might use the proxy according to the environment settings.

For using Tun mode, refer to Chapter 8

Differences between System Proxy Mode and Tun Mode, refer to Chapter 8

Tun mode is recommended

II. General Process Configuration

  1. VM Software Configuration
  2. Host Configuration
  3. VM Virtual Machine Configuration

The above processes basically do not require command line input.

III. VM Software Configuration

1. VM Virtual Network Editor

Open the Virtual Network Editor (Path: Edit -> Virtual Network Editor),

 host IP change

Then click Change Settings

 host IP change

2. Configure VMnet8 and VMnet1

VMnet8 [Subnet Configuration] as follows:

[NAT Settings] as follows:

[DHCP Settings] as follows: (This can be understood as the IP range for the virtual machine. Ensure it does not conflict with the gateway configuration above)

[VMnet1] can use the default configuration, but you can also change it to an easy-to-remember IP as per the VMnet8 setup above:

IV. Host IP Configuration

On Windows, go to Settings -> Network

[Supplement 2024-9-18] [Optional START // This range is optional]

Double click the red box above and configure as follows: (Make sure it does not conflict with the previous gateway)

[Supplement 2024-9-18] [Optional END // This range is optional]

The proxy software should enable [Allow LAN]: (Note the port here, mine is 7890)

Then click on:

Note the following interface IPs; this IP will be used in the VM virtual machine, both can be used:

You can also find this by typing ipconfig in the Windows terminal:

V. Virtual Machine Proxy IP Configuration

Before configuring the proxy, you need to set the network adapter. We previously configured VMnet8, and it can be used here.

5.1 Configuring Proxy on the Virtual Machine Using [Settings]

Configure the proxy using [Settings]. Proxy settings will affect all graphic apps, such as browsers, shell…

However, it does not affect ssh (using ssh to connect to the virtual machine ubuntu) terminals, so you will need to configure the proxy for ssh separately, see Chapter 7.

Of course, this configuration also does not affect many apps that require a separate proxy configuration, such as conda, pip, docker, etc.

Enter the virtual machine, configure the IP. If it’s Ubuntu, you can reference the configuration below: (Pay attention to the port in the image; it should be consistent with the proxy software’s port)

Then you can open the browser to view external websites, or in the terminal:

VI. On Proxy IP Selection Issues

[Supplement 2024-9-18 START]

According to the above, we obtained two groups of proxy IPs:

VMnet1: 192.168.80.1 VMnet8: 192.168.6.1

If the virtual machine can ping the above IPs (e.g., ping 192.168.80.1), it means the virtual machine and host are in the same Local Area Network.

In my case: I could ping both IPs from the virtual machine, theoretically allowing both to be used. But in practice, VMnet1 worked while VMnet8 did not.

I did not delve into the underlying principles of the VM network in this area. I let it slide since it worked for me ^_^.

[Supplement 2024-9-18 END]

In the previous configuration, I used the VMnet1 network interface instead of VMnet8?

This mainly stems from noticing that the VMnet8 network interface was not working, so I tried using VMnet1 and found it could use the proxy.

VII. On SSH Proxy Configuration, Terminal Proxy Use

SSH Connection

1. VS Code Proxy Configuration

This enables the use of some plugins requiring a proxy, like copilot.

2. Use Proxy for SSH Remote Terminal

Add proxy configuration in ~/.bashrc:

# Proxy
export hostip=192.168.80.1
export post=7890
alias proxy='
    export http_proxy=http://${hostip}:${post}
    export https_proxy=http://${hostip}:${post}
    export ALL_PROXY=http://${hostip}:${post}
    export all_proxy=socks://${hostip}:${post}
'
alias unproxy='
    unset ALL_PROXY
    unset https_proxy
    unset http_proxy
    unset all_proxy
'
alias echoproxy='
    echo $ALL_PROXY
    echo $all_proxy
    echo $https_proxy
    echo $http_proxy
'

source ~/.bashrc

To use the proxy, enter ‘proxy’ in the terminal, and ‘unproxy’ to cancel.

VIII. [Supplement 2024-12-29] Tun Mode

1. The host proxy software needs to support Tun mode

2. [Author Recommends clash-verge-rev 2024-12-29]Release Clash Verge Rev v2.0.2 · clash-verge-rev/clash-verge-rev · GitHub

3. Official Tutorial Documentation: Quick Start – Clash Verge Rev Docs

4. Difference between System Proxy and Tun Mode, screenshot from the above tutorial documentation: