This answer may not help you because it's so late, but hopefully it helps someone else who comes along. I've solved the problem you described by using domain names, a local DHCP server, and a local DNS server which can override public domain names.
This method obviously relies on you having a public DNS address which you can use in place of IP addresses no matter where you go. There are free dynamic DNS services which will serve that purpose. You can set the public IP address in their web interface.
In your LAN, you need a DNS server which gives priority to it's own record of domain names. On that server, you need to redefine your public domain name to point to your local LAN address for the server. Also, your DHCP server needs to provide that local DNS server's address to your android device whenever it assigns the device a LAN address -- otherwise you'll pull the public DNS record and get the public IP address even when you're in the LAN. After doing this, you can connect to the VPN using the domain name no matter where you are.
When you are away from the LAN, your android device will query the public DNS servers provided by your ISP for your VPN's IP address.
myvpn.somepublicdomainname.net -> x.x.x.x (public IP)
When you are inside your LAN, your android device will query your local DNS server.
myvpn.somepublicdomainname.net -> 192.168.1.2 (private IP)
This should work even if your VPN provides an additional DNS server to its clients.
Installing a DNS server (dnsmasq)
The easiest way to set up a DNS server the way I've described is to install and configure
dnsmasq. It is a very lightweight caching DNS server (and DHCP server too, incidentally).
Type this into the terminal:
sudo apt-get update && sudo apt-get install -y dnsmasq
Insert the following line into the end of
Insert into the
/etc/dnsmasq.hosts file or create it if it doesn't exist:
That first part (
192.168.1.2) needs to be the local IP address of your VPN, and the last part (
myvpn.somepublicdomainname.net.) needs to be the public domain name WITH A PERIOD AT THE END. Sorry for the caps, but it's important. That final period lets the server know that it is a top-level domain.
Now restart dnsmasq:
sudo service dnsmasq restart
At this point you should be able to query your DNS server for the IP address of your VPN and get the local IP address instead of the public one. Test it by using dig to query the DNS server (I'll assume the DNS server's IP is
dig @192.168.1.1 myvpn.somepublicdomainname.net
That should give several lines of text, but you can ignore all the ones that start with a comma
; and focus on the one that doesn't:
myvpn.somepublicdomainname.net. 0 IN A 192.168.1.2
If you see this, your local DNS server is giving the local IP address in response to queries. This is good news. If it actually gives the public IP address, you need to double-check your
dnsmasq configuration. Maybe restart the server before going crazy with too many changes. That works a surprising number of times.
Now use the same
dig command and replace
myvpn.somepublicdomainname.net with other public domain names (like
google.com) to make sure it's returning those correctly too. If they work, you can safely reconfigure your DHCP server to use your new DNS server!
Configuring a DHCP server
I'll assume you already have a DHCP server set up in your LAN. That is a service usually provided by your WiFi router. You'll need to configure it to use your new DNS server first, before any other DNS server. That procedure varies, so I'll leave the answer to another question.
If your android device is manually configured to use specific DNS servers (like Google's popular
188.8.131.52) you'll have to switch back to using DHCP-assigned DNS servers OR list your LAN's DNS server first, and use
184.108.40.206 as a fall-back. Manually listing your LAN DNS server first will almost certainly result in slower domain name lookups whenever you aren't inside your LAN which will have a negative effect on your web browsing. There are ways around it, but I'll assume you just go with the DHCP-assigned DNS servers and leave this problem's answer to another question. If you don't know what I'm talking about, it probably doesn't apply to your situation anyway.