Imagine there's a data centre which has a single physical network card.
Data centre use ip link and ip address to split a single physical network card into multiple virtual interfaces (VLANs).
Each VLAN handle specific type of traffic such as public internet traffic, private database traffic etc.
By manually using ip route, engineer create strict rules: "Database traffic is only allowed to exit through the secure internal interface, and public traffic can never cross over into the backup network." It's called gateway.
This isolation is critical for security and to prevent hackers who breach a web server from hopping onto the internal database network.
Create Network Interface
Create a virtual network adapter named backup0
sudo ip link add [Interface Name] type [Link Type]
[Link Type] usually is bridge, veth, vlan, dummy.
Example: sudo ip link add backup0 type dummy
ip link can't persisted after reboot, if want permenant may use nmcli connection add in 21 - nmcli
Verify interface
ip link show dev [Interface Name]
Example: ip link show dev backup0
Turn on interface
sudo ip link set [Interface Name] up
Example: sudo ip link set backup0 up
Verify interface whether is active or not
ip link show dev [Interface Name]
Example: ip link show dev backup0
Assign IP Address
Check all available IP address
ip a
Assign static IP
sudo ip address add [Static IP]/[Subnet Mask] dev [Interface Name]
[Static IP] and [Subnet Mask] are obtained from IT department.
Example: sudo ip address add 10.10.50.99/24 dev backup0
Verify IP address
ip address show dev [Interface Name]
Example: ip address show dev backup0
Mapping Gateway
Show current gateway
ip route show dev [Interface Name]
Example: ip route show dev backup0
Configure gateway
sudo ip route add [Destination Network]/[Subnet Mask] via [Gateway IP] dev [Interface Name]
[Destination Network], [Subnet Mask] and [Gateway IP] are obtained from IT department.
Example: sudo ip route add 192.168.100.0/24 via 10.10.50.1 dev backup0
Verify
ip route show dev [Interface Name]
Example: ip route show dev backup0
Remove IP
Delete IP
sudo ip link delete [Interface Name]
Example: sudo ip link delete backup0
Verify
ip a
Solution
student@localhost:~$ sudo ip link add backup0 type dummy
[sudo] password for student:
student@localhost:~$ ip link show dev backup0
3: backup0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
link/ether 9a:7a:f6:5a:96:ae brd ff:ff:ff:ff:ff:ff
student@localhost:~$ sudo ip link set backup0 up
student@localhost:~$ ip link show dev backup0
3: backup0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/ether 9a:7a:f6:5a:96:ae brd ff:ff:ff:ff:ff:ff
student@localhost:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:51:d6:54 brd ff:ff:ff:ff:ff:ff
altname enx08002751d654
inet 192.168.0.110/24 brd 192.168.0.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe51:d654/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3: backup0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether 9a:7a:f6:5a:96:ae brd ff:ff:ff:ff:ff:ff
inet6 fe80::987a:f6ff:fe5a:96ae/64 scope link proto kernel_ll
valid_lft forever preferred_lft forever
student@localhost:~$ sudo ip address add 10.10.50.99/24 dev backup0
student@localhost:~$ ip address show dev backup0
3: backup0: <BROADCAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default qlen 1000
link/ether 9a:7a:f6:5a:96:ae brd ff:ff:ff:ff:ff:ff
inet 10.10.50.99/24 scope global backup0
valid_lft forever preferred_lft forever
inet6 fe80::987a:f6ff:fe5a:96ae/64 scope link proto kernel_ll
valid_lft forever preferred_lft forever
student@localhost:~$ ip route show dev backup0
10.10.50.0/24 proto kernel scope link src 10.10.50.99
student@localhost:~$ sudo ip route add 192.168.100.0/24 via 10.10.50.1 dev backup0
student@localhost:~$ ip route show dev backup0
10.10.50.0/24 proto kernel scope link src 10.10.50.99
192.168.100.0/24 via 10.10.50.1
student@localhost:~$ sudo ip link delete backup0
student@localhost:~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host noprefixroute
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 08:00:27:51:d6:54 brd ff:ff:ff:ff:ff:ff
altname enx08002751d654
inet 192.168.0.110/24 brd 192.168.0.255 scope global noprefixroute enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe51:d654/64 scope link noprefixroute
valid_lft forever preferred_lft forever