Adding internal host names to DNS or /etc/hosts [SOLVED]

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Author Message
evan
DD-WRT Novice


Joined: 17 Jun 2012
Posts: 2

PostPosted: Sun Jun 17, 2012 7:17    Post subject: Adding internal host names to DNS or /etc/hosts [SOLVED] Reply with quote
I want to add some local host names for my local network.

I tried adding them to /etc/hosts in my DD-WRT, which works, but the changes are lost on restart.

Is there anyway to do more permanently?

Thanks


Last edited by evan on Fri Jun 22, 2012 3:46; edited 1 time in total
Sponsor
Luniz2k1
DD-WRT Guru


Joined: 04 Oct 2007
Posts: 1258
Location: Ohio USA

PostPosted: Mon Jun 18, 2012 14:02    Post subject: Re: Adding internal host names to DNS or /etc/hosts Reply with quote
evan wrote:
I want to add some local host names for my local network.

I tried adding them to /etc/hosts in my DD-WRT, which works, but the changes are lost on restart.

Is there anyway to do more permanently?

Thanks

Administration -> Commands, Command shell box put:
Code:
echo '' > /etc/hosts
echo '127.0.0.1     localhost' >> /etc/hosts
echo '192.168.1.1     some.local.hostname' >> /etc/hosts

Then click Save Startup

_________________
(05/02/17) std - 31924
Linksys WRT400N
Buffalo WHR-G300N

Got OpenDNS?
evan
DD-WRT Novice


Joined: 17 Jun 2012
Posts: 2

PostPosted: Fri Jun 22, 2012 3:45    Post subject: Reply with quote
Thanks, that almost did the job.

Didn't need the "echo '' > /etc/hosts" to clobber the initial file. Just wanted to append to it.

Also, need to add "restart_dns" after the echo commands to make it reload and the changes to take effect.

So my startup script looks like:

Code:

echo '192.168.1.1 some.local.hostname' >> /etc/hosts
echo '192.168.1.2 another.local.hostname' >> /etc/hosts
restart_dns


E.
volitation
DD-WRT User


Joined: 30 Dec 2011
Posts: 91

PostPosted: Mon Jun 25, 2012 10:33    Post subject: Reply with quote
This can be done in dnsmasq also (Services > Additional DNSMasq Options).

Code:

address=/some.local.hostname/192.168.1.1
address=/another.local.hostname/192.168.1.2
addn-hosts=/some/file/somewhere


Then create /some/file/somewhere and add the following

Code:

192.168.1.1 some.local.hostname
192.168.1.2 another.local.hostname


My addn-hosts file is saved on the USB stick. It should also be possible to put it on jffs if you don't have a USB port.

This way your local hostnames will resolve to their IPs, and those IPs will also reverse resolve into your local hostnames.

Note: addn-hosts is optional.
rjt
DD-WRT Novice


Joined: 10 Aug 2006
Posts: 22
Location: Omaha

PostPosted: Sun Jul 29, 2012 20:19    Post subject: Reply with quote
Thank you, this worked for saving aliased dns names across reboots without an extra hosts file!

address=/uranos/uranos.my.ip.net./192.168.1.139
address=/mythtv/mythtv.my.ip.net./192.168.1.6
address=/firewall/firewall.my.ip.net/192.168.1.1
stepram
DD-WRT Novice


Joined: 13 May 2019
Posts: 2

PostPosted: Thu Jan 02, 2020 22:08    Post subject: Redirect google urls Reply with quote
I use DD-WRT at home and have some young kids. The time has come to restrict some youtube access.

I tried the cname route with the following in DNSMASQ
--cname=www.google.com,forcesafesearch.google.com
--cname=www.youtube.com,m.youtube.com,youtubei.googleapis.com,youtube.googleapis.com,www.youtube-nocookie.com,restrict.youtube.com

however as per thread here the cname Function dose not work. https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=704052

Therefore I was directed here and tried:
echo '' > /etc/hosts
echo '127.0.0.1 localhost' >> /etc/hosts
echo '216.239.38.120 www.google.com' >> /etc/hosts

However, this does not redirect the Google search to safe search only.

Google instructions here: https://support.google.com/websearch/answer/186669?hl=en

and here: https://support.google.com/a/answer/6214622?visit_id=637135970381628754-1488549170&rd=1

Any advice welcome.

Firmware: DD-WRT v3.0-r37305 std (10/10/1Cool on Netgear R7000
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum