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 to assign my new IP address (fff.fff.fff.fff)? And how do I then restart it to accept the new configuration?

share|improve this question
    
What set of characters is that? Where did you find that? – Green Dec 6 '15 at 10:29
up vote 43 down vote accepted
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.

share|improve this answer
3  
This is outdated variant with aliases. Use below one with "ip addr" instead. – Heihachi Jun 4 '15 at 16:14
2  
It may be old (and maybe outdated), but there's nothing wrong with using this method, since it was not marked 'deprecated' and there's no plan for it being removed in the near future. IMHO this method is cleaner and safer than the others (see the Wilmer's answer and its comments). – Eric Carvalho Dec 6 '15 at 11:00

For an extra IP address, I usually add:

up ip addr add fff.fff.fff.fff/prefixlen dev eth0

to the bottom of the iface eth0 inet static stanza for future reboots and then run the command sudo ip addr add fff.fff.fff.fff/prefixlen 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.

share|improve this answer

As Heihachi points out using ethx:x aliases is outdated. However the ip addr solution is worse. It's ugly and incomplete, as you'll have to also add a down variant or ifdown won't work very cleanly.

See https://wiki.debian.org/NetworkConfiguration#Multiple_IP_addresses_on_one_Interface for a better solution: You can now just have repeated iface stanzas for the same interface. So just the solution above but drop the :x suffix.

share|improve this answer
2  
From the documentation at your link, talking about the most modern method for doing things (called iproute2): Note however that this method is dangerous! Certain driver/hardware combinations may sometimes fail to bring the link up if no labels are assigned to the alias interfaces. Considering that it's official documentation saying that the new way isn't such reliable, I'd prefer to stick with the working deprecated one. – reallynice Nov 27 '15 at 11:07
1  
Upvote because of official and precise documentation reference, but not for "a better solution", since it's marked as dangerous in the official documentation. – reallynice Nov 27 '15 at 12:46
    
@reallynice Reasonable point, though IMHO if this causes problems on a system that sounds to me like a buggy kernel/driver. I've been using multiple IP addresses on a single interfaces without the ugly :0/:1/etc aliases for years.(Also I'm pretty sure the solution from the Wiki is functionally equivalent to Robbie's solution above.) – Wilmer Jul 9 '16 at 18:37
    
@Wilmer I have a vmxnet3 device (VMware ESXi 6.5) on Ubuntu 16.04, and I could only get the new way to bring up the first device. Dropping the :x suffix was clearly not better for me. The documentation cleared up an error I was getting with the :x suffix though. – jbo5112 Jul 9 '17 at 3:06

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.