Linux's IP commands are similar to Ifconfig, but the former is more powerful and intended to replace the latter. With the IP command, you can easily perform some network administration tasks with just one command. Ifconfig is a command that has been deprecated in net-tools and has not been maintained for many years. Many of the enhanced commands are available in the Iproute2 suite, which is one of the IP commands.
Net Tools vs Iproute2
To install the IP, click here to download the Iproute2 Kit tool. However, most Linux distributions already have the Iproute2 tool preinstalled.
You can also use the git command to download the latest source code to compile:
- $ git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/shemminger/ Iproute2.git
Iproute2 git clone
Setting and removing IP addresses
To set an IP address for your machine, you can use the following IP commands:
- $ sudo ip addr Add 192.168. 0.193/ dev wlan0
Please note that the IP address must have a suffix, such as/24. This usage is used to display the subnet mask used in the no-class intra-domain routing (CIDR). In this example, the subnet mask is 255.255.255.0.
Once you've set up your IP address as described above, you'll need to see if it's already in effect.
- $ ip addr show wlan0
Set IP Address
You can also delete the IP address in the same way, just use del instead of Add.
- $ sudo ip addr del 192.168. 0.193/ dev wlan0
Delete IP Address
List the way out by table entry
The parameters of the routing object for the IP command also help you to view the routing data in the network and set up your routing table. The first entry is the default route entry, and you can change it at will.
In this example, there are several routing entries. This result shows that several devices are connected by different network interfaces. They include WiFi, Ethernet, and a point-to-point connection.
- $ IP Route show
IP Route Show
Assuming you now have an IP address, you need to know where the routing packets are coming from. You can use the following routing options: Lists the interfaces used by the route, and so on:
- $ IP route get 10.42. 0.47
IP Route Get
Change the default route
To change the default route, use the following IP command:
- $ sudo IP route add default via 192.168. 0.196
Default route
displaying network statistics
You can also use the IP command to display statistics for different network interfaces.
IP Statistics all interfaces
When you need to get information about a particular network interface, add the option LS after the network interface name. Using multiple options-S will give you more detailed information about this particular interface. This is especially useful when troubleshooting network connections.
- $ IP -s -s link ls p2p1
IP link Statistics
ARP entry
The Address Resolution Protocol (ARP) is used to translate an IP address into its corresponding physical address, which is commonly referred to as the MAC address. Using the Neigh or neighbour option of the IP command, you can view the MAC address of the device that is connected to your local area network.
- $ IP neighbour
IP neighbour
Monitoring NetLink messages
You can also use the IP command to view netlink messages. The monitor option allows you to view the status of network devices. For example, a computer on the local area network can be classified as reachable or stale depending on its state. Use the following command:
- $ IP monitor All
IP Monitor All
Activating and stopping network interfaces
You can use the up and down options of the IP command to stress a particular interface, just like the usage of ifconfig.
In this example, when the Ppp0 interface is activated and after it is stopped and activated again, you can see the corresponding routing table entry. This interface may be wlan0 or eth0. Change the ppp0 to any interface that you can use.
- $ sudo ip link set ppp0 down
- $ sudo ip link set ppp0 up
IP link set up and down
Get help
You can use the Help option when you're in trouble and don't know how to use a particular option. The man page does not provide much information on how to use IP options, so here is where to get help.
For example, to find out more about the route options:
- $ IP route Help
IP route Help
Summary
For network administrators and all Linux users, the IP command is a must-have tool. It's time to abandon the ifconfig command, especially when you're writing a script.
IP commands under Linux