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

Analysis of the use of ip commands in Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces "Linux ip command use case analysis". In daily operation, I believe that many people have doubts about the use of Linux ip command case analysis problems. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "Linux ip command use case analysis". Next, please follow the editor to study!

Case 1: check the network card information

Check the network information of the network card, such as IP address, subnet and so on, and use the ip addr show command:

[linuxtechi@localhost] $ip addr show or [linuxtechi@localhost] $ip a s

This will display the network information about all available network cards in the system, but if you want to view the information about a network card, the command is:

[linuxtechi@localhost] $ip addr show enp0s3

Here enp0s3 is the name of the network card.

IP-addr-show-commant-output

Case 2: enable / disable the network card

Use the ip command to enable a disabled network card:

[linuxtechi@localhost] $sudo ip link set enp0s3 up

To disable the Nic, use the down trigger:

[linuxtechi@localhost] $sudo ip link set enp0s3 down case 3: assign IP addresses and other network information to the network card

To assign an IP address to the Nic, we use the following command:

[linuxtechi@localhost] $sudo ip addr add 192.168.0.50 dev enp0s3 255.255.255.0

You can also use the ip command to set the broadcast address. The broadcast address is not set by default, and the command to set the broadcast address is:

[linuxtechi@localhost] $sudo ip addr add broadcast 192.168.0.255 dev enp0s3

We can also use the following command to set a standard broadcast address based on the IP address:

[linuxtechi@localhost] $sudo ip addr add 192.168.0.10 24 dev enp0s3

As shown in the example above, we can use brd instead of broadcast to set the broadcast address.

Case 4: delete the IP address configured in the network card

To delete an IP from the Nic, use the following ip command:

[linuxtechi@localhost] $sudo ip addr del 192.168.0.10 dev enp0s3 24 case 5: add an alias to the network card (assuming the network card name is enp0s3)

Add an alias, that is, add more than one IP to the Nic, execute the following command:

[linuxtechi@localhost] $sudo ip addr add 192.168.0.20 Universe 24 dev enp0s3 label enp0s3:1

Ip-command-add-alias-linux

Case 6: check routing / default gateway information

Looking at the routing information shows us the routing path of the packet to its destination. To view network routing information, execute the following command:

[linuxtechi@localhost] $ip route show

Ip-route-command-output

In the output above, we can see the routing information of packets on all network cards. We can also get routing information for a specific IP by:

[linuxtechi@localhost] $sudo ip route get 192.168.0.1 case 7: add static rout

We can also use IP to modify the default route of the packet. The method is to use the ip route command:

[linuxtechi@localhost] $sudo ip route add default via 192.168.0.150Universe 24

In this way, all network packets are forwarded through 192.168.0.150 instead of the previous default route. To modify the default route of a network card, execute:

[linuxtechi@localhost] $sudo ip route add 172.16.32.32 via 192.168.0.150hip 24 dev enp0s3 case 8: delete default rout

To delete the default route that was previously set, open the terminal and run:

[linuxtechi@localhost] $sudo ip route del 192.168.0.150Universe 24

Note: the default route modified by the above method is only temporary and all changes will be lost after the system restart. To permanently modify the route, you need to modify or create the route-enp0s3 file. Add the following line to it:

[linuxtechi@localhost] $sudo vi / etc/sysconfig/network-scripts/route-enp0s3172.16.32.32 via 192.168.0.150 Universe 24 dev enp0s3

Save and exit the file.

If you are using an operating system based on Ubuntu or debian, the file to be modified is / etc/network/interfaces, and then add the line ip route add 172.16.32.32 via 192.168.0.150 dev enp0s3 to the end of the file.

Case 9: check all ARP records

ARP, an abbreviation for address Resolution Protocol Address Resolution Protocol, is used to translate IP addresses into physical addresses (that is, MAC addresses). All IP and their corresponding MAC details are stored in a table called the ARP cache.

To view the records in the ARP cache, that is, the MAC address of the device connected to the local area network, use the following ip command:

[linuxtechi@localhost] $ip neigh

Ip-neigh-command-linux

Case 10: modify ARP record

The command to delete the ARP record is:

[linuxtechi@localhost] $sudo ip neigh del 192.168.0.106 dev enp0s3

To add a new record to the ARP cache, the command is:

[linuxtechi@localhost] $sudo ip neigh add 192.168.0.150 lladdr 33:1g:75:37:r3:84 dev enp0s3 nud perm

Where nud means "neghbour state" (network neighbor status), its value can be:

Perm-permanently valid and can only be deleted by the administrator noarp-record is valid, but allowed to be deleted after the life cycle expires stale-record is valid, but may have expired reachable-record is valid, but invalidated after timeout case 11: view network statistics

You can also view network statistics through the ip command, such as the number of bytes and messages transmitted on all network cards, the number of errors or discarded messages, and so on. Use the ip-s link command to view:

[linuxtechi@localhost] $ip-s link

Ip-s-command-linux

Case 12: get help

If you want to see an option that is not in the above example, you can check the help. In fact, you can ask for help with any order. To list all the options for the ip command, execute:

[linuxtechi@localhost] $ip help at this point, the study on "ip command use case analysis of Linux" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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