The Linux IP command

Source: Internet
Author: User

The IP command is a network configuration tool for Route2 that replaces commands such as Ifconfig,route. This command is only temporarily added, and restarting the NIC IP is lost.


Common parameters

Link: Often used to see the net view properties

Addr: For configuring/removing multiple IPs

Route: Used to configure routing information

Rule: Used to view the routing table


Detailed command:


IP link: Mainly used to view network card properties, or turn on, turn off the network card


Show

Set


Example: Show

[[Email protected] ~]# IP link show # # # # #查看所有网卡的硬件属性, not including the IP address

1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN

Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00

2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000

Link/ether 00:0c:29:01:bf:a0 BRD FF:FF:FF:FF:FF:FF

3:eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000

Link/ether 00:0C:29:01:BF:AA BRD FF:FF:FF:FF:FF:FF


[Email protected] ~]# IP link show eth0 ####### #查看某一块网卡信息

2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000

Link/ether 00:0c:29:01:bf:a0 BRD FF:FF:FF:FF:FF:FF


[[email protected] ~]# ip-s link show eth1 ######-s parameter view statistics

3:eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000

Link/ether 00:0C:29:01:BF:AA BRD FF:FF:FF:FF:FF:FF

Rx:bytes packets Errors dropped overrun Mcast

2085187 28951 0 0 0 0

Tx:bytes packets errors dropped carrier Collsns

5161 35 0 0 0 0

Example: Set

# IP Link set eth1 up|down # # # #关闭或开始某个网卡


IP addr: for managing multiple IPs


Add adds an IP

del Delete IP

Show Display IP

Flush Empty IP

Cases:

[[Email protected] ~]# IP addr Add 10.1.8.16/8 dev eth1 # # #eth1增加IP, and no aliases used

[[Email protected] ~]# IP addr

1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN

Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00

inet 127.0.0.1/8 Scope host Lo

INET6:: 1/128 Scope Host

Valid_lft Forever Preferred_lft Forever

2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000

Link/ether 00:0c:29:01:bf:a0 BRD FF:FF:FF:FF:FF:FF

inet 172.16.16.173/24 BRD 172.16.16.255 Scope Global eth0

Inet6 FE80::20C:29FF:FE01:BFA0/64 Scope link

Valid_lft Forever Preferred_lft Forever

3:eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000

Link/ether 00:0C:29:01:BF:AA BRD FF:FF:FF:FF:FF:FF

inet 192.168.7.173/24 BRD 192.168.7.255 Scope Global eth1

inet 10.1.8.16/8 Scope Global eth1 Note: Ifconfig not see

Inet6 FE80::20C:29FF:FE01:BFAA/64 Scope link

Valid_lft Forever Preferred_lft Forever

[[Email protected] ~]# IP addr Add 192.168.29.10/24 dev eth1 label eth1:1

Add a child card by using the Label keyword

[Email protected] ~]# ifconfig

Eth0 Link encap:ethernet HWaddr 00:0c:29:01:bf:a0

inet addr:172.16.16.173 bcast:172.16.16.255 mask:255.255.255.0

Inet6 ADDR:FE80::20C:29FF:FE01:BFA0/64 Scope:link

Up broadcast RUNNING multicast mtu:1500 metric:1

RX packets:27735 errors:0 dropped:0 overruns:0 frame:0

TX packets:549 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:1978580 (1.8 MiB) TX bytes:67070 (65.4 KiB)


eth1 Link encap:ethernet HWaddr 00:0C:29:01:BF:AA

inet addr:192.168.7.173 bcast:192.168.7.255 mask:255.255.255.0

Inet6 ADDR:FE80::20C:29FF:FE01:BFAA/64 Scope:link

Up broadcast RUNNING multicast mtu:1500 metric:1

RX packets:31549 errors:0 dropped:0 overruns:0 frame:0

TX packets:35 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:2277774 (2.1 MiB) TX bytes:5161 (5.0 KiB)


eth1:1 Link encap:ethernet HWaddr 00:0c:29:01:bf:aa

inet addr:192.168.29.10 bcast:0.0.0.0 mask:255.255.255.0

Up broadcast RUNNING multicast mtu:1500 metric:1


Lo Link encap:local Loopback

inet addr:127.0.0.1 mask:255.0.0.0

Inet6 addr::: 1/128 scope:host

Up LOOPBACK RUNNING mtu:16436 metric:1

RX packets:16 errors:0 dropped:0 overruns:0 frame:0

TX packets:16 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:960 (960.0 b) TX bytes:960 (960.0 b)


