OPNsense Forum

Archive => 18.1 Legacy Series => Topic started by: nycaleksey on July 17, 2018, 06:13:43 pm

Title: /etc/hosts modifications
Post by: nycaleksey on July 17, 2018, 06:13:43 pm
Hi,

Is there any way to edit /etc/hosts entries via UI? I know, similar functionality exists when enabling Unbound or DNSMasq, but I am using neither and just need to alter name resolution on the firewall for one hostname.

Thank you.
Title: Re: /etc/hosts modifications
Post by: JasMan on July 18, 2018, 08:00:24 am
As far as I know there's no point in the GUI where you can modify the hosts file.

I'm not an Linux expert, but maybe you can do it with a cron job:

echo "127.0.0.1       name.tld" >> /etc/hosts
Title: Re: /etc/hosts modifications
Post by: franco on July 19, 2018, 12:29:09 am
So.... if you don't use Unbound or Dnsmasq /etc/hosts is only for the firewall itself. Why do you need to modify one entry for the firewall itself?


Cheers,
Franco
Title: Re: /etc/hosts modifications
Post by: nycaleksey on July 19, 2018, 10:13:18 pm
Franco,

I am migrating Squid web proxy functionality from a Linux server to OPNsense, and on the old Linux-based proxy /etc/hosts is used for a dirty one-off URL rewriting hack (certain hostname in the host portion of the URL needs to always be resolved by the proxy to specific IP, no matter what DNS points to).
I know I can probably do it in the squid.conf somehow, but just wanted to copy the existing functionality as-is, and optimize it later.

JasMan, thanks for the cron trick, it worked for now, although I would prefer a cleaner interface.
Title: Re: /etc/hosts modifications
Post by: franco on July 20, 2018, 12:42:06 am
Thanks for the clarification. From ease of integration point of view it's best to use Dnsmasq for this. It's cheap and fast.

You said you don't use it, but have the perfect use case for it. I would encourage you to try it instead of editing /etc/hosts.

Another way would be patching the code to always inject that entry, but that is lost on updates so then needs to be reapplied.


Cheers,
Franco