Search code examples
spring-bootmicroservicesvpnresttemplatenetflix-eureka

Not able to access Rest Endpoint by machine name over vpn


I am facing issue with Rest Endpoint. When I am trying to access url with machine name instead of localhost, It is giving Access Denied error. It will give this error only over VPN connection otherwise it is working fine without VPN.

I do not have same issue with browser. Browser is able to identify url with machine name. This issue is only when I am trying to consume any endpoint running on different microservice on same machine through Java code or Postman

For Example, If I am consuming some endpoint in Java.

restTemplate.getForEntity("http://localhost:8761/actuator/beans", Object.class).getBody()
//Working fine

restTemplate.getForEntity("http://my_machine_name:8761/actuator/beans", Object.class).getBody()
//Access denied

or through Postman

http://my_machine_name:8761/actuator/beans

Error: connect EACCES 192.xxx.x.x:8761

enter image description here

Mainly I am using Discovery Client to identity the machine name and port so that I need not to hard code localhost in the url. I am using FeignClient for loadbalancer but looks like restTemplate is also giving same error.


Solution

  • I have fixed above error. If you connect your machine with VPN, it change your network. So you need to find which ip address is getting used in your machine. Try ipconfig in command prompt to find the ip address in Windows.

    If you give your machine name instead of above IP address then it will not be able to find your machine as your machine name is not available in your network (because of VPN connection).

    machine.ip.address=XX.66.223.XXX
    eureka.client.service-url.default-zone=http://${machine.ip.address}:8761/eureka
    eureka.instance.hostname=${machine.ip.address}
    

    Provide your network ip address in your URL instead of machine name to make it work.