Sign in with
Sign up | Sign in
Your question

Can get an IP address through DHCP but no default gateway

Tags:
  • DHCP
  • Default Gateway
  • Subnet
Last response: in Linux/Free BSD
Share
December 3, 2008 9:46:13 AM

Hi,

I am resonably new to Linux (I mean really new) and I have hit a problem. I have a machine with Linux with an extra nic card. When trying to use eth1 to connect to my network I am able to get an address through DHCP but unable to get a default gateway. Unfortunately with having multiple subnets in use this becomes a problem for me as I can still get to all other addresses within the same subnet as they are using layer 2 not 3.

I have found a way to get the default gateway on to the machine through DHCP however this is a fix that needs to be applied everytime I change subnets. The fix I use is as follows:

ifconfig eth1 down
killall dhcpcd
dhcpcd eth1

I find that when I do move from subnet to subnet the nic seems to keep the previous address and I am unable to drop this address unless I complete the commands above which in turn gives me the desired gateway.

So after that rant is there a way for me to move from subnet to subnet where the nic picks up the new ip address and the default gateway automatically rather than going through the commands mentioned above?

I could really do with some help on this

Cheers

More about : address dhcp default gateway

December 3, 2008 10:16:08 AM

Hmmm.. let me see if I understand this, you have two NIC's and two subnets that you want to use. I would look and binding each card to a unique subnet, you should then be able to use route to specify which direction requests are sent. I've done this a long time ago on an NT system with FDDI / 100BaseT cards.

I used to run two NIC's on my home rig, one bound to static details for a DMZ and the other to a standard NAT/DHCP connection to the router. I kept it REALLY simple and just swapped the cable!
December 3, 2008 11:32:57 AM

Thanks for the reply being a newbie I've realised that although I have two nics one internal and one external the internal is only used for receiving data. My problem was that unless I have the ethernet plugged in on startup it will not get the default gateway. If I plug the cable in after startup it does not get the gateway but does get an address.

Therefore I think I have answered my own question because when I change subnets the ip address is kept on the nic card and I presume the release command are the commands I entered above. If there is an easier way to release the ip address and renew ie one command like ipconfig /release on windows I would be grateful if you could let me know.

I realised that a reboot with the cable connected work by using the "init 6" command.

Cheers again.
December 3, 2008 11:56:54 AM

Just thought I'd post again as a colleague had been trying to sort this too.

It seems that the fix was to delete the network card and then re-install it. This allowed boot up and then connection to the network and it will get an address as well as a default gateway.

Therefore it leaves the question if I need to move between subnets I need to release the previous address. Is there a one line command or is it

ifconfig eth1 down
killall dhcpcd
dhcpcd eth1


Cheers
December 3, 2008 3:08:45 PM


  1. ifdown eth1
  2. ifup eth1


should do it.

Good luck :) 
December 3, 2008 3:20:23 PM

Cheers for that thats me sorted!!!
December 3, 2008 7:15:02 PM

As the resident forum Manc anything 'Sorted' is my teritory :p 

Although why you would want to be 'nickin' Liverpool I have no idea... ;) 

[/Very much a UK regional thing]
!