Linux ip Command With Examples- Network Management – POFTUT

Linux ip Command With Examples- Network Management


Linux network stack provides a lot of network-related features like a commercial network router or switch. There are different tools and ways to manage these advanced features. In this tutorial, we will look ip toolset which is a new generation tool designed to manage Linux network configuration.

Show IP Address

An IP address is a number used in the network to access a host.

$ ip address show

OR

$ ip add
Show IP Address
Show IP Address

As we see the same command can be expressed in different ways. I prefer short one like ip add which is the same ass ip address show

Set IP Address

Setting the IP Address will create new IP address of the interface and do not delete the existing IP address. To set IP address root privileges are required so we use sudo .

$ sudo ip address add 192.168.122.200/24 dev ens3
Set IP Address
Set IP Address

Remove IP Address

Removing IP address from an interface syntax is the same as the adding. Just the add keyword is changed with del keyword like below. This will remove the specified IP address from that interface.

$ sudo ip address del 192.168.122.200/24 dev ens3
Remove IP Address
Remove IP Address

Flush, Remove All IP Addresses

Removing IP addresses one by one is away but if we need to remove remove all IP addresses in a single command easily flush can be used like below.

$ sudo ip addr flush

Enable Network Interface

Interfaces can be enabled with the following command. This will bring interface into the downstate. In network terminology, this is called UP

$ sudo ip link set lxcbr0 up
Enable Network Interface
Enable Network Interface

Disable Network Interface

Disabling network interfaces are very similar to the enabling network interfaces. Just up keyword is changed with down keyword.

$ sudo ip link set lxcbr0 down
Disable Network Interface
Disable Network Interface

Change MTU

Maximum Transmission Unit is a configuration used to specify the size of a single package that can be transmitted over the network. By default, MTU is set to 1500. This values can be changed according to the network and applications special needs.

$ sudo ip link set mtu 9000 dev ens3
Change MTU
Change MTU

Show Routing Table

Linux provides powerful routing mechanism but this feature is generally used for only Linux host, not for the whole network. The routing table can be listed with the ip route command like below. To list routing table of Linux there is no need for root privilege

$ ip route

OR

$ ip route show
Show Routing Table
Show Routing Table

Add Static Route

Adding route requires root privileges. Adding new root is similar to the adding new IP address as we see below.

$ sudo ip route add 8.8.8.0/24 via 192.168.122.1 dev ens3
Add Static Route
Add Static Route

Remove Static Route

Removing a static route is as easy as adding it. We will change add keyword with del keyword like below. Removing static route also requires root privileges too.

$ sudo ip route del 8.8.8.0/24 via 192.168.122.1 dev ens3
Remove Static Route
Remove Static Route

Persistence Static Route

Adding a route with ip command will make them available for the current run. After boot, the added routes will be deleted because they are not persistence. We will add our routes to the network configuration of the distribution which is different from distribution. We will look at Ubuntu and Fedora-based distributions below.

LEARN MORE  How To Find IP Address On Windows?

Ubuntu, Debian, Kali, Mint:

Add following line to the /etc/network/interfaces file.

up ip route add 8.8.8.0/24 via 192.168.122.1 dev ens3
Persistence Static Route
Persistence Static Route

To enable these persistent static routes without restarting systems restart networking system with the following system.

$ systemctl restart networking

Fedora, RedHat, CentOS:

Add following line to the /etc/sysconfig/network-scripts/route-eth0 where eth0 is the name of the link or interface

8.8.8.0/24 via 192.168.122.1 dev eth0
Persistence Static Route
Persistence Static Route

To enable these persistent static routes without restarting systems restart networking system with the following system.

$ systemctl restart network

List/Show Default Gateway

The default gateway is a route which is preferred to other routes if the destination is not found in the routing table. Listing routes will also list default gateway in the first line like below.

$ ip route show
List Default Gateway
List Default Gateway

default via 192.168.122.1 dev ens3 is our default route

Add Default Gateway

New default gateways can be added to the Linux system. It is like adding new routes by providing default keyword. We do not specify the destination network or host because the default gateway is used for unknown destination networks.

$ sudo ip route add default via 10.0.3.254

Remove Default Gateway

Removing, deleting default gateway or route is very similar to the adding default gateway or route. Changing add keyword with del will remove same added default route like below.

$ sudo ip route del default via 10.0.3.254

List Arp Table

Address resolution protocol is used to identify IP – Mac address matches. Hosts store these matches for some time and then remove from their Arp table. Arp table populated with the known IP – Mac addresses records.

$ ip neighbour
List Arp Table
List Arp Table

IPv6

By default, all ip commands are interpreted as IPv4. If we need to specify IPv6 -6 option can be used. -4 option also used for IPv4

$ ip -6 address show
IPv6
IPv6

Show Bridge Devices

Bridge devices generally used to share some devices with different applications or virtual systems. Bridges devices can be listed with the following command.

$ ip link show type bridge
Show Bridge Devices
Show Bridge Devices

Show Vlan Devices

Virtual Local Area Network’s (VLAN) used to isolated networks in a single physical line. These devices can be listed with the following command.

$ ip link show type vlan

1 thought on “Linux ip Command With Examples- Network Management”

Leave a Comment