Here are some common use cases for the ip command.
To show the IP addresses assigned to an interface on your server:
[root@server ~]# ip address show
To assign an IP to an interface, for example, enps03:
[root@server ~]# ip address add 192.168.1.254/24 dev enps03
To delete an IP on an interface:
[root@server ~]# ip address del 192.168.1.254/24 dev enps03
Alter the status of the interface by bringing the interface eth0 online:
[root@server ~]# ip link set eth0 up
Alter the status of the interface by bringing the interface eth0 offline:
[root@server ~]# ip link set eth0 down
Alter the status of the interface by changing the MTU of eth0:
[root@server ~]# ip link set eth0 mtu 9000
Alter the status of the interface by enabling promiscuous mode for eth0:
[root@server ~]# ip link set eth0 promisc on
Add a default route (for all addresses) via the local gateway 192.168.1.254 that can be reached on device eth0:
[root@server ~]# ip route add default via 192.168.1.254 dev eth0
Add a route to 192.168.1.0/24 via the gateway at 192.168.1.254:
[root@server ~]# ip route add 192.168.1.0/24 via 192.168.1.254
Add a route to 192.168.1.0/24 that can be reached on device eth0:
[root@server ~]# ip route add 192.168.1.0/24 dev eth0
Delete the route for 192.168.1.0/24 via the gateway at 192.168.1.254:
[root@server ~]# ip route delete 192.168.1.0/24 via 192.168.1.254
Display the route taken for IP 10.10.1.4:
[root@server ~]# ip route get 10.10.1.4
ifconfig
The ifconfig command was/is a staple in many sysadmin's tool belt for configuring and troubleshooting networks. It has since been replaced by the ip command discussed above. However, if you would like more information on it, check out our previously published article here.
mtr
MTR (Matt's traceroute) is a program with a command-line interface that serves as a network diagnostic and troubleshooting tool. This command combines the functionality of the ping and traceroute commands. Just like a traceroute, the mtr command will show the route from a computer to a specified host. mtr provides a lot of statistics about each hop, such as response time and percentage. With the mtr command, you will get more information about the route and be able to see problematic devices along the way. If you see a sudden increase in response time or packet loss, then obviously, there is a bad link somewhere.
The syntax of the command is as follows:
mtr hostname/IP
Let's look at some common use cases.
The basic mtr command shows you the statistics, including each hop (hostnames) with time and loss%:
[root@server ~]# mtr google.com
Show numeric IP addresses (if you use -g, you will get IP addresses (numbers) instead of hostnames):
[root@server ~]# mtr -g google.com
Show the numeric IP addresses and hostnames, too:
[root@server ~]# mtr -b google.com
Set the number of pings that you want to send:
[root@server ~]# mtr -c 10 google.com
Get a report of the mtr command result:
[root@server ~]# mtr -r -c 10 google.com > mtr-command-google-output
or:
[root@server ~]# mtr -rw -c 10 google.com > mtr-command-google-output
Force the use of the TCP instead of the ICMP:
[root@server ~]# mtr –tcp google.com
Force the use of the UDP instead of the ICMP:
[root@server ~]# mtr –udp google.com
Set the maximum amount of hops:
[root@server ~]# mtr -m 35 216.58.223.78
Define the packet size:
[root@server ~]# mtr -r -s 50 google.com
Print to CSV output:
[root@server ~]# mtr –csv google.com
Print to XML output:
[root@server ~]# mtr –xml google.com