LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Router DHCP and Linux Hostname (https://www.linuxquestions.org/questions/linux-networking-3/router-dhcp-and-linux-hostname-9041/)

ccpirate 11-21-2001 02:31 PM

Router DHCP and Linux Hostname
 
Ok, I apologize if this has been covered somewhere, but I swear I have been up one side of the Net and down the other looking for the answer to this question.

I have a Netgear314 router that works great for Windows and Linux. It is doing NAT for my home network and basic firewalling. It gets a static IP from my @Home provider, and then generates DHCP addresses for my internal network. These addresses are of the form 192.168.0.x

When I installed RH7.2, I specified the correct ethx device and selected DHCP. Since I have network connectivity on the linux box, it appears that it is indeed getting a DHCP lease from the router and that is working ok. However, the issue is that the hostname is somehow default assigned as DHCCP2 or somesuch. How do I change this hostname and still have everything work? (Incidentally lpd complains about this hostname when I shutdown, which may have something to do with why I can't get my USB printer to work, but I digress).

From others posts, it seems as if I should be able to name this thing "monster.mynetwork" or whatever I want and have it work, but I can't seem to get it to work. If I name it, then it loses network connectivity. If I don't name it, then I get this stupid hostname and lpd complains.

Anyone know what I need to do to fix this?

Thanks in advance.

Chris

ccpirate 11-25-2001 02:42 PM

No help huh? Come on, someone has to know something! Someone has this same or similar setup! At least tell me to RTFM!!!!

finegan 11-25-2001 03:05 PM

Redhat's netconfig basically creates a cute little gui-esque frontend for either changing an rc file (if you're running statics), or invoking dhcpcd if you're using dhcp.

Unfortunately, netconfig keeps you from being able to pass arguments to dhcpcd if you're indeed using that.

Check the man page on dhcpcd. I think you want to use the -R or -D option, but I'm not entirely sure from your post... and well, I have to run to lunch.

You can invoke dhcpcd on startup by sticking the line in /etc/rc.d/rc.local btw.

Luck,

Finegan

krquinby 11-26-2001 02:09 PM

In the /etc/sysconfig/network-scripts directory there is a file for each interface called ifcfg-eth0 (or what ever interface you have). For an interface that recieves its network information via dhcp, there will be a line that looks like this:

BOOTPROTO=dhcp

Put the following lines in to see if it fixes your problem:

DHCP_HOSTNAME=yourhostname
DHCP_DOMAINNAME=youdomainname

Obviously, if you don't have an DNS domain you are using on your internal netowrk the domainname line is not required.

Kris

ccpirate 11-27-2001 07:45 AM

Ok, this last suggestion didn't work. I changed etc/sysconfig/network-scripts/ifcfg-eth1 to include DHCP_HOSTNAME = myhostname and nothing happened after rebooting (eth1 is where my card is at, I don't use the built in card at eth0). My machine is still named dhcppc2.

Any other suggestions?

finegan 11-27-2001 11:46 AM

eth1 is using dhcpcd to get its lease from the router. Under normal operation dhcpcd is built to not over-write the hostname with one sent by the router. This means that either:
A) Redhat's script is annoying. or,
B) Your router is really grouchy.

To find out which, boot the machine like normal, log in as root, and then bring down the eth1 interface and kill the dhcpcd lease with:

dhcpcd -k (-k is for kill the connection and clear all the dhcp cache)

The lease created by the Redhat init script is now dead.

change the name of the machine back to what its supposed to be. (This is assuming that the name stuck when the dhcp cache was killed. Hopefully it will revert.)

Open another terminal and try: tail -f /var/log/syslog
(this will give you a running log of what is happening)

In the first terminal try:

dhcpcd -d eth1 (-d is for it to log everything to syslog, and if the device isn't eth0, you have to give the device as an argument.)

try ifconfig to see if you have an IP.

If the hostname of your box is what it should be, then it was RedHat's init script. If it got re-named... look at that running log and see what the router forced it to do. If it force-fed dhcpcd a hostname, you'll probably have to poke around the config settings of the router.

Hope that helps,


Finegan

mcleodnine 11-27-2001 12:13 PM

Try to find RedHat's script for dhcpcd (in my SuSE box it's /etc/init.d/dhclient) and look for the line that starts the client up. Make sure that there is no '-H' option when starting the client as that will force the client to use the hostname supplied by the dhcp server. You can get more info with 'man dhcpcd'

ccpirate 11-28-2001 08:48 AM

Well, when I run /sbin/dhcpcd -k I get:

**** /sbin/dhcpcd: not running

hence /sbin/dhcpcd -d doesn't do much either.

