LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 07-15-2013, 09:52 PM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
Preferred settings for /etc/hosts


I have a residential router connected to two CentOS servers and the Internet, and myDomain.com points to my router's public IP.

Is there anything else I should add to /etc/sysconfig/network?

What is the purpose of /etc/hosts, and giving my configuration, should I change it?

Thank you

PS. Don't know if it is relevant, but desktop communicates using wlan0 and laptop communicates using eth0.

Code:
[root@desktop ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=desktop.myDomain.com

[root@desktop ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[root@desktop ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 88:51:FB:51:DF:70
          inet addr:192.168.0.202  Bcast:192.168.0.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

wlan0     Link encap:Ethernet  HWaddr B8:76:3F:69:31:95
          inet addr:192.168.0.104  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::ba76:3fff:fe69:3195/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:13547 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6620 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2846258 (2.7 MiB)  TX bytes:1298853 (1.2 MiB)

[root@desktop ~]#
Code:
[root@laptop ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=laptop.myDomain.com

[root@laptop ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[root@laptop ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1C:23:1E:8B:00
          inet addr:192.168.0.201  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:23ff:fe1e:8b00/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4042 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1454 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:324360 (316.7 KiB)  TX bytes:328752 (321.0 KiB)
          Interrupt:17

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:34 errors:0 dropped:0 overruns:0 frame:0
          TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:2412 (2.3 KiB)  TX bytes:2412 (2.3 KiB)

virbr0    Link encap:Ethernet  HWaddr 52:54:00:12:38:1C
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

wlan0     Link encap:Ethernet  HWaddr 00:1E:4C:9A:95:AE
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

[root@laptop ~]#
 
Old 07-15-2013, 10:36 PM   #2
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,734
Blog Entries: 28

Rep: Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277
This wikipedia article gives a pretty good summary of the history and uses of a hosts file.

https://en.wikipedia.org/wiki/Hosts_(file)

The only essential entry in most contemporary uses is the loopback address (commonly 127.0.0.1).

If you want to use it to block internet redirects (as "ad.doubleclick.net") this link will help. I prefer this method to running adblock browser add-ons, because it uses minimal CPU cycles and is browser-independent.

Last edited by frankbell; 07-15-2013 at 10:41 PM. Reason: grammar
 
Old 07-15-2013, 10:52 PM   #3
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Original Poster
Rep: Reputation: Disabled
Thanks Frank,

So, my /etc/hosts file lists a bunch of localhostX and localdomainX. Do I want to change any of these to desktop or laptop and myDomain.com?

PS. Anyone clicking the link, be sure to add a ) to the url.
 
Old 07-15-2013, 11:44 PM   #4
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,734
Blog Entries: 28

Rep: Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277Reputation: 6277
I would say that, if it's working, there's no reason to change anything.

If you want to test some new settings, be sure to save the original so you can restore it if necessary.

If you would like us to look at your hosts file, just post it, being sure to surround it with "code" tags, which become available when you click the "Go Advanced" button at the bottom of the quick reply window. Seeing the file, or at least a portion of it, would make it easier to answer your question.

Here's mine from Debian Wheezy:

Code:
~$ cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 tuna.bell.org tuna.bell.org

# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
127.0.0.1 tuna # added by Apache Friends XAMPP
bell.org is strictly internal to my home network and I name all my computers after denizens of the sea.

I'm not using IPv6, but Debian added that section, probably during the last dist-upgrade, because I know I didn't.

Last edited by frankbell; 07-15-2013 at 11:52 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Access denied for NFS - but hosts.allow and hosts.deny seem OK royce2020 Linux - Networking 4 10-17-2011 11:44 PM
Script for hosts, numbers of hosts and users connected to squid server arunabh_biswas Programming 5 08-28-2010 05:11 AM
Verify /etc/hosts usage and round robin in /etc/hosts MikeyCarter Linux - Software 1 06-24-2008 01:20 PM
can't restrict sshd access through hosts.allow and hosts.deny but was working earlier farhan Linux - Security 4 04-18-2008 08:41 AM
/etc/hosts.deny/hosts.allow have no effect on sshd access bganesh Linux - Security 4 05-04-2006 09:06 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration