Mapping a range of IP's to a domain name in hosts file
Clash Royale CLAN TAG#URR8PPP
I work with Wi-Fi. Due to that my system's IP changes every time I connect to the network. For my work, I need to map my IP to a specific domain name. So, every day I need to make changes in my hosts file to update the IP. This is really annoying and I hope there must be a workaround.So, I need to add the range of IP's to that domain name in my hosts file. Is there a way to do it.
ubuntu networking osx dns hosts
add a comment |
I work with Wi-Fi. Due to that my system's IP changes every time I connect to the network. For my work, I need to map my IP to a specific domain name. So, every day I need to make changes in my hosts file to update the IP. This is really annoying and I hope there must be a workaround.So, I need to add the range of IP's to that domain name in my hosts file. Is there a way to do it.
ubuntu networking osx dns hosts
add a comment |
I work with Wi-Fi. Due to that my system's IP changes every time I connect to the network. For my work, I need to map my IP to a specific domain name. So, every day I need to make changes in my hosts file to update the IP. This is really annoying and I hope there must be a workaround.So, I need to add the range of IP's to that domain name in my hosts file. Is there a way to do it.
ubuntu networking osx dns hosts
I work with Wi-Fi. Due to that my system's IP changes every time I connect to the network. For my work, I need to map my IP to a specific domain name. So, every day I need to make changes in my hosts file to update the IP. This is really annoying and I hope there must be a workaround.So, I need to add the range of IP's to that domain name in my hosts file. Is there a way to do it.
ubuntu networking osx dns hosts
ubuntu networking osx dns hosts
asked Dec 21 '18 at 4:35
Khandekar Mohammad Saleh
61
61
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Most likely, you don't actually need to put your DHCP-assigned IP address in the hosts file. E.g., you probably want to be able to point a browser at http://your-domain-here/
and have your local web server respond to that. (Same with any other client/server setup). In which case — just map the domain to a localhost IP, which is any IP starting with 127.
(I'd avoid 127.0.0.1 as that might give weird answers for reverse lookups). Just pick a new one that isn't already in your hosts file.
Another option is just to pick a static RFC1918 space IP address (192.168.x.x, 10.x.x.x, 172.16–31.x.x) and add it to a local interface, then just use that IP address.
If you really do need have it mapped to your current IP address, there is typically somewhere you can put a shell script to run when your machine gets an IP address via DHCP. If you're using dhclient, you can put place a script in /etc/dhcp/dhclient-enter-hooks.d/
. There is a dhclient-script(8) manual page that documents it, but something like this (very untested) would probably work (it uses "sponge" from the moreutils package):
#!/bin/sh
MY_DOMAIN=your-domain.com
if [ "$reason" != "BOUND" ] && [ "$reason" != "REBIND" ]; then
exit 0
fi
grep -v " $MY_DOMAIN$" /etc/hosts | sponge /etc/hosts # really should escape the dots in the domain, but probably doesn't matter.
printf '%s %sn' "$new_ip_address" "$MY_DOMAIN" >> /etc/hosts
That's very untested. Make sure to have a backup of /etc/hosts
before trying that!
add a comment |
You write,
I work with Wi-Fi. Due to that my system's IP changes every time I connect to the network.
These two statements should not be connected. You IP address can be assigned manually to fixed value ("static" address) or it can be assigned dynamically by the DHCP server on the network ("dynamic" address). It doesn't matter whether your system connects with WiFi or with a cable; these are your two options for getting an IP address.
To add interest, the DHCP server might be configured to give you the same IP address each time you connect to its network (informally sometimes called a "sticky" address). This is how I have my home network set up.
You cannot (usually) use a static IP address if you are roaming across different networks, so a sticky address might be your best approach.
On the other hand, if all you need to do is to get a host entry in your domain to point to your client system you might want to look up Dynamic DNS providers. One example is dyn.com
but there are plenty of others to consider. You install a small piece of software on your client that captures any change in IP address, and notifies the central server. It updates your domain entry for you. The final piece of the puzzle is that you replace the A
record in your real domain with a CNAME
that points to the DDNS domain entry that points to your client system.
add a comment |
I would either write a script that loops through a list of IP addresses, adding each on a single line in your host file - as ranges are not supported, or - which is better in my opinion - host your web application on a virtual machine with a NAT or host-only adapter so it has a fixed IP address.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f490262%2fmapping-a-range-of-ips-to-a-domain-name-in-hosts-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Most likely, you don't actually need to put your DHCP-assigned IP address in the hosts file. E.g., you probably want to be able to point a browser at http://your-domain-here/
and have your local web server respond to that. (Same with any other client/server setup). In which case — just map the domain to a localhost IP, which is any IP starting with 127.
(I'd avoid 127.0.0.1 as that might give weird answers for reverse lookups). Just pick a new one that isn't already in your hosts file.
Another option is just to pick a static RFC1918 space IP address (192.168.x.x, 10.x.x.x, 172.16–31.x.x) and add it to a local interface, then just use that IP address.
If you really do need have it mapped to your current IP address, there is typically somewhere you can put a shell script to run when your machine gets an IP address via DHCP. If you're using dhclient, you can put place a script in /etc/dhcp/dhclient-enter-hooks.d/
. There is a dhclient-script(8) manual page that documents it, but something like this (very untested) would probably work (it uses "sponge" from the moreutils package):
#!/bin/sh
MY_DOMAIN=your-domain.com
if [ "$reason" != "BOUND" ] && [ "$reason" != "REBIND" ]; then
exit 0
fi
grep -v " $MY_DOMAIN$" /etc/hosts | sponge /etc/hosts # really should escape the dots in the domain, but probably doesn't matter.
printf '%s %sn' "$new_ip_address" "$MY_DOMAIN" >> /etc/hosts
That's very untested. Make sure to have a backup of /etc/hosts
before trying that!
add a comment |
Most likely, you don't actually need to put your DHCP-assigned IP address in the hosts file. E.g., you probably want to be able to point a browser at http://your-domain-here/
and have your local web server respond to that. (Same with any other client/server setup). In which case — just map the domain to a localhost IP, which is any IP starting with 127.
(I'd avoid 127.0.0.1 as that might give weird answers for reverse lookups). Just pick a new one that isn't already in your hosts file.
Another option is just to pick a static RFC1918 space IP address (192.168.x.x, 10.x.x.x, 172.16–31.x.x) and add it to a local interface, then just use that IP address.
If you really do need have it mapped to your current IP address, there is typically somewhere you can put a shell script to run when your machine gets an IP address via DHCP. If you're using dhclient, you can put place a script in /etc/dhcp/dhclient-enter-hooks.d/
. There is a dhclient-script(8) manual page that documents it, but something like this (very untested) would probably work (it uses "sponge" from the moreutils package):
#!/bin/sh
MY_DOMAIN=your-domain.com
if [ "$reason" != "BOUND" ] && [ "$reason" != "REBIND" ]; then
exit 0
fi
grep -v " $MY_DOMAIN$" /etc/hosts | sponge /etc/hosts # really should escape the dots in the domain, but probably doesn't matter.
printf '%s %sn' "$new_ip_address" "$MY_DOMAIN" >> /etc/hosts
That's very untested. Make sure to have a backup of /etc/hosts
before trying that!
add a comment |
Most likely, you don't actually need to put your DHCP-assigned IP address in the hosts file. E.g., you probably want to be able to point a browser at http://your-domain-here/
and have your local web server respond to that. (Same with any other client/server setup). In which case — just map the domain to a localhost IP, which is any IP starting with 127.
(I'd avoid 127.0.0.1 as that might give weird answers for reverse lookups). Just pick a new one that isn't already in your hosts file.
Another option is just to pick a static RFC1918 space IP address (192.168.x.x, 10.x.x.x, 172.16–31.x.x) and add it to a local interface, then just use that IP address.
If you really do need have it mapped to your current IP address, there is typically somewhere you can put a shell script to run when your machine gets an IP address via DHCP. If you're using dhclient, you can put place a script in /etc/dhcp/dhclient-enter-hooks.d/
. There is a dhclient-script(8) manual page that documents it, but something like this (very untested) would probably work (it uses "sponge" from the moreutils package):
#!/bin/sh
MY_DOMAIN=your-domain.com
if [ "$reason" != "BOUND" ] && [ "$reason" != "REBIND" ]; then
exit 0
fi
grep -v " $MY_DOMAIN$" /etc/hosts | sponge /etc/hosts # really should escape the dots in the domain, but probably doesn't matter.
printf '%s %sn' "$new_ip_address" "$MY_DOMAIN" >> /etc/hosts
That's very untested. Make sure to have a backup of /etc/hosts
before trying that!
Most likely, you don't actually need to put your DHCP-assigned IP address in the hosts file. E.g., you probably want to be able to point a browser at http://your-domain-here/
and have your local web server respond to that. (Same with any other client/server setup). In which case — just map the domain to a localhost IP, which is any IP starting with 127.
(I'd avoid 127.0.0.1 as that might give weird answers for reverse lookups). Just pick a new one that isn't already in your hosts file.
Another option is just to pick a static RFC1918 space IP address (192.168.x.x, 10.x.x.x, 172.16–31.x.x) and add it to a local interface, then just use that IP address.
If you really do need have it mapped to your current IP address, there is typically somewhere you can put a shell script to run when your machine gets an IP address via DHCP. If you're using dhclient, you can put place a script in /etc/dhcp/dhclient-enter-hooks.d/
. There is a dhclient-script(8) manual page that documents it, but something like this (very untested) would probably work (it uses "sponge" from the moreutils package):
#!/bin/sh
MY_DOMAIN=your-domain.com
if [ "$reason" != "BOUND" ] && [ "$reason" != "REBIND" ]; then
exit 0
fi
grep -v " $MY_DOMAIN$" /etc/hosts | sponge /etc/hosts # really should escape the dots in the domain, but probably doesn't matter.
printf '%s %sn' "$new_ip_address" "$MY_DOMAIN" >> /etc/hosts
That's very untested. Make sure to have a backup of /etc/hosts
before trying that!
answered Dec 21 '18 at 8:57
derobert
72.1k8152210
72.1k8152210
add a comment |
add a comment |
You write,
I work with Wi-Fi. Due to that my system's IP changes every time I connect to the network.
These two statements should not be connected. You IP address can be assigned manually to fixed value ("static" address) or it can be assigned dynamically by the DHCP server on the network ("dynamic" address). It doesn't matter whether your system connects with WiFi or with a cable; these are your two options for getting an IP address.
To add interest, the DHCP server might be configured to give you the same IP address each time you connect to its network (informally sometimes called a "sticky" address). This is how I have my home network set up.
You cannot (usually) use a static IP address if you are roaming across different networks, so a sticky address might be your best approach.
On the other hand, if all you need to do is to get a host entry in your domain to point to your client system you might want to look up Dynamic DNS providers. One example is dyn.com
but there are plenty of others to consider. You install a small piece of software on your client that captures any change in IP address, and notifies the central server. It updates your domain entry for you. The final piece of the puzzle is that you replace the A
record in your real domain with a CNAME
that points to the DDNS domain entry that points to your client system.
add a comment |
You write,
I work with Wi-Fi. Due to that my system's IP changes every time I connect to the network.
These two statements should not be connected. You IP address can be assigned manually to fixed value ("static" address) or it can be assigned dynamically by the DHCP server on the network ("dynamic" address). It doesn't matter whether your system connects with WiFi or with a cable; these are your two options for getting an IP address.
To add interest, the DHCP server might be configured to give you the same IP address each time you connect to its network (informally sometimes called a "sticky" address). This is how I have my home network set up.
You cannot (usually) use a static IP address if you are roaming across different networks, so a sticky address might be your best approach.
On the other hand, if all you need to do is to get a host entry in your domain to point to your client system you might want to look up Dynamic DNS providers. One example is dyn.com
but there are plenty of others to consider. You install a small piece of software on your client that captures any change in IP address, and notifies the central server. It updates your domain entry for you. The final piece of the puzzle is that you replace the A
record in your real domain with a CNAME
that points to the DDNS domain entry that points to your client system.
add a comment |
You write,
I work with Wi-Fi. Due to that my system's IP changes every time I connect to the network.
These two statements should not be connected. You IP address can be assigned manually to fixed value ("static" address) or it can be assigned dynamically by the DHCP server on the network ("dynamic" address). It doesn't matter whether your system connects with WiFi or with a cable; these are your two options for getting an IP address.
To add interest, the DHCP server might be configured to give you the same IP address each time you connect to its network (informally sometimes called a "sticky" address). This is how I have my home network set up.
You cannot (usually) use a static IP address if you are roaming across different networks, so a sticky address might be your best approach.
On the other hand, if all you need to do is to get a host entry in your domain to point to your client system you might want to look up Dynamic DNS providers. One example is dyn.com
but there are plenty of others to consider. You install a small piece of software on your client that captures any change in IP address, and notifies the central server. It updates your domain entry for you. The final piece of the puzzle is that you replace the A
record in your real domain with a CNAME
that points to the DDNS domain entry that points to your client system.
You write,
I work with Wi-Fi. Due to that my system's IP changes every time I connect to the network.
These two statements should not be connected. You IP address can be assigned manually to fixed value ("static" address) or it can be assigned dynamically by the DHCP server on the network ("dynamic" address). It doesn't matter whether your system connects with WiFi or with a cable; these are your two options for getting an IP address.
To add interest, the DHCP server might be configured to give you the same IP address each time you connect to its network (informally sometimes called a "sticky" address). This is how I have my home network set up.
You cannot (usually) use a static IP address if you are roaming across different networks, so a sticky address might be your best approach.
On the other hand, if all you need to do is to get a host entry in your domain to point to your client system you might want to look up Dynamic DNS providers. One example is dyn.com
but there are plenty of others to consider. You install a small piece of software on your client that captures any change in IP address, and notifies the central server. It updates your domain entry for you. The final piece of the puzzle is that you replace the A
record in your real domain with a CNAME
that points to the DDNS domain entry that points to your client system.
answered Dec 21 '18 at 9:31
roaima
42.8k551116
42.8k551116
add a comment |
add a comment |
I would either write a script that loops through a list of IP addresses, adding each on a single line in your host file - as ranges are not supported, or - which is better in my opinion - host your web application on a virtual machine with a NAT or host-only adapter so it has a fixed IP address.
add a comment |
I would either write a script that loops through a list of IP addresses, adding each on a single line in your host file - as ranges are not supported, or - which is better in my opinion - host your web application on a virtual machine with a NAT or host-only adapter so it has a fixed IP address.
add a comment |
I would either write a script that loops through a list of IP addresses, adding each on a single line in your host file - as ranges are not supported, or - which is better in my opinion - host your web application on a virtual machine with a NAT or host-only adapter so it has a fixed IP address.
I would either write a script that loops through a list of IP addresses, adding each on a single line in your host file - as ranges are not supported, or - which is better in my opinion - host your web application on a virtual machine with a NAT or host-only adapter so it has a fixed IP address.
answered Dec 21 '18 at 7:46
Tom
1217
1217
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f490262%2fmapping-a-range-of-ips-to-a-domain-name-in-hosts-file%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