18

I want to have the wired interface simultaneously obtain a DHCP address, and also alias a fixed address so I can communicate with a device with a fixed IP address on a different subnet over the same link.

When searching for IP address aliasing in Ubuntu, I found this article How do I add interface aliases using Network Manager GUI?. Unfortunately, the Edit Connections GUI in Ubuntu 14 does not have the "additional addresses" button.

Where has this functionality moved?

2
  • 1
    I have updated that answer with another screenshot, see if it helps. But at any rate, I don't think the GUI allows you to have a DHCP and a static address at the same time - multiple static addresses are fine.
    – muru
    Feb 14, 2015 at 17:27
  • Correct - I tried setting it to manual, adding my static address and switching back to DHCP. Doing so deletes any manual addresses.
    – tim11g
    Feb 14, 2015 at 18:05

4 Answers 4

32

Skip the gui and do it via command line.

The following link provides detailed information on how to create the alias on a temporary basis, as well as how to edit the interfaces file to make the change permanent.

http://www.cyberciti.biz/faq/linux-creating-or-adding-new-network-alias-to-a-network-card-nic/

Information from site in case of site death:

ifconfig command line

You can use ifconfig command to configure a network interface and alias. For example:

  • eth0 NIC IP 192.168.1.5
  • eth0:0 first NIC alias: 192.168.1.6

To setup eth0:0 alias type the following command as the root user:

# ifconfig eth0:0 192.168.1.6 up

Verify alias is up and running using following command:

# ifconfig -a

# ping 192.168.1.6

However, if you reboot the system you will lost all your alias. To make it permanent you need to add it network configuration file.

# vi /etc/network/interfaces

Append the following to the file (This is in addition to existing information, not a replacement for it)

auto eth0:1
iface eth0:1 inet static
name Ethernet alias LAN card
address 192.168.1.7
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0

Save and close the file. Restart the network:

# /etc/init.d/networking restart
4
  • Thanks! the "ifconfig eth0:0 192.168.1.6 up" command works great. I don't need it to persist, so that is a perfect solution.
    – tim11g
    Feb 14, 2015 at 18:11
  • 2
    Just note: ip utility is now recommended way to manupulate interfaces ( serverfault.com/a/458639/115256 ). Here's the HowTo: askubuntu.com/a/547297/53738
    – dess
    Jul 8, 2015 at 5:50
  • Why is there no gateway entry in the config above? Jun 1, 2016 at 9:47
  • 3
    @Colin'tHart: you can only have one "default gateway" (there are special cases, but that is another story), so if the "main" network config already have a gateway, you should not put any in this alias. If the "main" network have no gateway, you can add in the alias the gateway, specially if it is related to this ip range
    – higuita
    Jul 13, 2016 at 13:37
3

In order to add an address temporarily use ip:

ip a add 192.168.178.2/24 dev enx0050b60c19af

For example to install OpenWRT on some old devices:

https://openwrt.org/toh/avm/avm_fritz_wlan_repeater_450e

0

You can use the below steps to add IP Address in a ubuntu network interface.

  1. Login to Ubuntu server via ssh.

  2. Hit the Following Command.

nano /etc/network/interfaces

  1. Enter the interface alias eth0:0 as mentioned in below.

(Note: If you already have interface alias eth0:0, you can add eth0:1 or eth0:2 for additional IP Address)

#secondary ip address
auto eth0:0
iface eth0:0 inet static
address 1*3.2*8.149.***
netmask 255.255.255.***
  1. Below Command will up the added interface alias within the network.

ifconfig eth0:0 1*3.2*8.149.*** up

  1. Restart the network service.

/etc/init.d/networking restart

  1. check the newly added ip address with the below command.

ifconfig

It is Done.

0

I just learned a trick from my colleague which involve the following:

If say eth_lan0 is set as the name of your wired network and has first been configured with the IP 192.168.1.2, say with something like netplan, you can then add an alias to connect to another internal network say with an IP with the pattern 10.42.0.x with the following:

sudo ifconfig eth_lan0:1 10.42.0.2

This assumes that the IP 10.42.0.2 has not yet been assigned to your LAN and that your host is connected to both networks, one with IP 192.168.1.x and the other with 10.42.0.x. Check if you have been successful by running ifconfig to see if the alias has been set. Then, it would be recommended to ping the hosts you are trying to connect on the two local networks to make sure everything runs as expected.

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.