====== 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: 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: 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 ==== To make it permanent ==== To make it permanent, you do it using ''nmcli'' or just add the following lines into ''ifcfg-ens33'' file: IPADDR1=172.16.134.5 PREFIX1=23 The ''nmcli'' command: nmcli con mod ens192 +ipv4.addresses "172.16.134.5/23" When done, just restart network: ''systemctl restart network'' ===== Remove (delete) an IP address ===== ip addr del 172.16.134.5/23 dev ens33 ===== Setup with VLAN tag ===== In some circumstances, a VLAN tagging is necessary. In this chapter, I show how-to setup such an interface. ^ What ^ ^ Value ^ | Physical device | : | ens2f0 | | IP address | : | 192.168.1.54 | | Netmask/Prefix | : | 255.255.255.0 / 24 | | VLAN interface | : | ens2f0.90 | ==== 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 192.168.1.54/24 dev ens2f0.90 ==== Add a default gateway ==== ip route add default via 192.168.1.1 dev ens2f0.90