Linux ip command example

Source: Internet
Author: User
Linux ip command example

IP

1. Role
IP is a powerful network configuration tool in the iproute2 software package. It can replace some traditional network management tools, such as ifconfig and route, and use permissions as superusers. Almost all Linux releases support this command.

2. Format
IP [Options] object [Command [arguments]

3. Main Parameters
Options is an option for modifying IP behavior or changing its output. All options start with a-character, which can be long or short. Currently, IP supports the options shown in table 1.

An object is an object for administrators to obtain information. Currently, the IP addresses are identified in table 2.

Table 1 IP support options

-V and-version print the IP version and exit.
-S,-stats, and-Statistics Output more detailed information. If this option appears twice or multiple times, the output information is more detailed.
The-F,-family option is followed by the protocol type, including Inet, inet6, or link, emphasizing the protocol type used. If there is not enough information to tell the protocol type used by the IP address, the default value is Inet or any. Link is special. It indicates that no network protocol is involved.
-4 is short for-family inet.
-6 is short for-family inet6.
-0 is short for-family link.
-O and-oneline use single-line output for each record and replace the returned row with characters. This option is used if you need to use tools such as WC and grep to process IP output.
-R,-resolve queries the domain name resolution system and replaces the Host IP address with the obtained Host Name

Command sets the operation performed on the specified object, which is related to the object type. Generally, IP addresses support adding, deleting, and displaying objects ). Some objects do not support these operations, or some other commands. For all objects, you can use the help command for help. This command lists the commands and parameter syntaxes supported by this object. If no operation command is specified for an object, the IP address uses the default command. Generally, the default command is list. If the object cannot be listed, the Help Command is executed.

Arguments are some parameters of commands, which depend on objects and commands. IP supports two types of parameters: flag and parameter. Flag is composed of a keyword. parameter is composed of a keyword and a value. For convenience, each command has a default parameter that can be ignored. For example, the dev parameter is the default parameter of the IP link command, so IP link ls eth0 is equal to IP link ls Dev eth0. We will detail the use of each command in the following sections. The default parameters of the command will be marked with default.

4.1 IP link set -- change device properties. Abbreviation: Set, S

Example 1: up/down start/Close the device.

# IP link set Dev eth0 up

This is equal to the traditional # ifconfig eth0 up (down)

Example 2: change the length of the device transmission queue.

Parameter: txqueuelen number or txqlen number

# IP link set Dev eth0 txqueuelen 100

Example 3: Change the MTU value of the network device.

# IP link set Dev eth0 MTU 1500

Example 4: Modify the MAC address of a network device.

Parameter: Address lladdress

# IP link set Dev eth0 address 00: 01: 4f: 00: 15: F1

4.2 IP link show -- display device properties. Abbreviations: Show, list, lst, sh, ls, l

If the-s option appears twice or more times, the IP will output more detailed error information statistics.

Example:

# IP-s link ls eth0

Eth0: MTU 1500 qdisc CBQ qlen 100

Link/ether 00: A0: CC: 66: 18: 78 brd ff: FF

RX: bytes packets errors dropped overrun MCAST

2449949362 2786187 0 0 0 0

RX errors: length CRC frame FIFO missed

0 0 0 0 0

TX: bytes packets errors dropped carrier collsns

178558497 1783946 332 0 332 35172

TX errors: aborted FIFO window heartbeat

0 0 0 332

This command is equivalent to the traditional ifconfig eth0

5.1 IP address add -- Add a new Protocol address. Abbreviation: add,

Example 1: Set a string for each address as a tag. To be compatible with the Linux-2.0's network alias, this string must start with the device name, followed by a colon,

# Ip addr add local 192.168.4.1/28 BRD + label eth0: 1 Dev eth0

Example 2: add an IP address 192.168.20.0 to the Ethernet interface eth0. The mask length is 24 bits (155.155.155.0), the standard broadcast address, and the label is eth0: alias:

# Ip addr add 192.168.4.2/24 BRD + Dev eth1 label eth1: 1

This command is equivalent to the traditional: ifconfig eth1: 1 192.168.4.2

5.2 IP address Delete -- delete a Protocol address. Abbreviations: delete, Del, and D

# Ip addr del 192.168.4.1/24 BRD + Dev eth0 label eth0: alias1

5.3 IP address show -- display Protocol address. Abbreviation: Show, list, lst, sh, ls, l

# Ip addr ls eth0

5.4.ip address flush -- clear Protocol address. Abbreviation: flush, F

Example 1: Delete all addresses in the private network 10.0.0.0/8:

# IP-s a f-10/8

Example 2: cancel the IP addresses of all Ethernet cards

