Cyberithub

10 Useful iproute2 tools examples to Manage Network Connections in Linux

Advertisements

In this article, I will take you through different iproute2 tools examples to manage Network Connections in Linux. You might have used tools from net-tools package to manage your kernel static routes and manage other Network related infrastructure but over the time it has become obsolete now since its development stopped long back and now there is a latest iproute2 package with new set of tools like ip command available to manage network connections in Linux. In this session, we will look into multiple examples and usages of iproute2 tools in Linux.

10 Useful iproute2 tools examples to Manage Network Connections in Linux 1

iproute2 tools examples in Linux

Also Read: 11 Best Linux route command examples (How to add route in Linux)

Example 1: How to Check Current Route using ip command

In the traditional net-tools package you might have used route -n command to check all the static routes. You might want to check How to install route command on Linux(RedHat/CentOS 7/8) Using 5 Easy Steps.

[root@localhost ~]# route -n
Kernel IP routing table
Destination    Gateway    Genmask      Flags Metric Ref Use Iface
0.0.0.0      192.168.0.1  0.0.0.0       UG     0     0   0  enp0s3
192.168.0.0    0.0.0.0    255.255.255.0 U      0     0   0  enp0s3

But if you want to check the routes using latest iproute2 tools then you need to use ip ro command as shown below.

[root@localhost ~]# ip ro
default via 192.168.0.1 dev enp0s3
192.168.0.0/24 dev enp0s3 proto kernel scope link src 192.168.0.100

NOTE:

Please note that here I am using root user to run all the below commands.You can use any user with sudo access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

Example 2: How to check IPV4/IPV6 Address of a Network Interface

Similarly, in the traditional net-tools package you might be using ifconfig enp0s3 command to check the IPV4 or IPV6 Address of interface enp0s3. You might also want to check How to List/Get/Display/Find MAC Address in Linux Using 11 Popular Methods.

[root@localhost ~]# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.100 netmask 255.255.255.0 broadcast 192.168.0.255
ether 08:00:27:1d:8e:54 txqueuelen 1000 (Ethernet)
RX packets 4039 bytes 506945 (495.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2975 bytes 672077 (656.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

But If you want to view the IPv4 or IPv6 address of a network interface using latest iproute2 tools then you need to use ip add sh enp0s3 command as shown below.

[root@localhost ~]# ip add sh enp0s3
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 08:00:27:1d:8e:54 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.100/24 brd 192.168.0.255 scope global dynamic enp0s3
valid_lft 2332sec preferred_lft 2332sec

Example 3: How to check neighbor address

If you want to check all the connected neighbor ip address then you need to use ip neighbor command as shown below. You might want to check 25 Popular Linux IP Command Examples(How to check Linux IP Address).

[root@localhost ~]# ip neighbor
192.168.0.101 dev enp0s3 lladdr 28:16:ad:1c:43:46 DELAY
192.168.0.1 dev enp0s3 lladdr c4:6e:1f:49:44:7a REACHABLE

Example 4: How to check the connected interface Link

If you want to check only Link status of all network interfaces then you need to use ip link show command. You can notice from below output that this command will not show any ipv4 address.

[root@localhost ~]# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:1d:8e:54 brd ff:ff:ff:ff:ff:ff

Example 5: How to set an IPV4 Address in Linux 

If you want to set an ipv4 address to your network interface then you need to use below ip command. In this example, we are setting ip address of enp0s3 interface to 192.168.0.100 using ip addr add 192.168.0.100 dev enp0s3 command as shown below.

[root@localhost ~]# ip addr add 192.168.0.100 dev enp0s3

Example 6: How to enable a Network Interface in Linux

If you want to enable a network interface in Linux then you need to use below ip link command. In this example we are enabling enp0s3 interface using ip link set enp0s3 up command.

[root@localhost ~]# ip link set enp0s3 up

Example 7: How to disable a Network Interface in Linux

Similarly, if you want to disable a network interface in Linux then you need to use below ip link command. In this command, we are disabling enp0s3 interface using ip link set enp0s3 down command.

[root@localhost ~]# ip link set enp0s3 down

NOTE:

Please be very sure before disabling your network interface specially when you are running this command on a Production System. It could be catastrophic if you disable the incorrect network interface.

Example 8: How to Add a route in Linux

If you want to add a route a linux then you need to use below ip route add command. In this example, we are adding route 20.0.0.0/24 through 192.168.0.1 using ip ro add 20.0.0.0/24 via 192.168.0.1 command as shown below.

[root@localhost ~]# ip ro add 20.0.0.0/24 via 192.168.0.1

Now check again if the route is added or not using ip ro sh command as shown below.

[root@localhost ~]# ip ro sh
default via 192.168.0.1 dev enp0s3
20.0.0.0/24 via 192.168.0.1 dev enp0s3
192.168.0.0/24 dev enp0s3 proto kernel scope link src 192.168.0.100

Example 9: How to delete a route in Linux

If you want to delete a route then you need to use below ip route del command. In this example we are deleting a route 20.0.0.0/24 which we added in the previous example using ip ro del 20.0.0.0/24 via 192.168.0.1 command.

[root@localhost ~]# ip ro del 20.0.0.0/24 via 192.168.0.1

Now you can again run ip route show command and check if the route is deleted or not.

[root@localhost ~]# ip route show
default via 192.168.0.1 dev enp0s3
192.168.0.0/24 dev enp0s3 proto kernel scope link src 192.168.0.100

Example 10: How to check tunnel status in Linux

There is an important tunnel feature available with iproute2 tool. If you want to check the tunnel status in Linux then you need to use ip tunnel show command as shown below.

[root@localhost ~]# ip tunnel show
sit0: ipv6/ip remote any local any ttl 64 nopmtudisc 6rd-prefix 2002::/16

 

 

Recommended Posts:-

How to delete Volume Group (LVM) in Linux Using 5 Easy Steps

Popular firewalld examples to open a port on RedHat/CentOS 7

8 Most Popular mkdir command in Linux with Examples

26 Useful Firewall CMD Examples on RedHat/CentOS 7

12 Most Popular rm command in Linux with Examples

9 useful w command in Linux with Examples

Popular Apache Kafka Architecture Explained Using 4 Basic Components

5 Easy Steps to recover LVM2 Partition , PV , VG , LVM metadata in Linux

Leave a Comment