In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to add routes using route under Linux". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "how to use route to add routes under Linux".
Route is used to manipulate the IP routing table of the management kernel. The main function is to set the static routing table to a specific host or network through the network interface after configuring the network interface with the ifconfig command.
Route-n shows all routes now
The result of root@Ubuntu:~# route is from top to bottom, that is to say, which one is in front, which one has priority, and there is none in front, just use the last default.
# add a route (all routes sent to the network segment 192.168.62 are sent through the gateway 192.168.1.1) route add-net 192.168.62.0 netmask 255.255.255.0 gw 192.168.1." when deleting a route, you do not need to write the method of adding a route under the gateway route del-net 192.168.122.0 netmask 255.255.255.0linux:
One: use the route command to add
The route added using the route command becomes invalid after the machine is rebooted or the network card is restarted. Method:
# routes added to the host # route add-host 192.168.168.110 dev eth0# route add-host 192.168.168.119 gw 192.168.168.168.168." routes added to the network # route add-net IP netmask MASK eth0# route add-net IP netmask MASK gw IP# route add-net IP/24 eth2# add default gateway # route add default gw IP# delete route # route del-host 192.168.168.110 dev eth0
Second: the method of setting permanent route under linux:
1. Add to / etc/rc.local
Route add-net 192.168.3.0 dev eth0route add 24 dev eth0route add-net 192.168.2.0 Universe 24 gw 192.168.3.254
two。 Add to the end GATEWAY=gw-ip or GATEWAY=gw-dev in / etc/sysconfig/network
3./etc/sysconfig/static-router:
The correct usage of any net x.x.x.x/24 gw y.y.y.yRoute command
Use the Route command line tool to view and edit the computer's IP routing table. The Route command and syntax are as follows:
Route [- f] [- p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]] 1
-f clears the routing table for all gateway entrances. -p makes the route permanent when used with the add command. Command specifies the command you want to run (Add/Change/Delete/Print). Destination specifies the network destination for the route. Mask Netmask specifies the network mask (also known as the subnet mask) associated with the network destination. Gateway specifies the forward or next-hop IP address that can be reached by the set of addresses defined by the network destination and the subnet mask. Metric Metric specifies an integer cost value for the route (from 1 to 9999), which can be used when selecting multiple routes in the routing table that best match the destination address of the forwarded packet. If Interface specifies the interface index for the interface that can access the target. To get a list of interfaces and their corresponding interface index, use the display function of the route print command. You can use decimal or hexadecimal values for interface indexing. ? Displays help at the command prompt. The sample route print shows the entire contents of the IP routing table
Route print 10. * is displayed at 10. Routes in the starting IP routing table
Route add 0.0.0.0 mask 0.0.0.0 192.168.12.1 add a default route with a 192.168.12.1 default gateway address
Route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 add a route to the 10.41.0.0 destination with a 255.255.0.0 subnet mask and 10.27.0.1 next hop address
Route-p add 10.41.0.0 mask 255.255.0.0 10.27.0.1 add a permanent route to the 10.41.0.0 destination with a 255.255.0.0 subnet mask and 10.27.0.1 next hop address
Route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 metric 7 adds a route to the 10.41.0.0 destination with a 255.255.0.0 subnet mask, a 10.27.0.1 next hop address and a cost value of 7
Route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 if 0x3 adds a route to the 10.41.0.0 destination with a 255.255.0.0 subnet mask, 10.27.0.1 next hop address and using the 0x3 interface index
Route delete 10.41.0.0 mask 255.255.0.0 removes a route to the 10.41.0.0 destination with a 255.255.0.0 subnet mask
Route delete 10. * Delete by 10. All routes in the starting IP routing table
Route change 10.41.0.0 mask 255.255.0.0 10.27.0.25` modify the next hop address with `10.41.0.0` target and `255.255.0.0` subnet mask from `10.27.0.1` to `10.27.0.25 traditional network configuration command: use the ifconfig command to configure and view the network interface # example 1: configure the IP of eth0 Activate device simultaneously: ifconfig eth0 192.168.4.1 netmask 255.255.255.0 up# example 2: configure IP for eth0 alias device eth0:1 and add routing ifconfig eth0:1 192.168.4.2route add-host 192.168.4.2 dev eth0:1# example 3: activate (disable) device ifconfig eth0:1 up (down) # example 4: view all (specified) network interface configuration ifconfig (eth0)
\ 2. Use the route command to configure the routing table
Example 1: add to host route route add-host 192.168.4.2 dev eth0:1route add-host 192.168.4.1 gw 192.168.4.250 example 2: routes added to the network route add-net IP netmask MASK eth0route add-net IP netmask MASK gw IProute add-net IP/24 eth2 example 3: add default gateway route add default gw IP example 4: delete route route del-host 192.168.4.1 dev eth0:1 example 5 : check the routing information route or route-n (- n means that the name is not resolved Listing will be faster than route)
3.ARP management command
Example 1: view ARP cache arp example 2: add arp-s IP MAC example 3: delete arp-d IP
\ 4. Ip is a powerful network configuration tool in iproute2 software package, which can replace some traditional network management tools. For example: ifconfig, route, etc., the above example can be achieved with the following ip command, and the ip command can achieve more functions. Here are some examples: syntax of the 4. 0 ip command
Ip [OPTIONS] OBJECT [COMMAND [ARGUMENTS]]
4.1 ip link set- changes the properties of the device. Abbreviations: set, s
Example 1:up/down starts / shuts down the device. # ip link set dev eth0 up this equals 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 100Example 3: change the value of the network device MTU (maximum transmission unit). # 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- displays device properties. Abbreviations: show, list, lst, sh, ls, l,-s options appear two or more times, ip will output more detailed error information statistics.
Example: # ip-s-s link ls eth0eth0: mtu 1500 qdisc cbq qlen 100link/ether 00:a0:cc:66:18:78 brd ff:ff:ff:ff:ff:ffRX: bytes packets errors dropped overrun mcast2449949362 2786187 000 0RX errors: length crc fifo missed0 000 0TX: bytes packets errors dropped carrier collsns178558497 1783946 332 0 332 35172TX errors: aborted fifo window heartbeat0 00 332 this command is equal to traditional ifconfig eth0
5.1 ip address add-- add a new protocol address. Abbreviations: add, a
Example 1: set a string for each address as a label. To be compatible with Linux-2.0 's network alias, the string must start with the device name, followed by a colon, # ip addr add local 192.168.4.1 label eth0:1 dev eth0 28 brd + label eth0:1 dev eth0 example 2: add an address 192.168.20.0 to the Ethernet interface eth0 with a mask length of 24 bits (155.155.155.0), standard broadcast address The command labeled eth0:Alias:# ip addr add 192.168.4.2 Plus 24 brd + dev eth2 label eth2:1 equals the traditional: ifconfig eth2:1 192.168.4.2
5.2 ip address delete- deletes a protocol address. Abbreviations: delete, del, d
# ip addr del 192.168.4.1 ip addr del 24 brd + dev eth0 label eth0:Alias1
5.3 ip address show- displays the protocol address. Abbreviations: show, list, lst, sh, ls, l
# ip addr ls eth0
5.4.ip address flush- clears the protocol address. Abbreviations: flush, f
Example 1: delete all addresses belonging to private network 10.0.0.0 ip neighbour--neighbour/arp 8: # ip-s-s a f to 10swap 8 example 2: cancel the IP address of all Ethernet cards # ip-4 addr flush label "eth0" ip neighbour--neighbour/arp table management command abbreviations neighbour, neighbor, neigh, n command add, change, replace, delete, fulsh, Show (or list) 6.1 ip neighbour add-add a new adjacency entry ip neighbour change- modify an existing entry ip neighbour replace- replace an existing entry abbreviation: add, a Change, chg;replace, repl example 1: on the device eth0, add a permanent ARP entry for the address 10.0.0.3: # ip neigh add 10.0.0.3 lladdr 0VOV 0VOV 0VOV 0Vlv 1 dev eth0 nud perm example 2: change the state to reachable# ip neigh chg 10.0.0.3 dev eth0 nud reachable
6.2.ip neighbour delete- Delete an adjacency entry example 1: delete an ARP entry 10.0.0.3 on the device eth0
# ip neigh del 10.0.0.3 dev eth0
6.3.ip neighbour show- displays information about network neighbors. Abbreviations: show, list, sh, ls
# 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 neighbour flush- clears adjacency entries. Abbreviations: flush, f example 1: (- s can display details)
# ip-s-s n f 193.233.7.254 routing table management 7.1. Abbreviations route, ro, r 7.2. Routing tables start with Linux-2.2, and the kernel generalizes routes into many routing tables, which are numbered with numbers ranging from 1 to 255. In addition, for convenience, you can name the routing table in / etc/iproute2/rt_tables. By default, all routes are inserted into the table main (number 254). When doing routing queries, the kernel uses only the routing table main. 7.3.ip route add-add a new route ip route change-modify a route ip route replace-replace the existing route abbreviations: add, a change, chg;replace, repl example 1: the route that is set to the network 10.0.0Mab 24 passes through the gateway 193.233.7.6 route ip route add 10.0.0 via 24 193.233.7.65
Example 2: modify the direct route to network 10.0.0amp 24 to pass through the device dummy
# ip route chg 10.0.0/24 dev dummy
Example 3: achieve link load balancing. Add the default multipath route and let ppp0 and ppp1 share the load. (note: the scope value is not required, it just tells the kernel that the route goes through the gateway rather than directly connected. In fact, if you know the address of the remote endpoint, it's better to use the via parameter to set it.
# 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: set up NAT routing. Before forwarding the packet from 192.203.80.144, the network address is translated 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, allowing packets to be sent out randomly from multiple routes. Weight can set weights.
# ip route replace default equalize nexthop via 211.139.218.145 dev eth0 weight 1 nexthop via 211.139.218.145 dev eth2 weight 1
7.4.ip route delete- delete route abbreviation: delete, del, d example 1: delete the multipath route added by the command in the previous section
# ip route del default scope global nexthop dev ppp0 nexthop dev ppp1
7.5.ip route show-list route abbreviations: show, list, sh, ls, l example 1: calculate the number of routes using the gated/bgp protocol
# ip route ls proto gated/bgp | wc1413 9891 7901012
Example 2: calculate the number of entries in the route cache, because the attributes of the cached route may be larger than one row, so you need to use the-o option
# ip-o route ls cloned | wc159 2543 18707
Example 3: list the routes in the routing table TABLEID. The default setting is table main. TABLEID is either a real routing table ID or a string defined by the / etc/iproute2/rt_tables file, or the following special values: all-lists the routes for all tables; cache-lists the contents of the route cache.
Ip ro ls 193.233.7.82 tab cache
Example 4: list the contents of a routing table
# ip route ls table fddi153
Example 5: list the contents of the default routing table
# ip route ls
This command is equal to the traditional: route 7.6.ip route flush-erase routing table example 1: delete all gateway routes in the routing table main (example: after the route monitor hangs):
# ip-4 ro flush scope global type unicast
Example 2: clear all cloned IPv6 routes:
# ip-6-s-s ro flush cache
Example 3: after the gated program dies, clear all BGP routes:
# ip-s ro f proto gated/bgp
Example 4: clear all ipv4 routing cache
# ip route flush cache*** IPv4 routing cache is flushed.
7.7 ip route get-get a single route. Abbreviations: get, g use this command to get a route to the destination address and its exact contents. The ip route get command and the ip route show command perform different operations. The ip route show command simply displays existing routes, while the ip route get command derives new routes if necessary. Example 1: route found in 193.233.7.82
# ip route get 193.233.7.82193.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 arriving from the eth0 device (this command produces a very interesting route, which is a loopback route to 193.233.7.82)
# ip r g 193.233.7.82 from 193.233.7.82 iif eth0193.233.7.82 from 193.233.7.82 dev eth0 src 193.233.7.65 realms inr.ac/inr.accachemtu 1500 rtt 300 iif eth0ip route-routing policy database management commands add, delete, show (or list) Note: policy routing (policy routing) is not equal to routing policy (rouing policy). In some cases, we need to route not only by the destination address of the packet, but also through other domains: the source address, the IP protocol, the transport layer port, or even the payload of the packet. This is called Policy routing (policy routing). 8.1. Ip rule add-insert new rule ip rule delete-delete rule abbreviation: add, a Delete, del, d example 1: routing packets from packets with source address 192.203.80 table inr.ruhep prio 24 through routing table inr.ruhep example 2: convert the source address of a Datagram with source address 193.233.7.83 to 192.203.80.144 And route ip ru add from 193.233.7.83 nat 192.203.80.144 table 1 prio 320 example 3: delete the useless default rule ip ru del prio 32767
8.2. Ip rule show-list the abbreviations of routing rules: show, list, sh, ls, l
Example 1: # ip ru ls0: from all lookup local32762: from 192.168.4.89 lookup fddi15332764: from 192.168.4.88 lookup fddi15332766: from all lookup main32767: from all lookup 253ip maddress-Multicast address Management abbreviation: show, list, sh, ls, l 9.1.ip maddress show-list Multicast address example 1: # ip maddr ls dummy 9.2. Ip maddress add-add Multicast address ip maddress delete-remove Multicast address acronym: add, a BX delete, del, d using these two commands, we can add / remove link layer multicast addresses that are listening on the network interface. This command can only manage link layer addresses. Example 1: add # ip maddr add 3300 ip ip 00001 dev dummy example 2: view # ip maddr del-O maddr ls dummy2: dummylink 3300 O maddr ls dummy2 0001 users 2 staticlink 01:00:5e:00:00:01 example 3: delete # ip maddr del 3300VLV 3300VLV 0001 dev dummy
10.ip mroute-Multicast routing cache management 10.1. Ip mroute show-lists the abbreviations of multicast route cache entries: 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) Iif: eth0 Oifs: pimreg example 2: view # ip-s mr ls 224.66 Iif 16 (193.233.7.65, 224.66.66) Iif: pimreg9383 packets: 300256 bytesip tunnel-Channel configuration abbreviations tunnel, tunl 11.1.ip tunnel add-add new channel ip tunnel change-modify existing channel ip tunnel delete-delete a channel abbreviation: add, a Change, chg;delete, del, d example 1: establish a point-to-point channel with a maximum TTL of 31st ip tunnel add Cisco mode sit remote 192.31.7.104 local 192.203.80.1 ttl 32
11.2.ip tunnel show-list existing channel abbreviations: show, list, sh, ls, l
Example 1: # ip-s tunl ls Cisco
Ip monitor and rtmon-the status Monitoring ip command can be used to continuously monitor the status of devices, addresses, and routes. The format of this command option is a little different. The name of the command option is monitor, followed by the operator: ip monitor [file FILE] [all | OBJECT-LIST]
Example 1: # rtmon file / var/log/rtmon.log
Example 2: # ip monitor file / var/log/rtmon.log r
The above is all the contents of the article "how to use route to add routing under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.