Jay Taylor's notes

back to listing index

use dhcp on eth0 using command line

[web search]
Original source (unix.stackexchange.com)
Tags: linux networking dhcp unix.stackexchange.com
Clipped on: 2018-05-25

I am trying to set the eth0 interface to use dhcp to get an ipv4 address, using the command line. I can manually change the ip address using

sudo ifconfig eth0 x.x.x.x netmask x.x.x.x

Is there a similar command to use to set eth0 to get an address using dhcp? I tried typing:

sudo dhclient eth0 

however the ip address doesn't change when I type this. The /etc/network/interfaces file was set to

iface eth0 inet manual 

which I then changed to:

auto eth0
iface eth0 inet dhcp 

however this doesn't change the eth0 ip address even if the system is rebooted.

asked Oct 29 '16 at 15:51
user197699
up vote 7 down vote accepted

If your dhcp is properly configured to give you an IP address, the command:

dhclient eth0 -v 

should work. The option -v enable verbose log messages, it can be useful.

If your eth0 is already up, before asking for a new IP address, try to deconfigure eth0.

To configure the network interfaces based on interface definitions in the file /etc/network/interfaces you can use ifup and ifdown commands.

answered Oct 29 '16 at 16:16
andreatsh
1,1771413

First you need to run the following command:

dhclient -v -r

Then change the ip adress:

ifconfig eth0 xx.xx.xx.xx

Change xx.xx.xx.xx with the needed ip_adress

answered Oct 29 '16 at 16:55
GAD3R
20.4k144686

Your Answer

 
community wiki

asked

1 year, 6 months ago

viewed

40,289 times

active

1 year, 6 months ago

Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.

This site is not affiliated with Linus Torvalds or The Open Group in any way.