Home   Profile   Fun
#154 Linux  07.01.2008

Use dhcpcd on the shell to retrieve an IP address via DHCP


Linux video tutorial for dhcpcd * Video Tutorial


Sometimes you find yourself on a machine which has no network connection, no IP address or even no network interface set up. Usually it's a matter of seconds to configure the network. To get an IP address from a DHCP server the DHCP client daemon can be used:
dhcpcd eth0

In case this is not working let's check the status of the network interfaces. The following commands should show the interfaces along with their status.
ip addr show
or
ifconfig

If the relevant interface is not displayed try to bring it up.
ifconfig eth0 up

You may see something like
eth0: unknown interface: No such device

This means that the kernel does not know this network interface. Make sure that the correct drivers are installed and loaded and try again. You can find the names of the recognized interfaces with dmesg.

If the interface is visible with ifconfig but has no IP address we get one via DHCP.
dhcpcd eth0

Now the machine should have an IP address and a working network connection. If it still failes make sure that you have used the right interface name. For example the network interface with the physical connection could have been named eth1 instead of eth0.