I just set up a second IP adress on my Ubuntu server and now I'm trying to change the default outgoing IP adress to the new one with ip route replace default via <old-ip> src <new-ip>.

But whenever I restart the networking service, it gets changed to the old IP adress.


Yes, that is because Ubuntu sets the default route dynamically on every startup of the networking service. You can open /etc/network/interfaces and append your command under the interface like this:

post-up ip route replace default via <old-ip> src <new-ip>

Do you mean you are trying to change your ip address?


change the settings in /etc/network/interfaces to set the ip address you would like. Just change eth0 to eth1 or whatever interface is.

auto eth0
iface eth0 inet static
  • I want to keep both for inbound connections but only the new one for outbound connections. – kevdotcom Sep 22 '16 at 15:23
  • Make sure the correct default gateway is set in the interfaces file, and remove all other gateway directives. – Tero Kilkanen Sep 22 '16 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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