This is an old revision of the document!
Linux IP/Network how-to
Setup a secondary IP on the same physical device
This how-to shows the procedure to setup an alias on a physical ethernet device. We are going to use 'ip' command line tool. We are going to setup following parameters:
What | Value | |
---|---|---|
Physical device | : | ens33 |
Default gateway | : | 172.16.135.254 |
Netmask/Prefix | : | 255.255.254.0 |
Alias interface | : | ens33:1 |
Attention: The alias network IP only is routed, if you use the same Netmask/Prefix!
- Get current IP configuration:
ip a list dev ens33 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:50:56:02:13:85 brd ff:ff:ff:ff:ff:ff inet 172.16.134.3/23 brd 172.16.135.255 scope global ens33 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe02:1385/64 scope link valid_lft forever preferred_lft forever
- Add a secondary IP on the physical device:
ip addr add 172.16.134.5/23 dev ens33 label ens33:1
- Check the configuration previously added:
ip a list dev ens33 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:50:56:02:13:85 brd ff:ff:ff:ff:ff:ff inet 172.16.134.3/23 brd 172.16.135.255 scope global ens33 valid_lft forever preferred_lft forever inet 172.16.134.5/23 scope global secondary ens33:1 valid_lft forever preferred_lft forever inet6 fe80::250:56ff:fe02:1385/64 scope link valid_lft forever preferred_lft forever
The line containing the new alias name (ens33:1
) must include secondary
!
- Delete alias from physical device:
ip addr del 172.16.134.5/23 dev ens33 label ens33:1
Setup with VLAN tag
In some circumstances, a VLAN tagging is necessary. In this chapter, I show how-to setup such an interface.
Add a vlan tag to an interface
Here we add the VLAN tag 90
to the interface, ens2f0.90
:
ip link add link ens2f0 name ens2f0.90 type vlan id 90
Add the IP to the linked device
ip addr add 10.90.1.54/24 dev ens2f0.901
Add a default gateway
ip route add default via 10.90.1.1 dev ens2f0.901