3

I use static IP adresses.

When changing the IP of a network interface (eth0 or wlan0) the settings are saved to the network connections but when running ifconfig or looking at Network Settings, either connections retain the old IP address.

I have tried restarting the networking service, the computers (yes, this occurs on more than one) and even reinstalling the OS.

PLEASE can somebody help me. I'm losing out on so much work this past week just trying to get Ubuntu 12.04 working like a normal OS.

Using the command sudo ip addr add 192.168.0.1/24 dev eth0 SOMETIMES works... the command switches the interface off, then when re-enabling it the IP reverts again. AAARGH!

3
  • 1
    Does it help to turn off the device via sudo ifconfig eth0 up and turn it on again with sudo ifconfig eth0 down. Does this help?
    – jplatte
    May 3, 2012 at 8:41
  • I have tried doing so, when the interface is up again it reverts to the old IP settings. Problem is whenever I change the IP, the interface goes down with the correct settings until I turn it on again.
    – beanaroo
    May 7, 2012 at 9:19
  • If "keeping you computer running" is not important, just restart the computer, or using command "sudo reboot". Its may not a true solution, but is a "quick and dirty" way :)
    – Andiana
    Jan 4, 2017 at 8:01

3 Answers 3

3

In general, your process will be:

  • Stop network-manager
  • bring the interface down
  • assign the address and netmask (using ifconfig)
  • optionally create a route to a gateway if the interface is the one that will access the internet (using route)
  • bring the interface back up
  • and either:
    • If DHCP-managed IP address assignment as defined in /etc/network/interfaces:
      • do nothing.
      • service network-manager force-reload
    • If Static IP address assignment as defined in /etc/network/interfaces:
      • change (or define) the IP, netmask, broadcast, gateway as needed
      • service network-manager start

Of course, network-manager is capable of assigning static routes too. Just define your static route in network-manager GUI and then service network-manager force-reload at terminal. Done.

Or switch back to DHCP-assigned dynamically by removing the static route definition from network-manager GUI, then service network-manager force-reload at terminal. Done.

Or you can do it...

The harder way

Which also happens to be the logically flawless, sure-fire way.

These instructions assume your interface is "eth0". If it's not, you'll need to change all commands and areas entered to reflect your interface.

First, check if network-manager is running:

service network-manager status

If it is running, right-click on Network-Manager and click "Edit connections...". Select the [interface] you're having trouble with, and click "Edit...". Click on the "IPv4 Settings" tab. If you see any entries under "Addresses", delete them. "Save" the settings, and close Network-Manager out.

Then, at a terminal, these four command strings, replace brackets and inner bounds area with value:

sudo service network-manager stop;
sudo ifconfig eth0 down;
sudo ifconfig eth0 [static IP you want] netmask [netmask; generally 255.255.255.0] up;
ifconfig eth0;

You should see that your interface now has the address you want, but we're not done. To make the settings persistent (i.e., across reboots), you'll need to edit (as root) /etc/network/interfaces, and either find the section related to your [interface], or you'll add a new section, separating each section (each "section" defines one interface) by a blank line:

Example (If already exists in file, looks like or similar to):

auto eth0
iface eth0 inet dhcp

Example (Change to this, or add if doesn't exist):

auto eth0
iface eth0 inet static
      address [ip address goes here]
      netmask [netmask goes here]
      broadcast [for netmask 255.255.255.0, this should be x.x.x.255 where x from IP]
      (optional here, if this is will be your internet interface, "gateway [gateway addr]" goes here)

Of particular note is that you don't want dhcp-assigned IP, you want static-IP. Note the difference in structure between the above two examples.

Save it.

Now if this interface will be meant for internet or external routing (i.e., communication on the interface needs to be able to access IPs outside of the network of the interface, which is defined by your netmask ultimately), then:

At terminal:

sudo route add default gw ["inside local" IP address of your router or other gateway]

Verify your settings are correct with:

sudo ifconfig eth0|grep addr && route|grep UG|awk '{print "Gateway:", $2, "Interface:", $8}';

Now:

sudo service network-manager start

...to restart network-manager. At this point you should be good to go.

In the future:

If you need to change your static IP to another static IP after this, it's as simple as sudo service network-manager stop as exampled above, sudo ifconfig eth0 down, edit /etc/network/interfaces as exampled above and changing the IP address to taste, sudo ifconfig eth0 [ip address] netmask [netmask] up as exampled above, and then sudo network-manager start as exampled above, in that order.

If instead you want DHCP to assign IP addresses automatically to the interface, it's as simple as sudo service network-manager stop as exampled above, sudo ifconfig eth0 down, edit /etc/network/interfaces as exampled above and remove the lines address, netmask, broadcast, gateway, and change the part that says static to dhcp, sudo ifconfig eth0 0.0.0.0 netmask 255.255.255.0 up, sudo service network-manager start. Done.

4
  • Shouldn't the last sudo service network-manager force-reload be sudo service network-manager start? At least that's what worked for me.
    – JohnAllen
    Aug 10, 2016 at 19:51
  • I think either could work... start will work for sure, more atomic and sane would be to force-reload so that the configuration is explicitly requested to reload. It's clearer what is occurring with force-reload. However, upon start, this occurs anyways. I will change my answer to reflect what worked for you.
    – SYANiDE
    Aug 11, 2016 at 4:31
  • Force-reload didn't work for me with 16.04. Forget what the output was.
    – JohnAllen
    Aug 11, 2016 at 14:12
  • Good to know! I've gone ahead and changed the answer to reflect your solution.
    – SYANiDE
    Aug 12, 2016 at 1:11
2

I`m not a geek! I just want to share my experience. try stopping some services like network-manager! like: sudo service network-manager stop I could not change my mac... but after stopping network-manager I could change my mac permanently. remember not to restart it, but to change settings during the stopped services!!!

1
  • Thanks, samphil. Turning off / restarting the network-manager doesn't seem to have an effect.
    – beanaroo
    May 7, 2012 at 9:20
0

In my case, just disconnecting and reconnecting to the network after changing the static IP worked fine! It might be worth a try.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .