Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

How can I restart a network interface? I have a vm that doesn't update its IP address correctly when switching between home and work. The vm runs Ubuntu server and uses a bridged network adapter.

share|improve this question
3  
Under what OS/distribution? How is the network configured in the VM? –  Gilles Jul 13 '12 at 23:56

3 Answers 3

ifdown to turn if off and ifup to turn it back on. To restart eth0:

> ifdown eth0
> ifup eth0

You will need root privileges.

More details about ifup and ifdown.

share|improve this answer

Sounds like you've got that interface configured using DHCP. If so, you want to kill the existing DHCP client, and restart it. For a lot of distros, you'd do this:

dhcpcd -k eth0
dhcpcd -d eth0

but not every distro used dhcpcd. I know some use dhclient, and doesn't Debian use pump?

Also, "eth0" may not constitute the correct interface name: do ifconfig -a to see what that VM has.

share|improve this answer
    
How about a reason for the downvote? If you confess to downvoting by giving a really good reason, I'll delete my answer. –  Bruce Ediger Jul 14 '12 at 4:00
1  
(Not about downvote:) I'm on Debian, dhcpcd and pump are in the repositories. Confusingly, dhclient is not, and that's the tool I got on installation and been using since. –  Emanuel Berg Jul 14 '12 at 13:46

Under Debian, you can tell an interface to get another DHCP lease with

dhclient -v {interface_name}

The -v means "verbose" and will show you the process in action.

@JustinY's answer will work (ifup and ifdown commands) if the interfaces are configured to pull addresses from DHCP. If they are configured as static, they'll just revert to their static IPs. dhclient will attempt to contact a DHCP server no matter what.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.