5

How do I add a second IP-address in Ubuntu 17.10 like the old days where you could add eth0:1, eth0:2 etc.

I've tried but lots of commands have been deprecated like ifup, ifdown etc. and the network settings doesn't seem to be the same as it used to. I might be wrong here but I can't seem to figure it out.

I have a network card eth0 where I want to add a second IP on the same subnet. If I add eth0:1 to /etc/network/interfaces but I can't seem to get the interface up.

Is there another way to do this permanently?

EDIT:

/etc/network/interfaces:

auto lo
iface lo inet loopback

auto eth0:1
iface eth0:1 inet static
    address 10.100.1.39
    netmask 255.255.255.0

I've tried to add the information on eth0 too but it doesn't seem to make a difference.

This if the output of ifconfig

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 10.100.1.38  netmask 255.255.255.0  broadcast 10.100.1.255
    inet6 fe80::215:5dff:fe00:1605  prefixlen 64  scopeid 0x20<link>
    ether 00:15:5d:00:16:05  txqueuelen 1000  (Ethernet)
    RX packets 496  bytes 248506 (248.5 KB)
    RX errors 0  dropped 4  overruns 0  frame 0
    TX packets 241  bytes 34934 (34.9 KB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  • I don't know, but I recall having to recompile the kernel with a flag set to enable the virtual-interfaces for ports; but its been too long since i required it.. – guiverc Mar 8 '18 at 10:39
  • could you post your /etc/network/interfaces file, and the output of ifconfig eth0? – pim Mar 8 '18 at 11:34
  • I doubt that the interface is eth0 in 17.10. – chili555 Mar 8 '18 at 12:03
  • @pim I have edited my post with the information. – PatricF Mar 8 '18 at 12:08
  • @chili555 no it's eth0. Why do you doubt that? – PatricF Mar 8 '18 at 12:09
6

Turns out in 17.10 you edit your network settings in /etc/netplan/01-netcfg.yaml

All I had to do was add the second IP next to the existing one separated with a comma like this:

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
     addresses: [ 10.100.1.38/24, 10.100.1.39/24 ]
     gateway4: 10.100.1.1

Then you run:

# netplan apply

Hope this helps someone in the future.

  • ..isn't that the network manager's files ? – Robert Riedl Mar 8 '18 at 13:26
  • What do you mean? – PatricF Mar 8 '18 at 14:57
  • That's correct; you can add as many addresses for an interface as necessary by adding to the "addresses" list this way. – Mathieu Trudel-Lapierre Mar 9 '18 at 11:28
0

You can do that directly on the commandline, which is not permanent (i.e. reboot-save)

sudo ifconfig eth0:0 10.100.1.40 netmask 255.255.255.0 up

or in your /etc/network/interfaces, which is permanent

sudo nano /etc/network/interfaces

add this (or similar) to the existing eth0 block

iface eth0:0 inet static
  address 10.100.1.40
  netmask 255.255.255.0

and bring it up with

sudo ifup eth0:0
  • 2
    I don't know whats unclear in my first post but that's pretty much exactly what I did and it doesn't seem to work in 17.10 anymore, hence my post about netplan that seems to be the new way to configure network. See here: wiki.ubuntu.com/Netplan – PatricF Mar 8 '18 at 15:02
  • What's your error message ? Because it works on my system and should work on yours – Robert Riedl Mar 8 '18 at 15:40
  • 1
    Did you upgrade from an earlier version maybe? Because they seem to have changed it in 17.10 as the old way doesn't work on a fresh install. I've always used Debian before and have used the "old" way for years so I was a little confused when it didn't work anymore. – PatricF Mar 8 '18 at 17:52
  • No its a pretty fresh install (2 months old). As the wiki page states its for NetworkManager and systemd, though it doesn't support a whole lot. What I'd like to know: If you use this sudo ifconfig eth0:0 10.100.1.40 netmask 255.255.255.0 up on the commandline, is the exitcode 0 ? what does ip a say ? – Robert Riedl Mar 8 '18 at 18:16
  • Tested the /etc/network/interface method on 18.04, it seems to work, after spending 3 full minutes on "Starting hostname service" – pim Mar 9 '18 at 7:31

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.