Linux--IP (RPM)

Source: Internet
Author: User

IP is a command, there are many functions of IP command! Basically it integrates the two commands, ifconfig and route, but the IP is more powerful! If you are interested, please vi/sbin/ifup on your own to know that the entire ifup is the use of IP this command to achieve. Here's how to use this

[[Email protected] ~]# IP [option] [action] [command]

Parameters:

Option: Set the parameters, mainly:

-S: Shows the device statistics (statistics), such as the total number of packets received;

Action: That is, which network parameters can be used for action, including:

Link: Device related settings, including MTU, MAC address, etc.

Addr/address: About the additional IP settings, such as the implementation of multiple IP, etc.;

Route: Relevant settings related to routing

By the above syntax we can know that IP in addition to set some basic network parameters, but also can make additional IP settings, including multi-IP implementation, it is perfect! The following is a three-part (link, addr, route) to introduce this IP command.

--------------------------------------------------------------------------------

Related Settings for device: IP link

IP link can set settings related to devices (device), including the MTU and the MAC of the network device, and of course it can start (up) or shut down a network device. The whole syntax is this:

[[Email protected] ~]# IP [-s] link show <== simple access to information about the device

[[Email protected] ~]# IP link set [device] [action and parameters]

Parameters:

Show: Show only relevant content of this device, if plus-S will show more statistics;

Set: Can start to set the project, device refers to eth0, eth1 and so on equipment code;

Actions and Parameters: include the following actions:

Up|down: Start (UP) or off (down) a device, other parameters using preset Ethernet parameters;

Address: If this device can change MAC, use this parameter to modify;

Name: Give this device a special name;

MTU: Sets the maximum transmission unit.

Example one: Show all device information

[[Email protected] ~]# IP link Show

1:lo: <LOOPBACK,UP,10000> MTU 16436 Qdisc noqueue

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

2:eth0: <BROADCAST,MULTICAST,UP,10000> MTU Qdisc pfifo_fast Qlen 1000

Link/ether 00:50:FC:22:9A:CB BRD FF:FF:FF:FF:FF:FF

3:sit0: <NOARP> MTU 1480 Qdisc NoOp

Link/sit 0.0.0.0 BRD 0.0.0.0

[Email protected] ~]# ip-s link show eth0

2:eth0: <BROADCAST,MULTICAST,UP,10000> MTU Qdisc pfifo_fast Qlen 1000

Link/ether 00:50:FC:22:9A:CB BRD FF:FF:FF:FF:FF:FF

Rx:bytes packets Errors dropped overrun Mcast

484011792 2247372 0 0 0 0

Tx:bytes packets errors dropped carrier Collsns

2914104290 2867753 0 0 0 0

Using the IP link show can display hardware-related information for the entire device, as shown above, including MAC address, MTU, and so on, the more interesting should be the SIT0 device, the SIT0 device is IPv4 and IPv6 of the packet conversion, for us to use only IPv4 Network is not functioning. Lo and sit0 are self-setting within the host. If you add the-s parameter, the relevant statistics of this network card will be listed, including the number of packets received (RX) and transmit (TX), and so on, the details are the same as the output of ifconfig.

Example two: Start, close and set up the device information

[[Email protected] ~]# IP link set eth0 up

# start eth0 this device;

[[Email protected] ~]# IP link set eth0 down

# close eth0 this device;

[[Email protected] ~]# IP link set eth0 MTU 1000

# change the MTU to bytes, the unit is bytes.

Updating the NIC's MTU using Ifconfig can also be real. If you want to change the "network card code, MAC address Information", then you have to use the IP, set the first need to close the network card, otherwise it will not succeed. As shown below:

Example three: Modify the network card name, MAC and other parameters

[[Email protected] ~]# IP link set eth0 name Vbird

Siocsifname:device or resource busy

# because the device is currently activated, it cannot be set. You should do this:

[[Email protected] ~]# IP link set eth0 down <== shutdown device

[[Email protected] ~]# IP link set eth0 name vbird <== Reset

[[Email protected] ~]# IP link show <== View information

2. Vbird: <BROADCAST,MILTICASE> MTU Qdisc pfifo_fast Qlen 1000

Link/ehter 00:40:d0:13:c3:46 BRD FF:FF:FF:FF:FF:FF

# Oh, even the network card code can be changed! However, after playing, remember to change back AH!

# because our Ifcfg-eth0 still use the original device code! To avoid problems, to change back

[[Email protected] ~]# IP link set vbird name eth0 <== device changed back

[[Email protected] ~]# IP link set eth0 address Aa:aa:aa:aa:aa:aa

[[Email protected] ~]# IP link show eth0

# if your NIC supports Mac changes,

# then the above command can change your NIC Mac!

# However, it is the old saying, please change it back immediately after the test!

In this device hardware related information settings, including the MTU, MAC and transmission mode, etc., can be set here. The interesting thing is the address project, which is followed by the MAC address instead of the IP address is easy to mistake! Remember, remember! More hardware parameters You can use the man IP to look up the settings related to IP link.

--------------------------------------------------------------------------------

About additional IP-related settings: IP address

If IP link is related to the second layer of data link layer of the OSI layer seven model, then IP address (IP addr) is related to the third layer of network layer. Mainly in the setting of IP-related parameters, including netmask, broadcast and so on.

[[Email protected] ~]# IP address show <== view IP parameters

[[Email protected] ~]# IP address [add|del] [IP parameters] [dev device name] [related parameters]

Parameters:

Show: Simply display the IP information of the device;

Add|del: Add (add) or delete (DEL) settings for related parameters, mainly:

