PDA

View Full Version : Problem with hostnames


zackr
2006-06-13, 02:16 AM CDT
I've been looking for a solution to this particular problem for ages.

I have four computers on a router which has static IP connection to the modem and doubles as a DHCP server for the local network.

Currently I have my Linux machine set up to retrieve an IP address via DHCP from that router. However, this is where the fun starts. I have edited my /etc/hosts file by adding the word 'dev' like so:

127.0.0.1 dev localhost.localdomain localhost

However, which it works fine on the Linux machine itself, I cannot get on any other machine and type 'dev' into the browser. Instead I am still forced to use the DHCP IP address of the Linux machine which changes from time to time and is quite annoying to type out all the time.

Any help would be much appreciated! It should be able to work even when it has a DHCP address because I was using a Mandriva installation which worked perfectly (though automatically) for me.

liro
2006-06-13, 02:32 AM CDT
with /etc/hosts (in linux) you setup a very simple dns lookup (not dns as it is). but the resource file is only on your machine...so any other machine in your network doesn't have this information.

copy your (manually) created hostfile to each system (but remove the dev entry on 127.0.0.1, this is the loopback interface...) setup an entry for your ip...

for example:

192.168.0.1 dev1 yourothernameforthismachine
192.168.0.2 dev2 yourothernameforthismachine
...

this file you can then use in your network (but every machine has to have it).

your problem now is, that your ip is dynamically setup by dhcp.
in this case, you can setup a virtual device....you can simply do this either via system-config-network-gui or direct in the /etc/sysconfig/network-scripts/ (copy the interface definition and rename to ifcfg-ethX:1, and edit it to a static ip address).

then update your hosts file and distribute to your clients (by the way in win the file is located in %windir%\system32\drivers\hosts)

cheers liro

zackr
2006-06-13, 03:54 AM CDT
Thank you! It looks as if it just might work!

...once I figure out how to activate the virtual device.

