3 ms·
Why not grep+awk ifconfig if you need your IP from a script?
by GuiA 14y ago
Why not grep+awk ifconfig if you need your IP from a script?
- jdc 14y agoNAT
- kelnos 14y agoThat won't give you your publicly-addressable IP if you're behind a NAT.
- cynwoody 14y agoBecause, typically, you are behind a NAT router, and you are after your WAN address, not the LAN address you were assigned by the router. Depending on the router, it might be simpler and more reliable to interrogate the router. Also, some routers come with dynamic DNS updating built in (dynamic DNS is a common reason for needing this service).
- jsnell 14y agoThat won't show you the public IP if you're behind a NAT. Why would you need the public IP instead of the private one? For example because you're trying to search for requests coming from that machin in some logs, take traffic traces from somewhere beyond the NAT, etc.
- Wilya 14y agoIf you're looking for your public ip, it won't always work. Especially if you are behind a nat/proxy. That, plus knowing which interface to inspect among those returned by ifconfig isn't always obvious.
- GuiA 14y agoCool, thanks for the reply! (and to all other replies as well :) )