Reprint Address: Baidu
Basically, IP command is the integration of the ifconfig and route these two instructions. However, IP can achieve more functionality. If you are interested, please vi/sbin/ifup, you know the entire ifup is the use of IP this directive to achieve.
[Root@linux ~]# IP [option] [action] [instruction]
Parameters:
Option: Set the parameters, mainly:
-S: Shows the statistical data of the device (statistics), such as the total number of packets accepted;
Action: That is, which network parameters can be used for action, including:
Link: Related Settings for the device (device), including MTU, MAC address, etc.
Addr/address: For additional IP protocols, such as multiple IP agreements, etc.;
Route: Relevant settings related to routing
From the above syntax we can know that IP can not only set some basic network parameters, but also to carry out additional IP protocol, including the achievement of multiple IP, it is perfect. Below we will be divided into three parts (link, addr, route) to introduce this IP instruction bar.
--------------------------------------------------------------------------------
About device Interface (device) Related settings: IP link
IP link can set the relevant settings related to the device (device), including the MTU and the network interface of the MAC, and so on, of course, you can start (up) or close (down) a network interface. The whole syntax is this:
[Root@linux ~]# IP [s] link show <== simply consult the device for information
[Root@linux ~]# IP link Set [device] [actions and parameters]
Parameters:
Show: Display only the relevant content of the device, if plus-s will show more statistical data;
Set: Can start to set the project, device refers to the eth0, eth1 and so on interface code;
Actions and Parameters: include the following actions:
Up|down: Start (UP) or close (down) an interface, other parameters using the preset Ethernet;
Address: If the device can change the MAC, use this parameter to modify it.
Name: Give the device a special name;
MTU: is the maximum transmission unit AH.
Example one: Display all the interface information
[Root@linux ~]# 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 1500 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
[Root@linux ~]# ip-s link show eth0
2:eth0: <BROADCAST,MULTICAST,UP,10000> MTU 1500 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
Use IP link Show to display hardware-related information about the entire appliance interface, as shown above, including the network card address (MAC), MTU, and so on, it is interesting to be the interface of the SIT0, the Sit0 interface is used in IPV4 and IPV6 packet conversion, for we only make Using a IPV4 network is not useful. Both lo and sit0 are set internally by the host. If you add the-s parameter, the relevant statistics for the network card are listed, including the number of packets received (RX) and transmit (TX), and so on, with the same details as the ifconfig output.
Example two: Information about starting, shutting down and setting up devices
[Root@linux ~]# IP link set eth0 up
# start eth0 this device interface;
[Root@linux ~]# IP link set eth0 down
# Ah, close it. Simple as hell ~
[Root@linux ~]# IP link set eth0 MTU 1000
# change MTU value, reach 1000 bytes, unit is bytes ah.
Update network card MTU use Ifconfig can also be achieved AH. Nothing great, however, if you want to change the "network card code, MAC address Information", that may have to use IP ROM ~ but, set before you have to shut down the network card, otherwise it will not succeed. As shown below:
Example three: Modify network card code, MAC and other parameters
[Root@linux ~]# 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:
[Root@linux ~]# IP link set eth0 down <== shutdown interface
[Root@linux ~]# IP link set eth0 name vbird <== Reset
[Root@linux ~]# IP link Show <== observe
2. Vbird: <BROADCAST,MILTICASE> MTU 900 Qdisc pfifo_fast Qlen 1000
Link/ehter 00:40:d0:13:c3:46 BRD FF:FF:FF:FF:FF:FF
# Afraid of it. Even the network card code can be changed. However, after playing, remember to change back.
# because our Ifcfg-eth0 still use the original device code. To avoid problems, to change back
[Root@linux ~]# IP link set vbird name eth0 <== interface Change back
[Root@linux ~]# IP link set eth0 address Aa:aa:aa:aa:aa:aa
[Root@linux ~]# IP link show eth0
# If your network card supports a hard address (MAC) that can be changed,
# So the above action can change your network card address. It's awesome.
# However, the old saying, after the test, please change back immediately.
The device's hardware-related information is set up, including the MTU, the MAC, and the mode of transmission, etc., which can be set here. The interesting thing about the address project was that the project was followed by a hard position (MAC) rather than IP. It's easy to get it wrong. Remember to remember. More hardware parameters can use the man IP to check the settings associated with IP link.
--------------------------------------------------------------------------------
For additional IP-related settings: IP address
If IP link is related to the second layer of the OSI Seven layer protocol, then IP address (IP addr) is the parameter related to the third layer of the network layer. Mainly in the setting of IP-related parameters, including netmask, broadcast and so on.
[Root@linux ~]# IP address show <== is a lookup of IP parameters.
[Root@linux ~]# IP address [add|del] [IP parameters] [dev device name] [related parameters]
Parameters:
Show: The simple display of IP information interface AH;
Add|del: To add (add) or delete (DEL) settings for related parameters, mainly:
IP parameters: The main is the domain settings, such as 192.168.100.100/24, such as the setting OH;
Dev: The interface to be set for this IP parameter, such as Eth0, eth1, and so on;
Related parameters: There are mainly the following:
Broadcast: Set the broadcast address, if the set value is + means "let the system automatically calculate"
Label: That is, the alias of this device, such as eth0:0 Just
Scope: The domain of this interface, usually in these broad categories:
Global: Allows connections from all sources;
Site: Only support IPV6, only allow the connection of the host;
Link: Only allow the device to self connect;
Host: Only allow the internal wiring of the host;
So of course it is using global ROM. The preset is global, too.
Example one: Displays the IP parameters of all interfaces:
[Root@linux ~]# 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 1500 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
See that special font on it. That's right. That's the IP parameter. IP address is also the most important function. Below we further to add virtual network interview to see:
Example two: Add a new interface, the name is assumed to be Eth0:vbird
[Root@linux ~]# IP address add 192.168.50.50/24 broadcast + \
> Dev eth0 label eth0:vbird
[Root@linux ~]# IP address show eth0
2:ETH0:MTU 1500 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 special font above. There is a new line of interfaces, and the name is Eth0:vbird
# to that broadcast + can also be written broadcast 192.168.50.255.
[Root@linux ~]# 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. It's cute. ^_^
Example three: Remove just the interface
[Root@linux ~]# IP address del 192.168.50.50/24 dev eth0
# It's easier to delete. ^_^
--------------------------------------------------------------------------------
About routing Related settings: IP route
Oh, this project is certainly the route of observation and set ROM. In fact, the function of IP route is almost the same as that of route, but he can also perform additional parametric design, such as MTU planning and so on, quite tough.
[Root@linux ~]# IP route show <== a simple display of routing settings.
[Root@linux ~]# IP route [add|del] [IP or domain] [via gateway] [Dev Device]
Parameters:
Show: simply display the routing table, you can also use the list;
Add|del: Add (add) or delete (del) route meaning.
IP or domain: You can use a domain such as 192.168.50.0/24 or a simple IP;
Via: Go out from that gateway, not necessarily;
Dev: That device is going to go out.
MTU: You can set an additional value for the MTU.
Example one: displaying current routing data
[Root@linux ~]# 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 display the current routing information, which is actually the same as the route command. Indicate that you must pay attention to a few small things:
Proto: This route routing protocol, mainly has redirect, kernel, boot, static, RA and so on, kernel refers to is directly by the core judgment automatic setting.
Scope: The range of routes, primarily link, which is the direct connection to the appliance.
Let's take a look at how to add and remove routes.
Example two: Increase the routing, mainly the local direct communication network domain
[Root@linux ~]# ip route add 192.168.5.0/24 dev eth0
# set a good route for the local direct communication network, do not need to go through the external router
[Root@linux ~]# IP route Show
192.168.5.0/24 Dev eth0 Scope link
.... The following omitted ....
Example three: Increase the route to the outside, through the router Oh.
[Root@linux ~]# IP route add 192.168.10.0/24 via 192.168.5.100 Dev eth0
[Root@linux ~]# 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
# look carefully, because I have a 192.168.5.0/24 routing presence (My network card is directly connected),
# So we can throw the 192.168.10.0/24 route to 192.168.5.100
# that mainframe to help pass OH. The same restrictions as the route instructions mentioned earlier.
Example four: Adding a preset route
[Root@linux ~]# IP route add default via 192.168.1.2 dev eth0
# that 192.168.1.2 is what my default router (gateway) means. ^_^
# really remember, just a preset route is OK.
Example five: Delete a route
[Root@linux ~]# ip route del 192.168.10.0/24
[Root@linux ~]# ip route del 192.168.5.0/24