On my server I want to assign several IP addresses to one NIC, but without using the deprecated ifconfig or the obsolete "alias" notation (like eth0:0) in /etc/network/interfaces because in IP Aliasing (on ) you can read
2IP-aliases are an obsolete way to manage multiple IP-addresses/masks per interface
3 Answers
If you need an additional IP address just for the moment you can add it to any interface on your machine with
sudo ip address add <ip-address>/<prefix-length> dev <interface>for instance
sudo ip address add 172.16.100.17/24 dev eth0would add
172.16.100.17using a 24 bit network prefix to the list of addresses configured for youreth0.You can check the result with
ip address show eth0and you can delete this address again with
sudo ip address del 172.16.100.17/24 dev eth0Of course these changes are lost when you reboot your machine.
To make the additional addresses permanent you can edit the file
/etc/network/interfacesby adding as many stanzas of the formiface eth0 static address 172.16.100.17/24so that it looks like
iface eth0 inet dhcp iface eth0 inet static address 172.16.100.17/24 iface eth0 inet static address 172.16.24.11/24You can even keep the
dhcpfor the primary address.To activate these settings without a reboot use
ifdown/ifuplikesudo ifdown eth0 && sudo ifup eth0It is essential to put those two commands into one line if you are remoting into the server because the first one will drop your connection! Given in this way the ssh-session will survive.
With the new toolkit, it is as easy as with the old to add new ip addresses:
ip addr add 192.168.1.1/24 dev eth0When looking with ip addr show again, you see the second ip address assigned to the interface:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff inet 192.168.0.100/24 brd 192.168.0.255 scope global eth0 inet 192.168.1.1/24 scope global eth0 inet6 fe80::223:54ff:fe45:f307/64 scope link valid_lft forever preferred_lft foreverRemove that ip address with:
ip addr del 192.168.1.1/24 dev eth0The iproute2 suite:
The iproute2 suite is the communication suite for interprocess communication beween the kernel and the user space via the netlink protocol. It should replace the whole standard network tools. Here is what they replace:
ifconfig-->ip addrandip linkroute-->ip routearp-->ip neighiptunnel-->ip tunnelipmaddr-->ip maddrnetstat-->ss
One way is:
sudo ip addr add 192.168.0.2/24 dev eth1