Wednesday, July 26, 2023

Configuring a proxy for WSL



Guest OS (WSL) is not able to connect to undleying internet of Host OS (Windows) when we connect to VPN  in the Host OS (Windows)

Before configuring Proxy in guest OS (WSL). First we need to perform communication check whether Guest OS (WSL) and Host OS are communicating each other not 


 - Communication check between Guest OS and Host OS<\u>
 
   1.  To know IPV4 Address of Ethernet Adapter for WSL, type ipconfig  (or) ipconfig /all in command shell of Host OS.
   2.  To know Ip address of proxy , type ping  in command shell of Host OS
   3.  to know ip address of WSL , type , hostname -I  (or) ifconfig in guest OS (WSL)
   
  Then 
  
  1. Ping ip address of WSL from Host OS  ( ex: Ping  <ip-Address-of-WSL>).   if packets are transferred and received successfully then it means  HostOS is able to communicate with Guest OS (WSL)
  
  2. ping IPV4 Address of Ethernet Adapter for WSL  and ping Ip address of proxy from Guest OS (WSL) . if packets are transferred and received successfully then it means  Guest-OS (WSL) is able to communicate with Host-OS.


if both are communicating each other then follow below steps to configure proxy in WSL.


### Proxy DNS name resolution in Guest OS

```sh
# To resolve proxy dns name in Guest OS , add proxy ip address and dns names of proxy  in /etc/hosts

sudo nano /etc/hosts

#Add below text with proper ip address and dns names of Proxy

#xxx.xx.xx.xx   proxy.example.com   proxy-dev.example.com   
```


### Add proxy configuration in  /etc/apt/apt.conf.d/proxy.conf file for execute apt-get , apt install command  with internet

```sh
#Open /etc/apt/apt.conf.d/proxy.conf in nano editor.  note: use vi editor  

sudo nano /etc/apt/apt.conf.d/proxy.conf
   
   
  Acquire::http::proxy  http://proxy.example.com:7007;
  Acquire::ftp::proxy  http://proxy.example.com:7007;
  Acquire::https::proxy http://proxy.example.com:7007;
  
  #Note: Please use correct proxy URL and port number



#if proxy configuration is enable in proxy.conf  . no need to add proxy config in apt.conf else you can add . this configuration will be used by apt command
 
   sudo nano /etc/apt/apt.conf

   Acquire::http::proxy  http://proxy.example.com:7007;
   Acquire::ftp::proxy  http://proxy.example.com:7007;
   Acquire::https::proxy http://proxy.example.com:7007;
   
  #Note: Please use correct proxy URL and port number

# then you can upgrade packages and install new packages using apt cli

#example

	#sudo apt-get update -y
	#sudo apt install ipmiutil
	#sudo apt install dotnet-host
    #sudo apt install net-tools
```

To avoid updating proxy configuration in conf file by restarting WSL. You can add proxy configuration in profile 

```sh 
sudo nano  ~/.profile

	export https_proxy=http://proxy.example.com:7007
    export http_proxy=http://proxy.example.com:7007

#Note: Please use correct proxy URL and port number

#To avoid restarting the WSL you can run the command:

source ~/.profile

```

### Below is the proxy configuration for wget command 


```sh 
 sudo nano ~/.wgetrc
    
    http_proxy=http://proxy.example.com:7007
    https_proxy=http://proxy.example.com:7007
    use_proxy=on

#Note: Please use correct proxy URL and port number

```

### Below is the proxy configuration for git

```sh
 git config —-global http.proxy http://proxy.example.com:7007
```

### Below is the proxy configuration for git

```sh
	npm set proxy http://proxy.example.com:7007
	npm set https-proxy http://proxy.example.com:7007
```



No comments:

Post a Comment