How To Use Ip Command In Linux with Examples
http://linoxide.com/linux-command/use-ip-command-linux/
The linux ip command is similar toifconfig, but more powerful and is intended to be a replacement for it. With ip you have the advantage of performing several network administration tasks with only one command. ifconfig is one of the deprecated command within net-tools that has not been maintained for many years. The functionalities of many commands is retained with more features under iproute2 suite.
To install ip download the iproute2 suite utility here, however most Linux distributions will come with the iproute2 tools pre-installed.
You can also use use git to download the source code:
$ git clone https://kernel.googlesource.com/pub/scm/linux/kernel/git/shemminger/iproute2.git
Setting and Deleting an Ip Address
To set an IP address for your computer, the command ip can be used as follows:
$ sudo ip addr add 192.168.0.193/24 dev wlan0
Note that the IP address has a prefix, for example /24. This is used in classless inter-domain routing (CIDR) to show the subnet mask used. In this case the subnet mask is 255.255.255.0.
After you have set the IP address confirm with show, whether the the changes have taken effect.
$ ip addr show wlan0
You can also use the same procedure to delete an IP address by just replacing add with del.
$ sudo ip addr del 192.168.0.193/24 dev wlan0
Show Routing Table Entry
The route object of ip command also helps you to see the route packets will take in your network as set in your routing table. The first entry is the default route which you can change as you prefer.
In this example there are several routes. These are a result of having a several devices connected through different network interface. These include WIFI, Ethernet and a point to point link.
$ ip route show
Suppose now that you have an IP address which you need to know the route packets will take. You can use route option as follows:
$ ip route get 10.42.0.47
Changing The Default Route
To change the default route, the ip command can be used as follows:
$ sudo ip route add default via 192.168.0.196
Show Network Statistics
The ip command can also be used to show the statistics of the various network interfaces. To do this you can use the ip command with the option -s and then specify the network device.
$ ip -s link
When you need to get information about a particular network interface, add the optionls followed by the name of the network interface. The option -s when used more than once gives you more information about that particular interface. This can be very useful especially when trouble shooting errors in network connectivity.
$ ip -s -s link ls p2p1
ARP Entries
Address Resolution Protocol (ARP) is used to translate an IP address to its corresponding physical address, commonly known as MAC address. With ip command you can view the MAC address of the devices connected in your LAN by using the option neigh or neighbour.
$ ip neighbour
Monitor Netlink Messages
It is also possible to view netlink messages with ip command. The monitor option allows you to see the state of your network devices. For instance a computer on your LAN could be categorized as REACHABLE or STALE depending on its status. The command can be used as follows:
$ ip monitor all
Activate and Deactivate Network Interface
To activate an particular interface you can use the ip command with options up and down, almost similar to how ifconfig is used.
In this example you can see the routing table entry when the ppp0 interface is activated and after it is deactivated and activated once again. The interface can be wlan0 or eth0. Change ppp0 to whatever interface is available in your case.
$ sudo ip link set ppp0 down
$ sudo ip link set ppp0 up
Getting Help
In case you get stuck and do not know how a particular option works you can use the help option. The man page does not give a lot of information on how to use the ip options and this is where help comes to the rescue.
For example, to know more about the route option:
$ ip route help
TCP Delayed ACK
From RHEL 7.1 iproute package added support for TCP Delayed ACK. Use below command to enable it
ip route quickack
Conclusion
The command ip is a must have tool for network administrators and all Linux users alike. It is time to move from ifconfig, especially when you are writing scripts.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通