Incidentally, I don't have a file called /var/log/syslog
Is this bad?

I can't seem to find RedHat's init file unless it is: /etc/sysconfig/network-scripts/ifup

I did find a dhcpcd -H in there. I removed that and ran /sbin/ifup eth1, but nothing seemed to happen.

I'll try to reboot and see what happens.... sigh.

finegan 11-28-2001 11:52 AM

Quote:

Incidentally, I don't have a file called /var/log/syslog. Is this bad?
Yeah, it means that its been so long since I played with a Redhat machine that I forgot where they stick their version of syslog. That seemed right...

RedHat's init file is going to be somewhere in /etc/rc.d/ probably in init.d, or xinet.d (sp?) if its new... somewhere around run level 5 is my guess.

Sorry that's vague. I moved mostly to Slackware a while ago and they use a BSD-ish init, while RedHat (and most of the rest of the world) use SysV.

Okay... I guess the way to make sure that everything isn't demented is to try to get a lease from the ground up. Make sure that eth1 is down with ifconfig. Also make sure the machine's hostname is set to what you want it to. Then try:

dhcpcd eth1

That should ask the router for an IP, a pair of nameservers, a gateway address and nothing else.

when you cut dhcpcd -H out of /etc/sysconfig/network-scripts/ifup, did you cut out dhcpcd -H, or just the -H? Also, when you say that this didn't work... could you get a connection at all after changing ifup, or do you mean the router still shafted you with a crap hostname?

-Finegan

ccpirate 11-28-2001 02:27 PM

When I cut dhcpcd -H out of /etc/sysconfig/network-scripts/ifup, I just cut out the -H and changed it to -h "monster"

I got a connection when I brought up ifup, but it was still dhccp2 the crap hostname. At least, I couldn't ping monster and the command line still said username@dhccp2

I'll try the rest of your suggestions tonight.

Is it just me, or should this not be easier? :)

mcleodnine 11-28-2001 04:37 PM

Have a look at /var/state/dhcp/dhcp-eth1.info or /var/lib/dhcpcd/dhcpcd-eth0.info (not too sure where RH keeps that stuff. It should contain the data recieved from the dhcp server after the lease negotiation.

ccpirate 11-29-2001 08:37 AM

Ok, I took the interface down with ifdown eth1. Confirmed it was down by making sure I couldn't ping. ran hostname monster

Then I tried /sbin/dhcpcd and got the below from /etc/dhcpc/dhcpcd-eth1.info (slightly modified to avoid hackers).

As you can see my hostname for dhcp is still dhcppc2

Tried it also as /sbin/dhcpcd -h monster eth1 and /sbin/dhcpcd eth1 -h monster and still got the same thing below. Any thoughts?

IPADDR=192.168.0.3
NETMASK=255.255.255.0
NETWORK=192.168.0.0
BROADCAST=192.168.0.255
GATEWAY=192.168.0.1
HOSTNAME=dhcppc2
DOMAIN=potlnd1.or.home.com
DNS=24.0.48.33,24.0.48.34
DHCPSID=192.168.0.1
DHCPGIADDR=0.0.0.0
DHCPSIADDR=192.168.0.1
DHCPCHADDR=00:01:02:4B:E6:13
DHCPSHADDR=00:30:AB:04:5D:0B
DHCPSNAME=c119XXXX-X
LEASETIME=4294967295
RENEWALTIME=2147483647
REBINDTIME=3758096377

mcleodnine 11-29-2001 03:05 PM

OK. When sending a request for a DHCP address to most cable ISPs, you usually need to send the client-identifier (given to you when you signed up for the service). That is what the '-h' directive is used for. Sending '-h monster' won't do much for you as I doubt their server will see that as a valid client-id. If the '-H' is used, your dhcp client will set the hostname sent from the dhcp server. Use the client-id supplied by your ISP (dhcpcd eth1 -h your_client_id) Don't use the '-H' and all should be well.

...

carp!

I re-read the thread from the beginning. Your netgear router is giving out the IP address. Better read up on the netgear setup. The above applies for the negtiation between the router and your ISP. dhcpcd with no options should give you the correct results unless the router is forcing the hostname (doubt it).

mjakob 11-29-2001 04:19 PM

How's about just setting up the linux box with a static IP? Is it just a matter of pride to get the DHCP leases working or is there some other reason?

-Mark

finegan 11-29-2001 04:56 PM

You could try a static, although it probably won't work because these home routers typically won't forward unless you've gotten a lease from them.

Yeah, I'm with mcleodnine, your router is force-feeding your box that hostname. There has to be a way to disable that.

-cheers,

Finegan


All times are GMT -5. The time now is 08:52 PM.