How do I add an additional IP address to /etc/network/interfaces?

I have an extra IP address available to my server, and so I need to assign it in the interfaces file. At the moment, I've got this:

auto lo
iface lo inet loopback auto eth0
iface eth0 inet static address aaa.aaa.aaa.aaa netmask 255.255.254.0 gateway bbb.bbb.bbb.bbb dns-nameservers ccc.ccc.ccc.ccc ddd.ddd.ddd.ddd eee.eee.eee.eee dns-search vps-number.com

What do I add/assign my new IP address (fff.fff.fff.fff)? And how do I then restart it to accept the new configuration?

1

3 Answers

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static address aaa.aaa.aaa.aaa netmask 255.255.254.0 gateway bbb.bbb.bbb.bbb dns-nameservers ccc.ccc.ccc.ccc ddd.ddd.ddd.ddd eee.eee.eee.eee dns-search vps-number.com
auto eth0:0
iface eth0:0 inet static address fff.fff.fff.fff netmask 255.255.254.0

Then you can run sudo ifup eth0:0 to bring it up and sudo ifdown eth0:0 to bring it down.

4

You can just have repeated iface stanzas for the same interface. Example from :

auto eth0
allow-hotplug eth0
iface eth0 inet static address 192.168.1.42/24 gateway 192.168.1.1
iface eth0 inet static address 192.168.1.43/24
iface eth0 inet static address 192.168.1.44/24
# adding IP addresses from different subnets is also possible
iface eth0 inet static address 10.10.10.14/24

So just the solution above but drop the :x suffix, which as Heihachi points out is outdated.

(The ip addr suggestion is the worst. It's ugly and incomplete, as you'll have to also add a down variant or ifdown won't work very cleanly.)

7

For an extra IP address, I usually add:

up ip addr add dev $IFACE

to the bottom of the iface eth0 inet static stanza for future reboots and then run the command sudo ip addr add dev eth0 again manually to activate it directly.

If your netmask is 255.255.254.0 then prefixlen should be 23 for you.

I'd love to know if there's a better way, though.

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like