IP parameters: The main is the network domain settings, such as 192.168.100.100/24 settings;

Dev: This IP parameter to set the device, such as eth0, eth1 and so on;

Related parameters: as shown below:

Broadcast: Set the broadcast address, if the setting value is + means let the system automatically calculate;

Scope: The realm of this device, usually the following major categories:

Global: Allow connections from all sources;

Site: Only support IPV6, only allow the connection of the host;

Link: Only allow the device to self-connect;

Host: Allow only internal connections to the host;

So of course it's using global. Presets are also global!

Example one: Displays the IP parameters of all devices:

[[Email protected] ~]# IP address Show

1:lo: <LOOPBACK,UP,10000> MTU 16436 Qdisc noqueue

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,10000> MTU Qdisc pfifo_fast Qlen 1000

Link/ether 00:50:FC:22:9A:CB BRD FF:FF:FF:FF:FF:FF

inet 192.168.1.2/24 BRD 192.168.1.255 Scope Global eth0

Inet6 FE80::250:FCFF:FE22:9ACB/64 Scope link

Valid_lft Forever Preferred_lft Forever

3:sit0: <NOARP> MTU 1480 Qdisc NoOp

Link/sit 0.0.0.0 BRD 0.0.0.0

Let's go further by adding virtual network devices:

Example two: Add a device with the name assumed to be Eth0:vbird

[[Email protected] ~]# IP address add 192.168.50.50/24 broadcast +/

> Dev eth0 label eth0:vbird

[[Email protected] ~]# IP address show eth0

2:eth0:mtu Qdisc pfifo_fast Qlen 1000

Link/ether 00:40:d0:13:c3:46 BRD FF:FF:FF:FF:FF:FF

inet 192.168.1.100/24 BRD 192.168.1.255 Scope Global eth0

inet 192.168.50.50/24 BRD 192.168.50.255 Scope Global Eth0:vbird

Inet6 FE80::240:D0FF:FE13:C346/64 Scope link

Valid_lft Forever Preferred_lft Forever

# See the above output a line more, add a new device, the name is Eth0:vbird

# As for that broadcast + can also be written broadcast 192.168.50.255.

[Email protected] ~]# ifconfig

Eth0:vbir Link encap:ethernet HWaddr 00:40:d0:13:c3:46

inet addr:192.168.50.50 bcast:192.168.50.255 mask:255.255.255.0

Up broadcast RUNNING multicast mtu:1500 metric:1

Interrupt:5 Base address:0x3e00

# If you use Ifconfig, you can see this weird thing!

Example three: Remove the device you just had

[Email protected] ~]# IP address del 192.168.50.50/24 dev eth0

# Delete is simple.

--------------------------------------------------------------------------------

About routing settings: IP route

This project is the view and setting of the route. In fact, the IP route function is almost the same as the route command, but it can also be used for additional parameter settings, such as MTU planning and so on, quite tough!

[[Email protected] ~]# IP route show <== simply shows the settings of the route

[[Email protected] ~]# IP route [add|del] [IP or domain] [via gateway] [Dev Device]

Parameters:

Show: A simple display of the routing table, you can also use list;

Add|del: Add (add) or delete (Del) routes;

IP or domain: can use domain such as 192.168.50.0/24 or pure IP;

Via: It's not necessary to go out from that gateway;

Dev: connected by that device, need;

MTU: The value of the MTU can be set in additional;

Example one: Shows the current routing data

[[Email protected] ~]# IP route Show

192.168.1.0/24 Dev eth0 proto kernel scope link src 192.168.1.2

169.254.0.0/16 Dev eth1 Scope link

Default via 192.168.1.254 Dev eth1

As shown in the table above, the simplest function is to show the current routing information, which is actually the same as the route command. Some points to be aware of:

Proto: Routing protocol for this route, mainly redirect, kernel, boot, static, RA, etc., where kernel refers directly to the core judgment automatically set.

Scope: The scope of the route, mainly link, is a direct connection to this device.

Take a look at how to add and remove routes:

Example two: Increase the routing, mainly the local network can communicate directly with the domain

[Email protected] ~]# IP route add 192.168.5.0/24 dev eth0

# set up a route for a domain that is directly communicated to the local computer, without having to go through an external router

[[Email protected] ~]# IP route Show

192.168.5.0/24 Dev eth0 Scope link

.... The following ellipsis ....

Example three: Increase the route that can lead to external, need through router;

[[Email protected] ~]# IP route add 192.168.10.0/24 via 192.168.5.100 Dev eth0

[[Email protected] ~]# IP route Show

192.168.5.0/24 Dev eth0 Scope link

.... Other omitted ....

192.168.10.0/24 via 192.168.5.100 Dev eth0

# carefully, because I have 192.168.5.0/24 routing presence (directly related to my NIC),

# so you can drop the 192.168.10.0/24 route to 192.168.5.100

# that mainframe to help pass! The same limitations as the route command mentioned earlier!

Example four: Adding a preset route

[[Email protected] ~]# IP route add default via 192.168.1.2 dev eth0

# that 192.168.1.2 is my default router (gateway);

# Remember, as long as a preset route is OK;

Example five: Delete a route

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

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

In fact, the command of this IP is too profound! Just contact the Linux network friends, you may see a little dizzy! You will first use Ifconfig, Ifup, Ifdown and route can, and so on after the experience, then continue to play IP this fun command it! If you are interested, you can also refer to this command by yourself Ethtool!

Turn from:

http://blog.csdn.net/qihuanfengyun/article/details/5507835

Linux--IP (RPM)

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.