Currently, this is what I have, with some comments (//) to explain what's currently happening.

file: ifcfg-eth0:1

TYPE=Ethernet
DEVICE=eth0:0
BOOTPROTO=none
NETMASK=255.255.255.0 // This is exactly the same as the real device. Should it be different?
IPADDR=192.168.0.1 // DHCP IP is currently 192.168.1.6
USERCTL=no
IPV6INIT=no
PEERDNS=yes
HWADDR=(MAC Address here from the real device)
ONPARENT=no

It refuses to activate. Its nickname is eth0:0, and it is set as device eth0:0. However, the real device is eth0 and its nickname is eth0.

Any pointers?

Just quickly, the windows host file on my other machine includes:

192.168.0.1 dev

As does the /etc/hosts file in Fedora. I tested that ping worked, but while it pings 192.168.0.1 it obviously can't connect due to the Linux machine not getting it.

liro
2006-06-13, 04:33 AM CDT
its a simple fault: your config file named ifcfg-eth0:1 references a config to eth0:0...just edit the line

DEVICE=eth0:0

to

DEVICE=eth0:1

and it should work!


and keep in mind: never set manually an ip of the same subnet, that the dhcp server is serving...(but you did correct, just a note)

zackr
2006-06-13, 04:53 AM CDT
I tried that, but it still refuses to work.

The error message it gives is: Could not find information on interface 'eth0:1' in /proc/net/dev

Is there still something I'm missing?

zackr
2006-06-14, 03:46 AM CDT
Hey, anybody out there? I really need help getting this working. I have completed everything per Liro's instructions. I'll give a step by step of what I did - maybe I messed something up along the way.

Background information: currently the network uses IP addresses such as 192.168.1.x NOTE THE 1. The next lot of IPs I'm using has a 0 instead. The network is based on four machines, but the ones I'm worried about are the Windows machine and the Fedora machine.

1. I added the following line to the Windows hosts file on my Windows machine:

192.168.0.1 dev

I checked that when pinging 'dev' it looked for 192.168.0.1, which was correct. However, it times out.

2. I then went to the Linux box and added the exact same line in the hosts file (etc/hosts)

3. After that I crearted the virtual device on the Linux box only. I called it dev0:1 and named the file appropriately. It is activated, and when using 192.168.0.1 or 'dev' on that machine it goes to the right page (of course). It uses the static IP 192.168.0.1 and though the netmask is exactly the same as the original network.

4. I then put 'dev' in my Windows machine. It still refused to ping. Now, what I want to know is how on earth I can get my Linux machine to act like a DNS server??? It also is on a DHCP IP. It's just that I've done everything Liro said but it's missing the last step - how do I get the machine to ACT like a DNS server???

liro
2006-06-14, 05:16 AM CDT
hy zackr

i'm sorry, i gave you a wrong recommendation. you should use eth0 as device (cause it uses the same hardware device)...

your problem is only located on setting up the virutal device, the rest is ok so. try setting DEVICE=eth0 in your config file, then start with ifup eth0:X -> where X is the number you gave...


liro

zackr
2006-06-14, 05:39 AM CDT
Thanks! It worked! Well, it does sort of.

Now both the devices are listed as active and the error is no longer showing. However, it seems to have over-ridden the DHCP! It now shows the device as address 192.168.0.1, instead of 192.168.1.x!

What do i do now??? It is no longer connected to the network!

liro
2006-06-15, 01:11 AM CDT
from which device are you talking now? cause if all went ok, you should have your eht0 device (dhcp) and a new eth0:1 one, which has setup a manual ipaddress...

you did make a copy of your ifcfg file, didn't you? a 'ls -l /etc/sysconfig/network-scripts/ifcfg-eth*' should give you 2 interface configs...

OK, so lets start over and begin step by step:

first, edit your ifcfg-eth0 config file to be DHCP-Client:


DEVICE=eth0
BOOTPROTO=dhcp
HWADDR=[HW-ADDRESS]
ONBOOT=yes
DHCP_HOSTNAME=[DHCPhostname, optionally]
TYPE=Ethernet


then make a copy and edit the new config to this 'cd /etc/sysconfig/network-scripts; cp ifcfg-eth0 ifcfg-eth0:1; vi ifcfg-eth0:1':


DEVICE=eth0:1
HWADDR=[same HW-ADDRESS as above]
IPADDR=[your ip, not in dhcp range]
NETMASK=255.255.255.0
ONBOOT=yes
TYPE=Ethernet


then, stop eth0 and start it again.

ifdown eth0;sleep 3;ifup eth0

i know, i wrote something wrong above....i didn't had access to a linux machine a this time. but this is the config where all is working fine on my FC5 machine....

you can't activate eth0:1 or so, you simply control eth0 (your real device), which setups two virtual devices...

Omega Blue
2006-06-15, 03:47 AM CDT
I have edited my /etc/hosts file by adding the word 'dev' like so:

127.0.0.1 dev localhost.localdomain localhost

However, which it works fine on the Linux machine itself, I cannot get on any other machine and type 'dev' into the browser.

127.0.0.1 is the loopback address. It automatically points to your own box, thus, it is not possible to use it to point to a remote node.

liro
2006-06-15, 06:32 AM CDT
127.0.0.1 is the loopback address. It automatically points to your own box, thus, it is not possible to use it to point to a remote node.


this is why we're dealing with the virutal devices :)

Omega Blue
2006-06-16, 02:34 AM CDT
I reckon it's easier to use static IP for a small network. Makes life simpler (DNS, NFS, etc.)

stevea
2006-06-16, 04:16 AM CDT
Liro is leading you down the wrong path. Listen to Blue_Omega.

*IF* you use dhcp and *if* you let the dhcp server assign random
(variable) IP addresses to each system then you *must* use some
other method of determining the current IP address assignment of
each system so they can communicate. The standard solution is to
use DNS. A DNS server basically keeps a dynamically updated table
of system names and IP addresses - just like /etc/hosts except dynamic.
When you try to access a system by name , you first look in your local
/etc/hosts for that name, and if that fails you ask any DNS servers for
help.

O_Blue is right - the simple solution is to turn off the dhcp server and
assigin fixed IP addresses to each system (in the ifcdg-eth0 file). Then
enter each fixed IP into an /etc/hosts file and copy this same hosts file
to each system.

'localhost' or any other name that resolves to 127.0.0.1 can only refer to
the local system. Yo uneed entries like
192.168.0.2 fred
192.168.0.3 ethel
...

liro
2006-06-16, 05:05 AM CDT
hey guy's you're absolutely right with your answers...but have you read the whole thread?

we're trying to setup a virtual address with manual ipaddresse beside the dhcp interface.....so zakcr doesn't need to setup a whole dnsserver, dhcpserver...and can leave the whole network as it is...

just by adding a virtual interface with a manual ip-address you can everytime refer to the same ipaddress in a dhcp managed zone....

stevea
2006-06-16, 07:31 PM CDT
hey guy's you're absolutely right with your answers...but have you read the whole thread?

we're trying to setup a virtual address with manual ipaddresse beside the dhcp interface....

No Liro - YOU are trying to set up a VLAN. A complex solution to this basic problem. You are not wrong, but the original question was to correctly resolve IPs, not to use a basic router's DHCP assignments at all costs.

Clearly the simple direct solution is to used fixed IPs and a /etc/hosts files. That is exactly what you are doing on the VLAN, but why have the VLAN at all when he can do this with the hardware interfaces ? Yours is an extravagant solution.

liro
2006-06-18, 07:53 AM CDT
ok, my opinion differs a bit from yours...but lets agree to a solution between our posts...
my opionion is, for this problem there are these 3 scenarios:

1. setup an own, dhcp/dns server with dynamic dns update - absolutely not requested for this problem here...(for unexperienced users)

2. setting up a vlan over the dhcp and usage of hosts-file (compared with solution 3, a bit more complex but the lan is still the same, no change - which is some times quite useful).

3. setting up the whole lan with fix ipaddresses and usage of hosts-file....the simplest way...here i absolutely agree with you.


but still, I WOULD NOT say that solution 2 is 'leading down to wrong path'...but anyway...

cheers liro

stevea
2006-07-17, 07:04 PM CDT
ok, my opinion differs a bit from yours...but lets agree to a solution between our posts...
my opionion is, for this problem there are these 3 scenarios:

1. setup an own, dhcp/dns server with dynamic dns update - absolutely not requested for this problem here...(for unexperienced users)

2. setting up a vlan over the dhcp and usage of hosts-file (compared with solution 3, a bit more complex but the lan is still the same, no change - which is some times quite useful).

3. setting up the whole lan with fix ipaddresses and usage of hosts-file....the simplest way...here i absolutely agree with you.


but still, I WOULD NOT say that solution 2 is 'leading down to wrong path'...but anyway...

cheers liro


Yes - let's agree to disagree liro,

Your solution is to keep a useless dhcp assigned IP, then a fixed VLAN assigned IP. Why ? You can just ignore the dhcp if you wish and select an address outside the assignable range. Instead of adding a functional layer on top of a useless layer - you can simply fix the base layer. Of course the VLAN addressing has implications for routing and address resolution too.

No ! Your solution is a lot like putting spiders in your underware to eat the mites - it may work but it's definitely the wrong path.

-S