What's new

Managing Local Hosts File Suggestions

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

davewolfs

Regular Contributor
Hello all,

I would like to maintain a local hosts file that persists through router restarts. Should I just be updating the hosts file via the JFFS file system, or am I better off linking the additional hosts to a hosts file on my USB Mount. My concern for doing this on JFFS is the writes taking place on flash memory.

Any suggestions? Should I even care about periodically modifying files on the JFFS file system?

Thanks!
 
Unless you are going to be updating your hosts file multiple times a day, every day then placing it on the JFFS will be fine.
 
Ended up adding a simple dnsmasq.postconf to my jffs/scripts folder.


Code:
#!/bin/sh
CONFIG=$1
HOSTS_PATH=/tmp/mnt/KINGSTON/config
source /usr/sbin/helper.sh
cp /etc/hosts.dnsmasq $HOSTS_PATH
cat $HOSTS_PATH/hosts >> $HOSTS_PATH/hosts.dnsmasq

pc_replace "addn-hosts=/etc/hosts.dnsmasq" "addn-hosts=$HOSTS_PATH/hosts.dnsmasq" $CONFIG

Also seems like it can be done even easier with the hosts.postconf

Code:
#!/bin/sh
HOSTS_PATH=/tmp/mnt/KINGSTON/config
cat /$HOSTS_PATH/hosts >> /etc/hosts
 
Last edited:
You can also accomplish this with the file /jffs/configs/dnsmasq.conf.add
and add to it (no shebang needed)
Code:
addn-hosts=/tmp/mnt/KINGSTON/config
If you are blocking hosts with this you can autoupdate it.
 
You can also accomplish this with the file /jffs/configs/dnsmasq.conf.add
and add to it (no shebang needed)
Code:
addn-hosts=/tmp/mnt/KINGSTON/config
If you are blocking hosts with this you can autoupdate it.

Hello,

Should that not read:

addn-hosts=/tmp/mnt/KINGSTON/config/nameof.file

Where nameof.file is the name of the hosts file to read?

Thanks
Sam
 
Should that not read:
addn-hosts=/tmp/mnt/KINGSTON/config/nameof.file
Where nameof.file is the name of the hosts file to read?
Whatever the path/filename of your additional hosts file is will be YOUR setting.
 
Hello,

I must be missing something because I can't seem to get it to work, I have created the add file.

uname@RT-AC66U:/jffs/configs# ls -la
drwxr-xr-x 2 uname root 0 Apr 17 16:52 .
drwxr-xr-x 5 uname root 0 Apr 17 17:00 ..
-rw-rw-rw- 1 uname root 47 Apr 17 16:52 dnsmasq.conf.add

sbarr@RT-AC66U:/jffs/configs# cat dnsmasq.conf.add
addn-hosts=/tmp/mnt/BLANK/config/myhosts.file

uname@RT-AC66U:/tmp/mnt/BLANK/config# ls -la
drwxrwxrwx 2 uname root 2048 Apr 17 2014 .
drwxrwxrwx 3 uname root 16384 Jan 1 2011 ..
-rwxrwxrwx 1 uname root 56 Apr 17 17:00 myhosts.file

uname@RT-AC66U:/tmp/mnt/BLANK/config# cat myhosts.file
0.0.0.2 gateway.specialdomain.com
0.0.0.2 diskstation

These are not pinging....

uname@RT-AC66U:/tmp/mnt/BLANK/config# ping diskstation
ping: bad address 'diskstation'
 
Last edited:
hmm it does seem to be reading the file.

Apr 17 17:16:45 dnsmasq-dhcp[564]: DHCP, IP range 0.0.0.0 -- 0.0.0.254, lease time 1d
Apr 17 17:16:45 dnsmasq-dhcp[564]: DHCP, sockets bound exclusively to interface br0
Apr 17 17:16:45 dnsmasq[564]: read /etc/hosts - 5 addresses
Apr 17 17:16:45 dnsmasq[564]: read /tmp/mnt/BLANK/config/myhosts.file - 2 addresses
Apr 17 17:16:45 dnsmasq[564]: using nameserver 212.159.6.10#53
Apr 17 17:16:45 dnsmasq[564]: using nameserver 212.159.6.9#53
 
These are not pinging....
Better do it that way, directly in dnsmasq.conf.add:
Code:
address=/gateway.specialdomain.com/10.0.1.2
address=/diskstation/10.0.1.2
 
Better do it that way, directly in dnsmasq.conf.add:
Code:
address=/gateway.specialdomain.com/10.0.1.2
address=/diskstation/10.0.1.2

Hello,

That doesn't seem to work either, plus I would rather not be editing files in the jffs partition too much.

Any other ideas?

-Sam
 
That doesn't seem to work either, plus I would rather not be editing files in the jffs partition too much.
Any other ideas?
-Sam
It'll take more than occasional editing of /jffs/ files to wear it out. Don't worry too much about the warning.
You have to restart dnsmasq to get your settings read by dnsmasq:
Code:
service restart_dnsmasq
or
Code:
reboot
Flush your DNS Cache on Windows:
Code:
ipconfig/flushdns
 
Hello,

Yep already tried the reboot and the service restart, the problem is even afterwards the hostnames are not pingable via the router.

uname@RT-AC66U:/tmp/home/root# ping diskstation
ping: bad address 'diskstation'

-Sam
 
Hang on Sam, this is a special case.
 
Yep already tried the reboot and the service restart, the problem is even afterwards the hostnames are not pingable via the router.
uname@RT-AC66U:/tmp/home/root# ping diskstation
ping: bad address 'diskstation'
Best way for you would be to add your diskstation to the LAN / DHCP Server Manually assigned DHCP list in your router.
gateway.specialdomain.com will work in dnsmasq.conf.add but
diskstation not. This is because dnsmasq will interpret a single name as tld as in whatever.diskstation
Capisce?
 
I've been following this thread and wondering all along: why not simply create /jffs/configs/hosts.add and you're done? What did I miss?
 
I've been following this thread and wondering all along: why not simply create /jffs/configs/hosts.add and you're done? What did I miss?
Depends on what you want to do. You can do a lot more with dnsmasq.conf.add than just the hosts file. Thats why I suggested to use it.
 
Hello,

Something still isn't right, I have added a totally duff (non existent domain) into the custom hosts file and tried to ping it from the router and it doesn't work.

Now if I put it in the default /etc/hosts it pings fine it just doesn't seem to work if I put it in my custom hosts file.

-Sam
 
Hello,

Something still isn't right, I have added a totally duff (non existent domain) into the custom hosts file and tried to ping it from the router and it doesn't work.

Now if I put it in the default /etc/hosts it pings fine it just doesn't seem to work if I put it in my custom hosts file.

-Sam
Check your paths, syntax, I dont know. This is simple stuff. It works.
 
Hello,

It couldn't be anything to do with the fact that I am not using the default admin username could it?

Thanks
Sam
 
It couldn't be anything to do with the fact that I am not using the default admin username could it?
No, this has nothing to do with it.
 

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top