I have two 18.04.2 Ubuntu computers on my home network behind the same router.
On each computer, if I run this command:
curl -4 ifconfig.me
I get the same result on each machine, the dynamic public IPv4 IP address currently assigned to the router: XX.XX.XX.XX.
Then, on computer #1, I start a VPN. When I then run the same curl command, I get a different result, the IP address that the VPN assigns: YY.YY.YY.YY.
Question: What terminal command do I run on computer #1 while the VPN is active on computer #1 to find out the currently assigned dynamic public IPv4 IP address the router is using for computer #2 (which is not using the VPN)?
You could ask the router.
If it supports UPnP, then you can use
upnpc
from the miniupnpc packageTry:
or
to specify explicitly the interface to use. So change
enp1s0
to fit your setup. Obviously, don't use thetun0
interface or the interface used by the VPN, if any.The general answer is that you can't. And with more complex configuration you're not guaranteed that the public IP will belong to your closest router (Carrier Grade NAT, multiple routers in private IP space, proxy servers and so forth).
You can add a route for
ifconfig.me
. This is somewhat complex, as the domain points to at least four IP's, and being hosted in Google Cloud, I wouldn't bet on those IP's to be entirely static either.Nor do you, in more complex configurations, have any assurance that two different computers will exit from the same public IP.
All together this smells like a X-Y problem. Why do you want to find the public IP of computer #2?