Can get an IP address through DHCP but no default gateway


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

6 answers Last reply
More about address dhcp default gateway
  1. 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!
  2. 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.
  3. 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

    ifdown eth1
    ifup eth1

    should do it.

    Good luck :)
  5. Cheers for that thats me sorted!!!
  6. 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]
Ask a new question

Read More

DHCP Default Gateway Subnet