# IP-4 ADDR flush label "eth0"

6. IP neighbor -- neighbor/ARP table management command

Abbreviations: neighbor, neighbor, neigh, n

Command add, change, replace, delete, fulsh, show (or list)

6.1 IP neighbor add -- Add a new adjacent entry

IP neighbor change -- modify an existing entry

IP neighbor Replace -- replace an existing entry

Abbreviation: add, A; change, chg; replace, REPL

Example 1: Add a permanent ARP entry for address 10.0.0.3 on the eth0:

# IP neigh add 10.0.0.3 lladdr 0: 0: 0: 0: 0: 1 Dev eth0 NUD perm

Example 2: change the status to reachable.

# IP neigh chg 10.0.0.3 Dev eth0 NUD reachable

6.2.ip neighbor Delete -- delete an adjacent entry

Example 1: delete an ARP entry 10.0.0.3 on the eth0 device.

# IP neigh del 10.0.0.3 Dev eth0

6.3.ip neighbor show -- display network neighbor information. Abbreviations: Show, list, sh, ls

Example 1: # IP-S n ls 193.233.7.254

193.233.7.254. Dev eth0 lladdr 00: 00: 0C: 76: 3f: 85 ref 5 used 12/13/20 NUD reachable

6.4.ip neighbor flush -- clear the adjacent entries. Abbreviations: flush, F

Example 1: (-S can display details)

# IP-s n f 193.233.7.254

7. Route table management

. Abbreviated route, Ro, R

7. 5. Route table

Starting from the Linux-2.2, the kernel has summarized the route into many routing tables that are numbered in the range of numbers 1 to 255. In addition,

For convenience, you can also name the route table in/etc/iproute2/rt_tables.

By default, all routes are inserted into the main table (No. 254. During route query, the kernel only uses the route table main.

7.6.ip route add -- Add a new route entry

IP route change -- modify a route

IP Route Replace -- replace existing routes

Abbreviation: add, A; change, chg; replace, REPL

Example 1: The route destined for 10.0.0/24 goes through the gateway 193.233.7.65

# IP Route add 10.0.0/24 Via 193.233.7.65

Example 2: Modify the direct route to 10.0.0/24 so that it passes through the device dummy

# IP Route chg 10.0.0/24 Dev dummy

Example 3: Achieve link load balancing. Add the default multi-path routing to share the load between ppp0 and ppp1 (Note: The scope value is not required, but it only tells the kernel,

This route must go through the gateway instead of directly connected. In fact, if you know the address of the remote endpoint, it is better to use the via Parameter ).

# IP Route add default scope global nexthop Dev ppp0 nexthop Dev ppp1

# IP Route replace default scope global nexthop Dev ppp0 nexthop Dev ppp1

Example 4: configure a NAT route. Before forwarding a packet from 192.203.80.144, convert the network address to 193.233.7.83.

# IP Route add Nat 192.203.80.142 via 193.233.7.83

Example 5: Achieve Packet-level load balancing and allow random packet sending from multiple routes. You can set the weight for weight.

# IP Route replace default equalize nexthop via 211.139.218.145 Dev eth0 weight 1 nexthop via 211.139.218.145 Dev eth1 weight 1

7.7.ip route Delete -- delete a route

Abbreviation: delete, Del, d

Example 1: Delete the multi-path route added to the previous command

# IP Route del default scope global nexthop Dev ppp0 nexthop Dev ppp1

7.8.ip route show -- list routes

Abbreviations: Show, list, sh, ls, l

Example 1: calculate the number of routes using the gated/BGP protocol

# IP Route ls proto gated/BGP | WC

1413 9891 79010

Example 2: calculate the number of cached routes. The-O option is required because the cached route attributes may be greater than one row.

# IP-O route ls cloned | WC

159 2543 18707

Example 3: List the routes in the tableid of the route table. The default setting is table main. Tableid is either a real route table ID or a string defined in the/etc/iproute2/rt_tables file,

Or the following special values:

All -- lists the routes of all tables;

Cache-list the content of the route cache.

IP Ro ls 193.233.7.82 tab Cache

Example 4: list the contents of a route table

# IP Route ls table fddi153

Example 5: list the content of the default route table

# IP Route ls

This command is equivalent to the traditional: Route

7.9.ip route flush -- Erase the route table

Example 1: Delete All gateway routes in the main route table (example: After the route monitoring program fails ):

# IP-4 Ro flush scope global type unicast

Example 2: Clear all cloned IPv6 routes:

# IP-6-s RO flush Cache

Example 3: Clear all BGP routes after the gated program fails:

# IP-s ro f proto gated/BGP

Example 4: Clear all IPv4 route caches

# IP Route flush Cache

* ** IPv4 routing cache is flushed.

7.10 IP Route get -- obtain a single route. Abbreviation: Get, G

Use this command to obtain a route entry to the destination address and its exact content.

The operations performed by the IP Route GET command and the IP route show command are different. The IP route show command only displays existing routes, while the IP Route GET command derives a new route when necessary.

Example 1: Search for Route 193.233.7.82

# IP Route get 193.233.7.82

193.233.7.82 Dev eth0 SRC 193.233.7.65 realms INR. AC cache MTU 1500 RTT 300

Example 2: The Search destination address is 193.233.7.82, from 193.233.7.82, the route from the eth0 device (this command will generate a very interesting route, This is a loop route to 193.233.7.82)

# Ip r g 193.233.7.82 from 193.233.7.82 IIF eth0

193.233.7.82 from 193.233.7.82 Dev eth0 SRC 193.233.7.65 realms INR. AC/INR. AC

Cache <Src-direct, redirect> MTU 1500 RTT 300 IIF eth0

8. IP route-database management commands for routing policies

Command

Add, delete, show (or list)

Note: Policy Routing is not equal to rouing policy ).

