Is there a way to programmatically add hosts to the local name resolver under Linux?
I would rather avoid fiddling with /etc/hosts dynamically…
Example: add the name foo and bind it to the local port 127.1.2.3
Use Case: I have an application installed locally accessible through a web browser. I’d like the application to be accessible through a local URI.
What is it that you want? You can add
foo 127.0.0.1tohostsor do the equivalent in your nameserver, but a connection tofooon port 1234 will always go to127.0.0.1:1234— it’s not possible to redirect that to port 9999 based on name, which is lost by the timeconnectis called.On Linux you can add IPs to the loopback device (i.e.
ip addr add 127.1.2.3 dev lo), and then useiptablesto change all connections destined for 127.1.2.3:1234 to instead go to 127.0.0.1:9999, but I can’t tell from your question if that the observable behavior you want.