[[Email protected] ~]# IP addr del 192.168.29.10/24 dev eth1:1 # # #删除eth1:1


[Email protected] ~]# ifconfig

Eth0 Link encap:ethernet HWaddr 00:0c:29:01:bf:a0

inet addr:172.16.16.173 bcast:172.16.16.255 mask:255.255.255.0

Inet6 ADDR:FE80::20C:29FF:FE01:BFA0/64 Scope:link

Up broadcast RUNNING multicast mtu:1500 metric:1

RX packets:29138 errors:0 dropped:0 overruns:0 frame:0

TX packets:627 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:2083498 (1.9 MiB) TX bytes:76506 (74.7 KiB)


eth1 Link encap:ethernet HWaddr 00:0C:29:01:BF:AA

inet addr:192.168.7.173 bcast:192.168.7.255 mask:255.255.255.0

Inet6 ADDR:FE80::20C:29FF:FE01:BFAA/64 Scope:link

Up broadcast RUNNING multicast mtu:1500 metric:1

RX packets:32839 errors:0 dropped:0 overruns:0 frame:0

TX packets:35 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:1000

RX bytes:2372722 (2.2 MiB) TX bytes:5161 (5.0 KiB)


Lo Link encap:local Loopback

inet addr:127.0.0.1 mask:255.0.0.0

Inet6 addr::: 1/128 scope:host

Up LOOPBACK RUNNING mtu:16436 metric:1

RX packets:16 errors:0 dropped:0 overruns:0 frame:0

TX packets:16 errors:0 dropped:0 overruns:0 carrier:0

collisions:0 txqueuelen:0

RX bytes:960 (960.0 b) TX bytes:960 (960.0 b)


[Email protected] ~]# IP addr del 10.1.8.16/8 dev eth1 # # # #删除IP


[[Email protected] ~]# IP addr Show

1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN

Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00

inet 127.0.0.1/8 Scope host Lo

INET6:: 1/128 Scope Host

Valid_lft Forever Preferred_lft Forever

2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000

Link/ether 00:0c:29:01:bf:a0 BRD FF:FF:FF:FF:FF:FF

inet 172.16.16.173/24 BRD 172.16.16.255 Scope Global eth0

Inet6 FE80::20C:29FF:FE01:BFA0/64 Scope link

Valid_lft Forever Preferred_lft Forever

3:eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000

Link/ether 00:0C:29:01:BF:AA BRD FF:FF:FF:FF:FF:FF

inet 192.168.7.173/24 BRD 192.168.7.255 Scope Global eth1

Inet6 FE80::20C:29FF:FE01:BFAA/64 Scope link

Valid_lft Forever Preferred_lft Forever


IP route

Show: Show routes

Add: Add route

Del: Delete route


[[Email protected] ~]# IP route show view route

192.168.7.0/24 Dev eth1 proto kernel scope link src 192.168.7.173

172.16.16.0/24 Dev eth0 proto kernel scope link src 172.16.16.173

169.254.0.0/16 Dev eth0 scope link metric 1002

10.0.0.0/8 Dev eth1 proto kernel scope link src 10.1.5.10

[[email protected] ~]# route-n View route

Kernel IP Routing Table

Destination Gateway genmask Flags Metric Ref use Iface

192.168.7.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

172.16.16.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0

169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0

10.0.0.0 0.0.0.0 255.0.0.0 U 0 0 0 eth1


[[Email protected] ~]# IP route add 10.0.8.0/24 via 192.168.7.1

Equivalent to: IP route add 10.0.8.0/24 dev eth1

[[Email protected] ~]# IP route Show

192.168.7.0/24 Dev eth1 proto kernel scope link src 192.168.7.173

172.16.16.0/24 Dev eth0 proto kernel scope link src 172.16.16.173

10.0.8.0/24 via 192.168.7.1 Dev eth1

169.254.0.0/16 Dev eth0 scope link metric 1002


[Email protected] ~]# IP route del 10.0.8.0/24

[Email protected] ~]# IP route show ####### #删除路由

192.168.7.0/24 Dev eth1 proto kernel scope link src 192.168.7.173

172.16.16.0/24 Dev eth0 proto kernel scope link src 172.16.16.173

169.254.0.0/16 Dev eth0 scope link metric 1002


IP rule: View default routes, policy routes, local routes

Show|list

[[Email protected] ~]# IP rule Show

0: from all lookup local

32766:from all lookup main

32767:from all lookup default


The Linux IP command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.