Use reference to file instead of IP in /etc/hosts

Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
From my host with hostname localhost, I would like to reach an external host with hostname exthost through the internet. The public IP address of exthost is dynamically assigned by the Internet Provider.
I would like to refer to exthost using always its name, and mapping this name to its actual IP address, according to the value assigned by the Provider, which may change.
To do so, I would like to use /etc/hosts, properly updating the IP address value of the line related to exthost.
For example, the line in /etc/hosts in Linux may look like:
<ip_address> exthost.domain exthost
I am using Ubuntu 18.04, but this surely applies also to other distros/Unix-like systems.
Is it possible to do this, avoiding to set up a DNS (and also a dynamic DNS, which sometimes is not a free service) just for this purpose?
For example, is it possible to use, instead of an explicit <ip_address>, a reference to another file containing only the desired IP as a string? So that this file can be accessed and modified by a user, according to the IP value, which may vary.
Note: this question seems not to be the same case, because it is about the local machine. I am instead referring to an external host.
ubuntu networking ip hosts
add a comment |
up vote
1
down vote
favorite
From my host with hostname localhost, I would like to reach an external host with hostname exthost through the internet. The public IP address of exthost is dynamically assigned by the Internet Provider.
I would like to refer to exthost using always its name, and mapping this name to its actual IP address, according to the value assigned by the Provider, which may change.
To do so, I would like to use /etc/hosts, properly updating the IP address value of the line related to exthost.
For example, the line in /etc/hosts in Linux may look like:
<ip_address> exthost.domain exthost
I am using Ubuntu 18.04, but this surely applies also to other distros/Unix-like systems.
Is it possible to do this, avoiding to set up a DNS (and also a dynamic DNS, which sometimes is not a free service) just for this purpose?
For example, is it possible to use, instead of an explicit <ip_address>, a reference to another file containing only the desired IP as a string? So that this file can be accessed and modified by a user, according to the IP value, which may vary.
Note: this question seems not to be the same case, because it is about the local machine. I am instead referring to an external host.
ubuntu networking ip hosts
Could you describe what you're trying to accomplish at a higher level as thehostsfile predates DNS and as the question now stands it looks like you're trying to build your own DNS system using saidhostfile... Maybe Dynamic DNS is a solution, but we need to have more info.
– Fabby
Nov 21 at 10:33
@Fabby I tried to better explain what I'm trying to do: question updated. Thanks! Yes, maybe it is a handcrafted, rudimentary DNS service. If/etc/hostsfile is intended for static IP only, this could be not a proper use of it: I don't know the purpose of/etc/hostsvery well, so this is part of the question.
– BowPark
Nov 21 at 10:49
Well, rAlen gave the answer I was going to give: there are free Dynymic DNS services out there (depending on your router brand, your router manufacturer might even provide you such a service for free)
– Fabby
Nov 21 at 11:27
@Fabby Thank you so much to both.
– BowPark
Nov 22 at 12:31
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
From my host with hostname localhost, I would like to reach an external host with hostname exthost through the internet. The public IP address of exthost is dynamically assigned by the Internet Provider.
I would like to refer to exthost using always its name, and mapping this name to its actual IP address, according to the value assigned by the Provider, which may change.
To do so, I would like to use /etc/hosts, properly updating the IP address value of the line related to exthost.
For example, the line in /etc/hosts in Linux may look like:
<ip_address> exthost.domain exthost
I am using Ubuntu 18.04, but this surely applies also to other distros/Unix-like systems.
Is it possible to do this, avoiding to set up a DNS (and also a dynamic DNS, which sometimes is not a free service) just for this purpose?
For example, is it possible to use, instead of an explicit <ip_address>, a reference to another file containing only the desired IP as a string? So that this file can be accessed and modified by a user, according to the IP value, which may vary.
Note: this question seems not to be the same case, because it is about the local machine. I am instead referring to an external host.
ubuntu networking ip hosts
From my host with hostname localhost, I would like to reach an external host with hostname exthost through the internet. The public IP address of exthost is dynamically assigned by the Internet Provider.
I would like to refer to exthost using always its name, and mapping this name to its actual IP address, according to the value assigned by the Provider, which may change.
To do so, I would like to use /etc/hosts, properly updating the IP address value of the line related to exthost.
For example, the line in /etc/hosts in Linux may look like:
<ip_address> exthost.domain exthost
I am using Ubuntu 18.04, but this surely applies also to other distros/Unix-like systems.
Is it possible to do this, avoiding to set up a DNS (and also a dynamic DNS, which sometimes is not a free service) just for this purpose?
For example, is it possible to use, instead of an explicit <ip_address>, a reference to another file containing only the desired IP as a string? So that this file can be accessed and modified by a user, according to the IP value, which may vary.
Note: this question seems not to be the same case, because it is about the local machine. I am instead referring to an external host.
ubuntu networking ip hosts
ubuntu networking ip hosts
edited Nov 21 at 10:50
asked Nov 21 at 9:51
BowPark
1,52982445
1,52982445
Could you describe what you're trying to accomplish at a higher level as thehostsfile predates DNS and as the question now stands it looks like you're trying to build your own DNS system using saidhostfile... Maybe Dynamic DNS is a solution, but we need to have more info.
– Fabby
Nov 21 at 10:33
@Fabby I tried to better explain what I'm trying to do: question updated. Thanks! Yes, maybe it is a handcrafted, rudimentary DNS service. If/etc/hostsfile is intended for static IP only, this could be not a proper use of it: I don't know the purpose of/etc/hostsvery well, so this is part of the question.
– BowPark
Nov 21 at 10:49
Well, rAlen gave the answer I was going to give: there are free Dynymic DNS services out there (depending on your router brand, your router manufacturer might even provide you such a service for free)
– Fabby
Nov 21 at 11:27
@Fabby Thank you so much to both.
– BowPark
Nov 22 at 12:31
add a comment |
Could you describe what you're trying to accomplish at a higher level as thehostsfile predates DNS and as the question now stands it looks like you're trying to build your own DNS system using saidhostfile... Maybe Dynamic DNS is a solution, but we need to have more info.
– Fabby
Nov 21 at 10:33
@Fabby I tried to better explain what I'm trying to do: question updated. Thanks! Yes, maybe it is a handcrafted, rudimentary DNS service. If/etc/hostsfile is intended for static IP only, this could be not a proper use of it: I don't know the purpose of/etc/hostsvery well, so this is part of the question.
– BowPark
Nov 21 at 10:49
Well, rAlen gave the answer I was going to give: there are free Dynymic DNS services out there (depending on your router brand, your router manufacturer might even provide you such a service for free)
– Fabby
Nov 21 at 11:27
@Fabby Thank you so much to both.
– BowPark
Nov 22 at 12:31
Could you describe what you're trying to accomplish at a higher level as the
hosts file predates DNS and as the question now stands it looks like you're trying to build your own DNS system using said host file... Maybe Dynamic DNS is a solution, but we need to have more info.– Fabby
Nov 21 at 10:33
Could you describe what you're trying to accomplish at a higher level as the
hosts file predates DNS and as the question now stands it looks like you're trying to build your own DNS system using said host file... Maybe Dynamic DNS is a solution, but we need to have more info.– Fabby
Nov 21 at 10:33
@Fabby I tried to better explain what I'm trying to do: question updated. Thanks! Yes, maybe it is a handcrafted, rudimentary DNS service. If
/etc/hosts file is intended for static IP only, this could be not a proper use of it: I don't know the purpose of /etc/hosts very well, so this is part of the question.– BowPark
Nov 21 at 10:49
@Fabby I tried to better explain what I'm trying to do: question updated. Thanks! Yes, maybe it is a handcrafted, rudimentary DNS service. If
/etc/hosts file is intended for static IP only, this could be not a proper use of it: I don't know the purpose of /etc/hosts very well, so this is part of the question.– BowPark
Nov 21 at 10:49
Well, rAlen gave the answer I was going to give: there are free Dynymic DNS services out there (depending on your router brand, your router manufacturer might even provide you such a service for free)
– Fabby
Nov 21 at 11:27
Well, rAlen gave the answer I was going to give: there are free Dynymic DNS services out there (depending on your router brand, your router manufacturer might even provide you such a service for free)
– Fabby
Nov 21 at 11:27
@Fabby Thank you so much to both.
– BowPark
Nov 22 at 12:31
@Fabby Thank you so much to both.
– BowPark
Nov 22 at 12:31
add a comment |
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
There is no such thing as a user defined hosts file on Linux, you can use HOSTALIASES which works with canonical names.
If I got your question correctly you can use a dynamic DNS service like DynDNS or No-IP to always have a correct public IP address your ISP assigned.
You can then use HOSTSALIASES to map exthost to FQDN name provided by a dynamic DNS service.
Export HOSTALIASES value with export HOSTALIASES=~/.hosts and then add a following line to ~/.hosts file to map exthost to FDQN name provided by no-ip for example.
exthost yourname.no-ip.org
HOSTALIASES works only with cannonical names, not IPs, which is why you should use some dynamic DNS service to have FQDN name, but you can just use that FQDN, and skip the HOSTALIASES completely.
I don't think you can do this without setting up some DNS service, or scripting something on remote site to always send you their public IP and then change that IP in local /etc/hosts file.
Another option would be to either give user permission to change /etc/hosts or set that user in chroot environment, and give him his own /etc/hosts file in his chroot environment.
Yup, exactly what I was going to say: +1
– Fabby
Nov 21 at 11:28
Nope... /etc/hosts @rAlen
– Michael Prokopec
Nov 21 at 12:40
add a comment |
up vote
0
down vote
My /etc/hosts:
127.0.0.1 localhost
127.0.1.1 *some-host*
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
So say:
sudo nano /etc/hosts
Add a line:
IPOFEXTHOST exthost
Where IPOFEXTHOST is the known ip of exthost.
From that point on you could write a script to update the file by replacing the line containing exthost.
No matter what though, one of the computers is going to have to have a dyndns or no-ip updater. So that either you know the web address of exthost directly or exthost can know your other computer's address to reverse ssh in and update the file with it's curl'ed public IP.
New contributor
Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
There is no such thing as a user defined hosts file on Linux, you can use HOSTALIASES which works with canonical names.
If I got your question correctly you can use a dynamic DNS service like DynDNS or No-IP to always have a correct public IP address your ISP assigned.
You can then use HOSTSALIASES to map exthost to FQDN name provided by a dynamic DNS service.
Export HOSTALIASES value with export HOSTALIASES=~/.hosts and then add a following line to ~/.hosts file to map exthost to FDQN name provided by no-ip for example.
exthost yourname.no-ip.org
HOSTALIASES works only with cannonical names, not IPs, which is why you should use some dynamic DNS service to have FQDN name, but you can just use that FQDN, and skip the HOSTALIASES completely.
I don't think you can do this without setting up some DNS service, or scripting something on remote site to always send you their public IP and then change that IP in local /etc/hosts file.
Another option would be to either give user permission to change /etc/hosts or set that user in chroot environment, and give him his own /etc/hosts file in his chroot environment.
Yup, exactly what I was going to say: +1
– Fabby
Nov 21 at 11:28
Nope... /etc/hosts @rAlen
– Michael Prokopec
Nov 21 at 12:40
add a comment |
up vote
4
down vote
accepted
There is no such thing as a user defined hosts file on Linux, you can use HOSTALIASES which works with canonical names.
If I got your question correctly you can use a dynamic DNS service like DynDNS or No-IP to always have a correct public IP address your ISP assigned.
You can then use HOSTSALIASES to map exthost to FQDN name provided by a dynamic DNS service.
Export HOSTALIASES value with export HOSTALIASES=~/.hosts and then add a following line to ~/.hosts file to map exthost to FDQN name provided by no-ip for example.
exthost yourname.no-ip.org
HOSTALIASES works only with cannonical names, not IPs, which is why you should use some dynamic DNS service to have FQDN name, but you can just use that FQDN, and skip the HOSTALIASES completely.
I don't think you can do this without setting up some DNS service, or scripting something on remote site to always send you their public IP and then change that IP in local /etc/hosts file.
Another option would be to either give user permission to change /etc/hosts or set that user in chroot environment, and give him his own /etc/hosts file in his chroot environment.
Yup, exactly what I was going to say: +1
– Fabby
Nov 21 at 11:28
Nope... /etc/hosts @rAlen
– Michael Prokopec
Nov 21 at 12:40
add a comment |
up vote
4
down vote
accepted
up vote
4
down vote
accepted
There is no such thing as a user defined hosts file on Linux, you can use HOSTALIASES which works with canonical names.
If I got your question correctly you can use a dynamic DNS service like DynDNS or No-IP to always have a correct public IP address your ISP assigned.
You can then use HOSTSALIASES to map exthost to FQDN name provided by a dynamic DNS service.
Export HOSTALIASES value with export HOSTALIASES=~/.hosts and then add a following line to ~/.hosts file to map exthost to FDQN name provided by no-ip for example.
exthost yourname.no-ip.org
HOSTALIASES works only with cannonical names, not IPs, which is why you should use some dynamic DNS service to have FQDN name, but you can just use that FQDN, and skip the HOSTALIASES completely.
I don't think you can do this without setting up some DNS service, or scripting something on remote site to always send you their public IP and then change that IP in local /etc/hosts file.
Another option would be to either give user permission to change /etc/hosts or set that user in chroot environment, and give him his own /etc/hosts file in his chroot environment.
There is no such thing as a user defined hosts file on Linux, you can use HOSTALIASES which works with canonical names.
If I got your question correctly you can use a dynamic DNS service like DynDNS or No-IP to always have a correct public IP address your ISP assigned.
You can then use HOSTSALIASES to map exthost to FQDN name provided by a dynamic DNS service.
Export HOSTALIASES value with export HOSTALIASES=~/.hosts and then add a following line to ~/.hosts file to map exthost to FDQN name provided by no-ip for example.
exthost yourname.no-ip.org
HOSTALIASES works only with cannonical names, not IPs, which is why you should use some dynamic DNS service to have FQDN name, but you can just use that FQDN, and skip the HOSTALIASES completely.
I don't think you can do this without setting up some DNS service, or scripting something on remote site to always send you their public IP and then change that IP in local /etc/hosts file.
Another option would be to either give user permission to change /etc/hosts or set that user in chroot environment, and give him his own /etc/hosts file in his chroot environment.
edited Nov 21 at 11:08
answered Nov 21 at 11:03
rAlen
675410
675410
Yup, exactly what I was going to say: +1
– Fabby
Nov 21 at 11:28
Nope... /etc/hosts @rAlen
– Michael Prokopec
Nov 21 at 12:40
add a comment |
Yup, exactly what I was going to say: +1
– Fabby
Nov 21 at 11:28
Nope... /etc/hosts @rAlen
– Michael Prokopec
Nov 21 at 12:40
Yup, exactly what I was going to say: +1
– Fabby
Nov 21 at 11:28
Yup, exactly what I was going to say: +1
– Fabby
Nov 21 at 11:28
Nope... /etc/hosts @rAlen
– Michael Prokopec
Nov 21 at 12:40
Nope... /etc/hosts @rAlen
– Michael Prokopec
Nov 21 at 12:40
add a comment |
up vote
0
down vote
My /etc/hosts:
127.0.0.1 localhost
127.0.1.1 *some-host*
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
So say:
sudo nano /etc/hosts
Add a line:
IPOFEXTHOST exthost
Where IPOFEXTHOST is the known ip of exthost.
From that point on you could write a script to update the file by replacing the line containing exthost.
No matter what though, one of the computers is going to have to have a dyndns or no-ip updater. So that either you know the web address of exthost directly or exthost can know your other computer's address to reverse ssh in and update the file with it's curl'ed public IP.
New contributor
Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
My /etc/hosts:
127.0.0.1 localhost
127.0.1.1 *some-host*
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
So say:
sudo nano /etc/hosts
Add a line:
IPOFEXTHOST exthost
Where IPOFEXTHOST is the known ip of exthost.
From that point on you could write a script to update the file by replacing the line containing exthost.
No matter what though, one of the computers is going to have to have a dyndns or no-ip updater. So that either you know the web address of exthost directly or exthost can know your other computer's address to reverse ssh in and update the file with it's curl'ed public IP.
New contributor
Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
up vote
0
down vote
My /etc/hosts:
127.0.0.1 localhost
127.0.1.1 *some-host*
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
So say:
sudo nano /etc/hosts
Add a line:
IPOFEXTHOST exthost
Where IPOFEXTHOST is the known ip of exthost.
From that point on you could write a script to update the file by replacing the line containing exthost.
No matter what though, one of the computers is going to have to have a dyndns or no-ip updater. So that either you know the web address of exthost directly or exthost can know your other computer's address to reverse ssh in and update the file with it's curl'ed public IP.
New contributor
Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
My /etc/hosts:
127.0.0.1 localhost
127.0.1.1 *some-host*
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
So say:
sudo nano /etc/hosts
Add a line:
IPOFEXTHOST exthost
Where IPOFEXTHOST is the known ip of exthost.
From that point on you could write a script to update the file by replacing the line containing exthost.
No matter what though, one of the computers is going to have to have a dyndns or no-ip updater. So that either you know the web address of exthost directly or exthost can know your other computer's address to reverse ssh in and update the file with it's curl'ed public IP.
New contributor
Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
answered Nov 21 at 13:04
Michael Prokopec
59315
59315
New contributor
Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Michael Prokopec is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f483167%2fuse-reference-to-file-instead-of-ip-in-etc-hosts%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Could you describe what you're trying to accomplish at a higher level as the
hostsfile predates DNS and as the question now stands it looks like you're trying to build your own DNS system using saidhostfile... Maybe Dynamic DNS is a solution, but we need to have more info.– Fabby
Nov 21 at 10:33
@Fabby I tried to better explain what I'm trying to do: question updated. Thanks! Yes, maybe it is a handcrafted, rudimentary DNS service. If
/etc/hostsfile is intended for static IP only, this could be not a proper use of it: I don't know the purpose of/etc/hostsvery well, so this is part of the question.– BowPark
Nov 21 at 10:49
Well, rAlen gave the answer I was going to give: there are free Dynymic DNS services out there (depending on your router brand, your router manufacturer might even provide you such a service for free)
– Fabby
Nov 21 at 11:27
@Fabby Thank you so much to both.
– BowPark
Nov 22 at 12:31