How to redirect a URL to another URL using /etc/hosts
What you are trying to do is not possible. Well, at least not how you are trying to do it.
In your desired URL (https://i.imgur.com/6FxzzCT.png
), only this part has a specific IP address: i.imgur.com
.
$ dig +short i.imgur.com
151.101.16.193
In a simplified form, when you enter that whole link in your browser (https://i.imgur.com/6FxzzCT.png
). You are sending a request to 151.101.16.193
asking for 6FxzzCT.png
file using HTTPS protocol.
Using /etc/hosts
you can only set predefined IP addresses per hosts but you can't handle HTTP requests.
What you might be able to do is to run a simple HTTP server on localhost
serving a picture or a random picture at index.html
or whatever predefined default page. Then redirect every site you like to 127.0.0.1
using /etc/hosts
. Now your page is waiting there to bring up some random picture.
Heisenberg
Updated on September 18, 2022Comments
-
Heisenberg over 1 year
I want to block some sites on my ubuntu system.So, I added some lines to the
/etc/hosts
, which are127.0.1.1 www.reddit.com 127.0.1.1 www.facebook.com
This now successfully blocks the website but I want to redirect to another URL when I go to one of the URL I mentioned above, I found that you need to change the
127.0.1.1
toIP of website
to make it work but I can't convert URL such as https://i.imgur.com/6FxzzCT.png to IP address.It would be really helpful if someone can let be convert any URL to IP address.