Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the ip command under Linux

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use the ip command under Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.

Linux's ip command is similar to ifconfig, but the former is more powerful and is intended to replace the latter. With the ip command, you can easily perform some network management tasks with just one command. Ifconfig is an obsolete command in net-tools that has been out of maintenance for many years.

Start using modern methods to configure Linux network interfaces.

For a long time, the ifconfig command was the default method for configuring network interfaces. It provides a good service for Linux users, but the network is very complex, so the command to configure the network must be robust. The ip command is the new default network command in modern systems, and in this article, I'll show you how to use it. The ip command works on two layers of the OSI network stack: layer 2 (data link layer) and layer 3 (network or IP). It does all the work of the previous net-tools package.

Install ip

The ip command is included in the iproute2util package, which may already be installed in your Linux distribution. If not, you can install it from the repository of the distribution.

Comparison between ifconfig and ip

Both the ip and ifconfig commands can be used to configure network interfaces, but they do things differently. Next, for comparison, I will use them to perform some common tasks.

Check the network port and IP address

If you want to see the host's IP address or network interface information, the ifconfig (without any parameters) command provides a good summary.

$ifconfigeth0: flags=4099 mtu 1500ether bc:ee:7b:5e:7d:d8 txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0B) RX errors 0 dropped 0 overruns 0 frame 0TX packets 0 bytes 0 (0.0B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73 mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6:: 1 prefixlen 128 scopeid 0x10loop txqueuelen 1000 (Local Loopback) RX packets 41 bytes 5551 (5.4 KiB) RX errors 0 dropped 0 overruns 0 frame 0TX packets 41 bytes 5551 ( KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0wlan0: flags=4163 mtu 1500inet 10.1.1.6 netmask 255.255.255.224 broadcast 10.1.1.31inet6 fdb4:f58e:49f:4900:d46d:146b:b16:7212 prefixlen 64 scopeid 0x0inet6 fe80::8eb3:4bc0:7cbb:59e8 prefixlen 64 scopeid 0x20ether 08:71:90:81:1e:b5 txqueuelen 1000 (Ethernet) RX packets 569459 bytes 779147444 (743.0 MiB) RX errors 0 dropped 0 overruns 0 frame 0TX packets 302882 bytes 38131213 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

The new ip command provides similar results, but the command is ip address show, or abbreviated to ip a:

$ip A1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000link/loopback 1500 qdisc pfifo_fast state DOWN group default qlen 1000link/ether bc:ee:7b:5e:7d:d8 brd ff:ff:ff:ff:ff:ff3 00 brd 00:00:00:00:00:00inet 127.0.0.1 8 scope host lovalid_lft forever preferred_lft foreverinet6:: 1 eth0: mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000link/ether bc:ee:7b:5e:7d:d8 brd ff:ff:ff:ff:ff:ff3: wlan0: Mtu 1500 qdisc noqueue state UP group default qlen 1000link/ether 08:71:90:81:1e:b5 brd ff:ff:ff:ff:ff:ffinet 10.1.1.6 brd 27 brd 10.1.1.31 scope global dynamic wlan0valid_lft 83490sec preferred_lft 83490secinet6 fdb4:f58e:49f:4900:d46d:146b:b16:7212/64 scope global noprefixroute dynamicvalid_lft 6909sec preferred_lft 3309secinet6 fe80::8eb3:4bc0:7cbb:59e8/64 scope linkvalid_lft forever preferred_lft forever add IP address

Use the ifconfig command to add the IP address command as follows:

$ifconfig eth0 add 192.9.203.21

Ip is similar to:

$ip address add 192.9.203.21 dev eth0

The subcommands in ip can be shortened, so the following command is also valid:

$ip addr add 192.9.203.21 dev eth0

You can be even shorter:

$ip an add 192.9.203.21 dev eth0 removes an IP address

Adding an IP address is the opposite of deleting an IP address.

Using ifconfig, the command is:

$ifconfig eth0 del 192.9.203.21

The syntax of the ip command is:

$ip a del 192.9.203.21 dev eth0 enables or disables multicast

Use the ifconfig interface to enable or disable multicast multicast:

# ifconfig eth0 multicast

For ip, use the set subcommand and device (dev) with a Boolean and multicast option:

# ip link set dev eth0 multicast on enables or disables the network

Every system administrator is familiar with the "close, then open" technique to solve the problem. For network interfaces, the network is turned on or off.

The ifconfig command uses the up or down keyword to implement:

# ifconfig eth0 up

Or you can use a special command:

# ifup eth0

The ip command uses the set subcommand to set the network to the up or down state:

# ip link set eth0 up enables or disables address resolution (ARP)

With ifconfig, you can enable it by declaring it

# ifconfig eth0 arp

Using ip, you can set the arp property to on or off:

# ip link set dev eth0 arp on Thank you for reading this article carefully. I hope the article "how to use ip commands under Linux" shared by the editor will be helpful to you. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report