In some cases, we do not only need to determine the route through the destination address of the data packet, but also need to use other domains: the source address, IP protocol, transport layer port, and even the load of the data packet.

This is called policy routing ).

8.5. IP rule add -- Insert a new rule

IP rule Delete -- delete a rule

Abbreviation: add, A; delete, Del, d

Example 1: Route data packets whose source address is 192.203.80/24 by using the INR. ruhete route table

IP Ru add from 192.203.80/24 table INR. ruhoo PRIO 220

Example 2: Convert the source address of a datagram whose source address is 193.233.7.83 to 192.203.80.144, and route it through table 1

IP Ru add from 193.233.7.83 Nat 192.203.80.144 Table 1 PRIO 320

Example 3: delete useless default rules

IP Ru del PRIO 32767

8.7. IP rule show -- list routing rules

Abbreviations: Show, list, sh, ls, l

Example 1: # IP Ru ls

0: from all lookup local

32762: From 192.168.4.89 lookup fddi153

32764: From 192.168.4.88 lookup fddi153

32766: from all lookup main

32767: from all lookup 253

9. IP maddress-multicast address management

Abbreviations: Show, list, sh, ls, l

9.3.ip maddress show -- list multicast addresses

Example 1: # IP maddr ls dummy

9.4. IP maddress add -- add multicast address

IP maddress Delete -- delete multicast address

Abbreviation: add, A; delete, Del, d

With these two commands, we can add/Delete the link layer multicast address listened on the network interface. This command can only manage link layer addresses.

Example 1: Add # IP maddr add 33: 33: 00: 00: 00: 01 Dev dummy

Example 2: view # IP-O maddr ls dummy

2: dummy

Link 33: 33: 00: 00: 00: 01 users 2 static

Link 01: 00: 5E: 00: 00: 01

Example 3: delete # IP maddr del 33: 33: 00: 00: 00: 01 Dev dummy

10. IP mroute-Multicast Route Cache Management

10.4. IP mroute show -- list Multicast Route cache entries

Abbreviations: Show, list, sh, ls, l

Example 1: view # IP mroute ls

(193.232.127.6, 224.0.1.39) IIF: unresolved

(193.232.244.34, 224.0.1.40) IIF: unresolved

(193.233.7.65, 224.66.66.66) IIF: eth0 oifs: pimreg

Example 2: view # IP-s Mr ls 224.66/16

(193.233.7.65, 224.66.66.66) IIF: eth0 oifs: pimreg

9383 packets, 300256 bytes

11. IP Tunnel-Channel Configuration

Abbreviations

Tunnel and tunl

11.4.ip tunnel add -- Add a new channel

IP Tunnel change -- modify existing channel

IP Tunnel Delete -- delete a channel

Abbreviations: add, A; change, chg; delete, Del, d

Example 1: Create a point-to-point channel with a maximum TTL of 32

# IP Tunnel add Cisco mode sit remote 192.31.7.104 local 192.203.80.1 TTL 32

11.4.ip tunnel show -- Some channels appear in the column

Abbreviations: Show, list, sh, ls, l

Example 1: # IP-s tunl ls Cisco

12. IP monitor and rtmon -- Status Monitoring

IP commands can be used to continuously monitor the status of devices, addresses, and routes. The format of this command option is a bit different. The Command Option name is monitor, followed by the operation object:

IP monitor [file] [All | object-list]

Example 1: # rtmon file/var/log/rtmon. Log

Example 2: # IP monitor file/var/log/rtmon. log R

Related Article

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.