This week's book giveaway is in the Spring forum.
We're giving away four copies of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 and have Marten Deinum & Iuliana Cosmina on-line!
See this thread for details.
Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Changing IP address of an interface without rebooting Ubuntu

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can I change the IP address of my NIC's eth0 and get the changes effected without restarting Ubuntu?

I have tried the following commands after changing IP:
sudo ifdown -a
sudo ifup -a

But they dont work.
Running "sudo ifdown eth0" gives an error : "eth0 not configured"

I have also tried "sudo service network-manager restart"

Can someone suggest a method for this?




 
Saloon Keeper
Posts: 23695
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check your /etc/network/interfaces file. That's where Ubuntu/Debian define the IP addresses (or address leasing) for the NICs.

Normally you can just change that file and use ifdown/ifup on eth0. Or do it brute-force via the ifconfig or "ip" commands.
 
Rahul Dayal Sharma
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the /etc/network/interfaces file with policies for interface eth0 (dynamic followed by static)

Then interface was brought up using 'ifup eth0'. (I wanted the dynamic IP to be assigned and it worked)
The interface was brought down and up again. (Now I wanted the static IP to be assigned and it worked)


It worked fine for once, then I started getting the same error : 'interface eth0 not configured"

But during both attempts, when we tried bringing the inteface down using 'ifdown', we were getting the same error: 'interface eth0 not configured"

Any help is appreciated.
Thanks in anticipation,
 
Tim Holloway
Saloon Keeper
Posts: 23695
161
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't really know at this point. The closest I can come is pretty wild. Check dmesg and the system logs. These days the hotplug mechanisms can rename the eth devices. You see this especially when working with VM host machines. When that happens, the normal configuration won't work because the device is "no longer there" - under its original name, anyway. But there should be a log message in that case.

Fixes may include statements in the /etc/modules config and/or udev, but don't ask for details. I get confused enough on my own systems!
 
Ranch Hand
Posts: 310
18
MS IE Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Simply use ifconfig eth0 1.2.3.4.

I am running on Linux Mint, which is based on Ubuntu. Take a look at the effects of running this command (I used wlan1 in my case instead of eth0).


Remember just that the effects of that command will be lost after reboot.

If you want to switch your IP to other network, remember also about changing other parameters like mask and gateway.
 
Die Fledermaus does not fear such a tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic