Table of Contents
In this article, we will look into 25 Popular Linux IP Command Examples and how to check Linux IP Address. If you are a Linux Professional then you might be aware of ifconfig command which is around from past many years as part of net-tools package. Similarly other net-tools packages command like route is also in use from quite sometime now. All these commands are now replaced by a new set of tools called iproute2. This packages provides ip command which can be used for achieving various network management tasks in Linux with some advance features over earlier set of commands. In this session, we will try to look the various usages of ip command.
Syntax
ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
25 Popular Linux IP Command Examples(How to check Linux IP Address)
Also Read: 10 Useful iproute2 tools examples to Manage Network Connections in Linux
Example 1: Check Linux IP Command Version
If you want to check the Linux ip command version then you need to use ip -V
command as shown below. As you can see from below output, ip utility is a part of iproute2-ss180813
package.
[root@localhost ~]# ip -V ip utility, iproute2-ss180813
NOTE:
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: Check Linux IP Address
If you want to check the ip address of all the network interfaces then you need to use ip addr sh
command as shown below. This command output will give you multiple information about the network interface such as IPV4 Address, IPV6 Address, MAC Address, Broadcast Address, MTU Size etc.
[root@localhost ~]# ip addr sh 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 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:1a:91:9b brd ff:ff:ff:ff:ff:ff inet 192.168.0.103/24 brd 192.168.0.255 scope global dynamic enp0s3 valid_lft 4543sec preferred_lft 4543sec inet6 fe80::a00:27ff:fe1a:919b/64 scope link valid_lft forever preferred_lft forever
Example 3: Check IP Rule List
If you want to check all ip rule list then you need to use ip rule list
command as shown below.
[root@localhost ~]# ip rule list 0: from all lookup local 32766: from all lookup main 32767: from all lookup default
Example 4: Check IP Link Status
If you want to check the status of connected network interface then you need to use ip link show
command as shown below.
[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 fq_codel state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:1a:91:9b brd ff:ff:ff:ff:ff:ff
Example 5: Check Link Stats using Linux ip command
If you want to check the packet stats of all connected network interfaces then you need to use ip -s link
command as shown below.
[root@localhost ~]# ip -s link 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 RX: bytes packets errors dropped overrun mcast 0 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 0 0 0 0 0 0 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether 08:00:27:1a:91:9b brd ff:ff:ff:ff:ff:ff RX: bytes packets errors dropped overrun mcast 63208631 46763 0 0 0 81 TX: bytes packets errors dropped carrier collsns 1192191 11813 0 0 0 0
Example 6: Check Routing Table using Linux ip command
If you want to check the current routing table then you need to use ip route show
command as shown below.
[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.103
Example 7: Display State of Devices Continuously using Linux ip command
If you want to display state of devices in continuous screen then you need to use ip monitor
command as shown below. This command is very useful in case of any network troubleshooting.
[root@localhost ~]# ip monitor 192.168.0.102 dev enp0s3 lladdr 28:16:ad:1c:43:46 REACHABLE 192.168.0.1 dev enp0s3 lladdr c4:6e:1f:49:44:7a STALE 192.168.0.102 dev enp0s3 lladdr 28:16:ad:1c:43:46 STALE 192.168.0.102 dev enp0s3 lladdr 28:16:ad:1c:43:46 PROBE 192.168.0.102 dev enp0s3 lladdr 28:16:ad:1c:43:46 REACHABLE
Example 8: Display MAC Addresses of the Connected System
If you want to display MAC addresses of all the connected system then you need to use ip neighbor
command as shown below.
[root@localhost ~]# ip neighbor 192.168.0.102 dev enp0s3 lladdr 28:16:ad:1c:43:46 REACHABLE 192.168.0.1 dev enp0s3 lladdr c4:6e:1f:49:44:7a STALE
Example 9: Assign an IP Address to a network interface
If you want assign an ip address to a network interface then you need to use below ip addr add
command. Here we are assigning IPv4 address 192.168.0.100
to interface enp0s3
.
[root@localhost ~]# ip addr add 192.168.0.100 dev enp0s3
Example 10: Enable multicast feature on Network Interface
If you want to enable multicast feature on a network interface then you need to use below Linux ip
command. In this example, we are enabling multicast feature on network interface enp0s3
.
[root@localhost ~]# ip link set enp0s3 multicast on
Example 11: Disable multicast feature on Network Interface
Similarly if you want to disable multicast feature on interface enp0s3 then you need to use ip link set enp0s3 multicast off
command as shown below.
[root@localhost ~]# ip link set enp0s3 multicast off
Example 12: Change MTU Size using Linux ip command
If you want to change the Maximum Transmission Unit size for interface enp0s3 to 1200 then you need to use ip link set enp0s3 mtu 1200
command as shown below.
[root@localhost ~]# ip link set enp0s3 mtu 1200
Example 13: Change Packet Queue Length using Linux ip command
If you want to change the Packet Queue Length then you need to use below Linux ip command. In this example we are changing packet queue Length of enp0s3 network interface using ip link set enp0s3 txqueuelen 900
command as shown below.
[root@localhost ~]# ip link set enp0s3 txqueuelen 900
Example 14: Enable ARP Feature on the Network Interface using Linux ip command
If you want to enable ARP feature then you need to use below Linux ip command. In this example, we are enabling ARP feature using ip link set enp0s3 arp on
command.
[root@localhost ~]# ip link set enp0s3 arp on
Example 15: Disable ARP Feature on the Network Interface
If you want to disable ARP feature then you need to use below Linux ip command. In this example, we are disabling ARP feature using ip link set enp0s3 arp off
command.
[root@localhost ~]# ip link set enp0s3 arp off
Example 16: Rename Your Network Interface Using Linux ip command
If you want to rename your network interface then you need to use below Linux ip command. In this example, we are renaming our network interface enp0s3 to eth0 using ip link set enp0s3 name eth0
command.
[root@localhost ~]# ip link set enp0s3 name eth0
Example 17: Check the Rule in multicast routing policy database
If you want to check the rule in multicast routing policy database then you need to use ip mrule show
command as shown below.
[root@localhost ~]# ip mrule show 32767: from all lookup default
Example 18: Check the Neighbor Table Parameters and Statistics
If you want to check the neighbor table parameters then you need to use ip ntable show dev enp0s3
command as shown below.
[root@localhost ~]# ip ntable show dev enp0s3 inet arp_cache dev enp0s3 refcnt 3 reachable 27511 base_reachable 30000 retrans 1000 gc_stale 60000 delay_probe 5000 queue 31 app_probes 0 ucast_probes 3 mcast_probes 3 anycast_delay 1000 proxy_delay 800 proxy_queue 64 locktime 1000 inet6 ndisc_cache dev enp0s3 refcnt 1 reachable 33346 base_reachable 30000 retrans 1000 gc_stale 60000 delay_probe 5000 queue 31 app_probes 0 ucast_probes 3 mcast_probes 3 anycast_delay 1000 proxy_delay 800 proxy_queue 64 locktime 0
Example 19: Change the Number of Packets Queued
If you want to change the number of packets queued then you need to use the below ip ntable command. In this example we are changing arp_cache queue parameter value from 31 to 35 for interface enp0s3 using ip ntable change name arp_cache queue 35 dev enp0s3
command as shown below.
[root@localhost ~]# ip ntable change name arp_cache queue 35 dev enp0s3
Check if the number of packets has changed or not. More information can be checked on ip ntable man page.
[root@localhost ~]# ip ntable show dev enp0s3 inet arp_cache dev enp0s3 refcnt 3 reachable 27511 base_reachable 30000 retrans 1000 gc_stale 60000 delay_probe 5000 queue 35 app_probes 0 ucast_probes 3 mcast_probes 3 anycast_delay 1000 proxy_delay 800 proxy_queue 64 locktime 1000 inet6 ndisc_cache dev enp0s3 refcnt 1 reachable 33346 base_reachable 30000 retrans 1000 gc_stale 60000 delay_probe 5000 queue 31 app_probes 0 ucast_probes 3 mcast_probes 3 anycast_delay 1000 proxy_delay 800 proxy_queue 64 locktime 0
Example 20: Create a Tunnel Using Linux ip command
If you want to create a Tunnel in Linux then you need to use below ip tunnel command. In this example, we are creating a tunnel tunnel0 for peer 192.168.0.110 using ip tunnel add tunnel0 mode sit remote 192.168.0.110
command as shown below.
[root@localhost ~]# ip tunnel add tunnel0 mode sit remote 192.168.0.110
Check if the tunnel has created or not using ip tunnel show
command.
[root@localhost ~]# ip tunnel show sit0: ipv6/ip remote any local any ttl 64 nopmtudisc 6rd-prefix 2002::/16 tunnel0: ipv6/ip remote 192.168.0.110 local any ttl inherit 6rd-prefix 2002::/16
Example 21: Bring Up Tunnel in Linux
If you want to bring up the tunnel created in above example then you need to use ip link set tunnel0 up
command as shown below.
[root@localhost ~]# ip link set tunnel0 up
Example 22: Bring down Tunnel in Linux
Similarly, If you want to bring down the tunnel then you need to use ip link set tunnel0 down
command as shown below.
[root@localhost ~]# ip link set tunnel0 down
Example 23: Check Tunnel Status using Linux ip command
If you want to check the status of a tunnel then you need to use ip link show dev tunnel0
command to check tunnel0 status as shown below.
[root@localhost ~]# ip link show dev tunnel0 4: tunnel0@NONE: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1480 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/sit 0.0.0.0 peer 192.168.0.110
Example 24 : Delete a Tunnel using Linux ip command
If you want to delete a tunnel then you need to use below ip tunnel command. In this example, we are trying to delete a tunnel tunnel0 using ip tunnel del tunnel0
command as shown below.
[root@localhost ~]# ip tunnel del tunnel0
Example 25: Check Other ip command options
If you want to check all the other options available with ip command then you need to use ip --help
command as shown below.
[root@localhost ~]# ip --help Usage: ip [ OPTIONS ] OBJECT { COMMAND | help } ip [ -force ] -batch filename where OBJECT := { link | address | addrlabel | route | rule | neigh | ntable | tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm | netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila | vrf } OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] | -h[uman-readable] | -iec | -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } | -4 | -6 | -I | -D | -B | -0 | -l[oops] { maximum-addr-flush-attempts } | -br[ief] | -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] | -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}
Recommended Posts:-
Understanding Kafka Console Producer and Consumer in 10 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
[Solved] bash: ifconfig: command not found
How to find files and directories in Linux
Step by Step to Install Caine OS on Virtualbox [Complete Guide]